Skip to content

Commit

Permalink
overwriting the initial series and config correct way - fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Sep 8, 2018
1 parent ac84207 commit c9d0664
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 57 deletions.
42 changes: 18 additions & 24 deletions dist/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8678,7 +8678,7 @@ var Toolbar = function () {
xaxis.min = w.globals.initialConfig.xaxis.min;
xaxis.max = w.globals.initialConfig.xaxis.max;

me.ctx.updateOptionsInternal(w.globals.initialConfig, false, true);
me.ctx.updateSeriesInternal(w.globals.initialSeries, true);
}
}]);

Expand Down Expand Up @@ -10718,8 +10718,9 @@ var ApexCharts = function () {
value: function updateOptions(options) {
var redraw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var animate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var overwriteInitialConfig = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;

return this.updateOptionsInternal(options, redraw, animate, true);
return this.updateOptionsInternal(options, redraw, animate, overwriteInitialConfig);
}

/**
Expand All @@ -10728,15 +10729,15 @@ var ApexCharts = function () {
* @param {object} options - A new config object can be passed which will be merged with the existing config object
* @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
* @param {boolean} animate - should animate or not on updating Options
* @param {boolean} makeDefaultConfig - should update the default config or not
* @param {boolean} overwriteInitialConfig - should update the initial config or not
*/

}, {
key: 'updateOptionsInternal',
value: function updateOptionsInternal(options) {
var redraw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var animate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var makeDefaultConfig = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var overwriteInitialConfig = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;

var w = this.w;
this.w.config.chart.animations.dynamicAnimation.enabled = animate;
Expand Down Expand Up @@ -10776,9 +10777,8 @@ var ApexCharts = function () {

w.config = _Utils2.default.extend(w.config, options);

if (makeDefaultConfig) {
if (overwriteInitialConfig) {
w.globals.initialConfig = _Utils2.default.extend({}, w.config);
w.globals.initialSeries = JSON.parse(JSON.stringify(w.globals.initialConfig.series));
}
}

Expand All @@ -10796,9 +10796,9 @@ var ApexCharts = function () {
value: function updateSeries() {
var newSeries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var makeDefaultConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;

return this.updateSeriesInternal(newSeries, animate, makeDefaultConfig);
return this.updateSeriesInternal(newSeries, animate, overwriteInitialSeries);
}

/**
Expand All @@ -10809,27 +10809,22 @@ var ApexCharts = function () {

}, {
key: 'updateSeriesInternal',
value: function updateSeriesInternal(newSeries, animate, makeDefaultConfig) {
value: function updateSeriesInternal(newSeries, animate) {
var overwriteInitialSeries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

var w = this.w;
this.w.config.chart.animations.dynamicAnimation.enabled = animate;
var series = new _Series2.default(this.ctx);

w.globals.dataChanged = true;

// while updateing pie/donut series, user completely changed the series length too
// if (!w.globals.axisCharts && newSeries.length !== w.globals.series.length) {
// w.globals.dataChanged = false
// animate = false
// }

if (animate) {
series.getPreviousPaths();
}

w.config.series = newSeries.slice();
if (makeDefaultConfig) {
w.globals.initialConfig = _Utils2.default.extend({}, w.config);
w.globals.initialSeries = JSON.parse(JSON.stringify(w.globals.initialConfig.series));
if (overwriteInitialSeries) {
w.globals.initialSeries = JSON.parse(JSON.stringify(w.config.series));
}

return this.update();
Expand All @@ -10844,6 +10839,8 @@ var ApexCharts = function () {
}, {
key: 'appendData',
value: function appendData(newData) {
var overwriteInitialSeries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;

var me = this;

var series = new _Series2.default(me.ctx);
Expand All @@ -10862,9 +10859,9 @@ var ApexCharts = function () {
}
}
me.w.config.series = newSeries;

me.w.globals.initialConfig = _Utils2.default.extend({}, me.w.config);
me.w.globals.initialSeries = JSON.parse(JSON.stringify(me.w.globals.initialConfig.series));
if (overwriteInitialSeries) {
me.w.globals.initialSeries = JSON.parse(JSON.stringify(me.w.config.series));
}

return this.update();
}
Expand Down Expand Up @@ -17001,9 +16998,6 @@ var Range = function () {
var valuesDivider = Math.abs(yMax - yMin) / ticks;
for (var i = 0; i <= ticks - 1; i++) {
v = v + valuesDivider;
if (v % 1 !== 0 && typeof toFixed !== 'undefined') {
v = parseFloat(v.toFixed(toFixed));
}
result.push(v);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/apexcharts.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions samples/area/area-datetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
min: new Date('28 Jan 2013').getTime(),
max: new Date('27 Feb 2013').getTime(),
}
})
}, false, true, false)
})

document.querySelector("#six_months").addEventListener('click', function (e) {
Expand All @@ -167,7 +167,7 @@
min: new Date('27 Sep 2012').getTime(),
max: new Date('27 Feb 2013').getTime(),
}
})
}, false, true, false)
})

document.querySelector("#one_year").addEventListener('click', function (e) {
Expand All @@ -177,7 +177,7 @@
min: new Date('27 Feb 2012').getTime(),
max: new Date('27 Feb 2013').getTime(),
}
})
}, false, true, false)
})

document.querySelector("#ytd").addEventListener('click', function (e) {
Expand All @@ -187,7 +187,7 @@
min: new Date('01 Jan 2013').getTime(),
max: new Date('27 Feb 2013').getTime(),
}
})
}, false, true, false)
})

document.querySelector("#all").addEventListener('click', function (e) {
Expand All @@ -197,7 +197,7 @@
min: undefined,
max: undefined,
}
})
}, false, true, false)
})

document.querySelector("#ytd").addEventListener('click', function () {
Expand Down
17 changes: 17 additions & 0 deletions samples/mixed/line-column-area.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@
);

chart.render();

window.setTimeout(function () {
chart.updateSeries([{
name: 'TEAM A',
type: 'column',
data: [44, 55, 41, 67, 22, 43, 21, 41, 56, 27, 43]
}, {
name: 'TEAM B',
type: 'area',
data: [30, 25, 36, 30, 45, 35, 64, 52, 59, 36, 39]
}, {
name: 'TEAM C',
type: 'line',
data: [23, 11, 22, 27, 13, 22, 37, 21, 44, 22, 30]
}])
}, 2000)

</script>
</body>

Expand Down
3 changes: 2 additions & 1 deletion samples/scatter/scatter-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
height: 380,
type: 'scatter',
zoom: {
enabled: false
enabled: true,
type: 'xy'
}
},

Expand Down
36 changes: 14 additions & 22 deletions src/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ class ApexCharts {
* @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
* @param {boolean} animate - should animate or not on updating Options
*/
updateOptions (options, redraw = false, animate = true) {
return this.updateOptionsInternal(options, redraw, animate, true)
updateOptions (options, redraw = false, animate = true, overwriteInitialConfig = true) {
return this.updateOptionsInternal(options, redraw, animate, overwriteInitialConfig)
}

/**
Expand All @@ -325,9 +325,9 @@ class ApexCharts {
* @param {object} options - A new config object can be passed which will be merged with the existing config object
* @param {boolean} redraw - should redraw from beginning or should use existing paths and redraw from there
* @param {boolean} animate - should animate or not on updating Options
* @param {boolean} makeDefaultConfig - should update the default config or not
* @param {boolean} overwriteInitialConfig - should update the initial config or not
*/
updateOptionsInternal (options, redraw = false, animate = true, makeDefaultConfig = false) {
updateOptionsInternal (options, redraw = false, animate = true, overwriteInitialConfig = false) {
let w = this.w
this.w.config.chart.animations.dynamicAnimation.enabled = animate

Expand Down Expand Up @@ -366,9 +366,8 @@ class ApexCharts {

w.config = Utils.extend(w.config, options)

if (makeDefaultConfig) {
if (overwriteInitialConfig) {
w.globals.initialConfig = Utils.extend({}, w.config)
w.globals.initialSeries = JSON.parse(JSON.stringify(w.globals.initialConfig.series))
}
}

Expand All @@ -380,36 +379,29 @@ class ApexCharts {
*
* @param {array} series - New series which will override the existing
*/
updateSeries (newSeries = [], animate = true, makeDefaultConfig = false) {
return this.updateSeriesInternal(newSeries, animate, makeDefaultConfig)
updateSeries (newSeries = [], animate = true, overwriteInitialSeries = true) {
return this.updateSeriesInternal(newSeries, animate, overwriteInitialSeries)
}

/**
* Private method to update Series.
*
* @param {array} series - New series which will override the existing
*/
updateSeriesInternal (newSeries, animate, makeDefaultConfig) {
updateSeriesInternal (newSeries, animate, overwriteInitialSeries = false) {
const w = this.w
this.w.config.chart.animations.dynamicAnimation.enabled = animate
let series = new Series(this.ctx)

w.globals.dataChanged = true

// while updateing pie/donut series, user completely changed the series length too
// if (!w.globals.axisCharts && newSeries.length !== w.globals.series.length) {
// w.globals.dataChanged = false
// animate = false
// }

if (animate) {
series.getPreviousPaths()
}

w.config.series = newSeries.slice()
if (makeDefaultConfig) {
w.globals.initialConfig = Utils.extend({}, w.config)
w.globals.initialSeries = JSON.parse(JSON.stringify(w.globals.initialConfig.series))
if (overwriteInitialSeries) {
w.globals.initialSeries = JSON.parse(JSON.stringify(w.config.series))
}

return this.update()
Expand All @@ -420,7 +412,7 @@ class ApexCharts {
*
* @param {array} newData - New data in the same format as series
*/
appendData (newData) {
appendData (newData, overwriteInitialSeries = true) {
let me = this

let series = new Series(me.ctx)
Expand All @@ -439,9 +431,9 @@ class ApexCharts {
}
}
me.w.config.series = newSeries

me.w.globals.initialConfig = Utils.extend({}, me.w.config)
me.w.globals.initialSeries = JSON.parse(JSON.stringify(me.w.globals.initialConfig.series))
if (overwriteInitialSeries) {
me.w.globals.initialSeries = JSON.parse(JSON.stringify(me.w.config.series))
}

return this.update()
}
Expand Down
3 changes: 0 additions & 3 deletions src/modules/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class Range {
let valuesDivider = Math.abs(yMax - yMin) / ticks
for (let i = 0; i <= ticks - 1; i++) {
v = v + valuesDivider
if (v % 1 !== 0 && typeof (toFixed) !== 'undefined') {
v = parseFloat(v.toFixed(toFixed))
}
result.push(v)
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class Toolbar {
xaxis.min = w.globals.initialConfig.xaxis.min
xaxis.max = w.globals.initialConfig.xaxis.max

me.ctx.updateOptionsInternal(w.globals.initialConfig, false, true)
me.ctx.updateSeriesInternal(w.globals.initialSeries, true)
}
}

Expand Down

0 comments on commit c9d0664

Please sign in to comment.