Skip to content

Commit

Permalink
zoom autoselected by default fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Aug 12, 2018
1 parent 1366d10 commit eae1b12
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/apexcharts.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions samples/line/zoomable-timeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
zoom: {
enabled: true
},
toolbar: {
autoSelected: 'zoom'
}
},
plotOptions: {
line: {
Expand Down
6 changes: 6 additions & 0 deletions src/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ class ApexCharts {
w.config = Utils.extend(w.config, options)
}

w.globals.isDirty = true

return this.update()
}

Expand All @@ -428,6 +430,8 @@ class ApexCharts {

me.w.config.series = newSeries.slice()

me.w.globals.isDirty = true

return this.update()
}

Expand Down Expand Up @@ -456,6 +460,8 @@ class ApexCharts {
}
me.w.config.series = newSeries

me.w.globals.isDirty = true

return this.update()
}

Expand Down
6 changes: 6 additions & 0 deletions src/modules/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class Toolbar {
this.elToolbarWrap.appendChild(toolbarControls[i].el)
}

if (!w.globals.isDirty) {
w.globals.zoomEnabled = w.config.chart.toolbar.autoSelected === 'zoom'
w.globals.panEnabled = w.config.chart.toolbar.autoSelected === 'pan'
w.globals.selectionEnabled = w.config.chart.toolbar.autoSelected === 'selection'
}

if (w.globals.zoomEnabled) {
this.elZoom.classList.add('selected')
} else if (w.globals.panEnabled) {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/settings/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class Globals {
markers: {
colors: []
},
isDirty: false, // chart has been updated after the initial render
initialConfig: null, // we will store the first config user has set to go back when user finishes interactions like zooming and come out of it
series: [], // the MAIN series array (y values)
seriesPercent: [], // the percentage values of the given series
Expand All @@ -50,6 +51,7 @@ export default class Globals {
maxValsInArrayIndex: 0,
zoomEnabled: false,
panEnabled: false,
selectionEnabled: false,
yaxis: null,
minY: Number.MIN_VALUE, // is 5e-324, i.e. the smallest positive number
// NOTE: If there are multiple y axis, the first yaxis array element will be considered for all y values calculations. Rest all will be calculated based on that
Expand Down
3 changes: 2 additions & 1 deletion src/modules/settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ export default class Options {
zoomout: true,
pan: true,
reset: true
}
},
autoSelected: 'zoom' // accepts -> zoom, pan, selection
},
type: 'line',
width: '100%',
Expand Down

0 comments on commit eae1b12

Please sign in to comment.