Skip to content

Commit

Permalink
values out of bounds fix - fixes #622
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed May 26, 2019
1 parent 4897328 commit 0d6171d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
3 changes: 2 additions & 1 deletion samples/react/line/zoomable-timeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
stacked: false,
zoom: {
type: 'x',
enabled: true
enabled: true,
autoScaleYaxis: true
},
toolbar: {
autoSelected: 'zoom'
Expand Down
3 changes: 2 additions & 1 deletion samples/vanilla-js/line/zoomable-timeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
height: 350,
zoom: {
type: 'x',
enabled: true
enabled: true,
autoScaleYaxis: true
},
toolbar: {
autoSelected: 'zoom'
Expand Down
3 changes: 2 additions & 1 deletion samples/vue/line/zoomable-timeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
stacked: false,
zoom: {
type: 'x',
enabled: true
enabled: true,
autoScaleYaxis: true
},
toolbar: {
autoSelected: 'zoom'
Expand Down
17 changes: 6 additions & 11 deletions src/modules/Scales.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ export default class Range {
yMax = yMax * 1.01
}

// for extremely small values - #fix #553
if (range < 0.00001 && NO_MIN_MAX_PROVIDED && yMax < 10) {
yMax = yMax * 1.05
} else if (diff > 0.1 && diff < 3 && NO_MIN_MAX_PROVIDED) {
/* fix https://github.com/apexcharts/apexcharts.js/issues/576 */
/* fix https://github.com/apexcharts/apexcharts.js/issues/588 */
yMax = yMax + diff / 3
}

let tiks = ticks + 1
// Adjust ticks if needed
if (tiks < 2) {
Expand Down Expand Up @@ -103,7 +94,7 @@ export default class Range {
}
}

if (NO_MIN_MAX_PROVIDED && diff > 4) {
if (NO_MIN_MAX_PROVIDED && diff > 20) {
return {
result,
niceMin: result[0],
Expand All @@ -114,11 +105,15 @@ export default class Range {
let v = yMin
result.push(v)
let valuesDivider = Math.abs(yMax - yMin) / ticks
for (let i = 0; i <= ticks - 1; i++) {
for (let i = 0; i <= ticks; i++) {
v = v + valuesDivider
result.push(v)
}

if (result[result.length - 2] >= yMax) {
result.pop()
}

return {
result,
niceMin: result[0],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/exponential-data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ describe('Exponential values should parse', () => {
const maxY = chart.w.globals.maxY

expect(minY).toEqual(2.3e-7)
expect(maxY).toEqual(3.255e-7)
expect(maxY).toEqual(3.2599999999999993e-7)
})
})
38 changes: 35 additions & 3 deletions tests/unit/small-range.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('Y-axis with ultra-small values', () => {
const maxY = chart.w.globals.maxY

expect(minY.toFixed(6)).toEqual('0.003760')
expect(maxY.toFixed(6)).toEqual('0.003799')
expect(maxY.toFixed(6)).toEqual('0.003807')
})

it('should not round values for smaller range (less than 5)', () => {
it('should not apply nice scale for small values', () => {
const chart = createChartWithOptions({
chart: {
type: 'line'
Expand All @@ -46,8 +46,40 @@ describe('Y-axis with ultra-small values', () => {
}
})

const minY = chart.w.globals.minY
const maxY = chart.w.globals.maxY

expect(minY).toEqual(1)
expect(maxY).toEqual(4)
})

it('should not apply nice scale for small range with big numbers', () => {
const chart = createChartWithOptions({
chart: {
type: 'line'
},
series: [
{
data: [
[1553258700000, 1098],
[1553259000000, 1099],
[1553261100000, 1100]
]
}
],
xaxis: {
type: 'datetime'
}
})

const yAxisScale = chart.w.globals.yAxisScale[0].result

expect(yAxisScale).toEqual([1, 1.75, 2.5, 3.25, 4])
expect(yAxisScale).toEqual([
1097.9,
1098.5875,
1099.275,
1099.9625,
1100.65
])
})
})

0 comments on commit 0d6171d

Please sign in to comment.