From 7377b2c8e2717ab35339b501ac3bbebac81b7400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torstein=20H=C3=B8nsi?= Date: Wed, 19 Nov 2014 11:36:33 +0100 Subject: [PATCH] Added new method, Series.removePoint, to allow removing points that are not instanciated on demand. --- js/highcharts.src.js | 74 +++++++++++-------- js/highmaps.src.js | 74 +++++++++++-------- js/highstock.src.js | 74 +++++++++++-------- js/parts/Dynamics.js | 74 +++++++++++-------- .../members/series-removepoint/demo.details | 5 ++ .../members/series-removepoint/demo.html | 4 + .../members/series-removepoint/demo.js | 34 +++++++++ 7 files changed, 215 insertions(+), 124 deletions(-) create mode 100644 samples/highcharts/members/series-removepoint/demo.details create mode 100644 samples/highcharts/members/series-removepoint/demo.html create mode 100644 samples/highcharts/members/series-removepoint/demo.js diff --git a/js/highcharts.src.js b/js/highcharts.src.js index 63e0786f83a..0e728f1ce7c 100644 --- a/js/highcharts.src.js +++ b/js/highcharts.src.js @@ -14645,37 +14645,7 @@ extend(Point.prototype, { * configuration */ remove: function (redraw, animation) { - var point = this, - series = point.series, - points = series.points, - chart = series.chart, - i, - data = series.data; - - setAnimation(animation, chart); - redraw = pick(redraw, true); - - // fire the event with a default handler of removing the point - point.firePointEvent('remove', null, function () { - - // splice all the parallel arrays - i = inArray(point, data); - if (data.length === points.length) { - points.splice(i, 1); - } - data.splice(i, 1); - series.options.data.splice(i, 1); - series.updateParallelArrays(point, 'splice', i, 1); - - point.destroy(); - - // redraw - series.isDirty = true; - series.isDirtyData = true; - if (redraw) { - chart.redraw(); - } - }); + this.series.removePoint(inArray(this, this.series.data), redraw, animation); } }); @@ -14778,6 +14748,48 @@ extend(Series.prototype, { } }, + /** + * Remove a point (rendered or not), by index + */ + removePoint: function (i, redraw, animation) { // docs: new method on Series object. Sample created: series-removepoint + + var series = this, + data = series.data, + point = data[i], + points = series.points, + chart = series.chart, + remove = function () { + + if (data.length === points.length) { + points.splice(i, 1); + } + data.splice(i, 1); + series.options.data.splice(i, 1); + series.updateParallelArrays(point || { series: series }, 'splice', i, 1); + + if (point) { + point.destroy(); + } + + // redraw + series.isDirty = true; + series.isDirtyData = true; + if (redraw) { + chart.redraw(); + } + }; + + setAnimation(animation, chart); + redraw = pick(redraw, true); + + // Fire the event with a default handler of removing the point + if (point) { + point.firePointEvent('remove', null, remove); + } else { + remove(); + } + }, + /** * Remove a series and optionally redraw the chart * diff --git a/js/highmaps.src.js b/js/highmaps.src.js index 0d4d510fd25..8df9d3abc82 100644 --- a/js/highmaps.src.js +++ b/js/highmaps.src.js @@ -13853,37 +13853,7 @@ extend(Point.prototype, { * configuration */ remove: function (redraw, animation) { - var point = this, - series = point.series, - points = series.points, - chart = series.chart, - i, - data = series.data; - - setAnimation(animation, chart); - redraw = pick(redraw, true); - - // fire the event with a default handler of removing the point - point.firePointEvent('remove', null, function () { - - // splice all the parallel arrays - i = inArray(point, data); - if (data.length === points.length) { - points.splice(i, 1); - } - data.splice(i, 1); - series.options.data.splice(i, 1); - series.updateParallelArrays(point, 'splice', i, 1); - - point.destroy(); - - // redraw - series.isDirty = true; - series.isDirtyData = true; - if (redraw) { - chart.redraw(); - } - }); + this.series.removePoint(inArray(this, this.series.data), redraw, animation); } }); @@ -13986,6 +13956,48 @@ extend(Series.prototype, { } }, + /** + * Remove a point (rendered or not), by index + */ + removePoint: function (i, redraw, animation) { // docs: new method on Series object. Sample created: series-removepoint + + var series = this, + data = series.data, + point = data[i], + points = series.points, + chart = series.chart, + remove = function () { + + if (data.length === points.length) { + points.splice(i, 1); + } + data.splice(i, 1); + series.options.data.splice(i, 1); + series.updateParallelArrays(point || { series: series }, 'splice', i, 1); + + if (point) { + point.destroy(); + } + + // redraw + series.isDirty = true; + series.isDirtyData = true; + if (redraw) { + chart.redraw(); + } + }; + + setAnimation(animation, chart); + redraw = pick(redraw, true); + + // Fire the event with a default handler of removing the point + if (point) { + point.firePointEvent('remove', null, remove); + } else { + remove(); + } + }, + /** * Remove a series and optionally redraw the chart * diff --git a/js/highstock.src.js b/js/highstock.src.js index b4597200b5b..18d3f74377b 100644 --- a/js/highstock.src.js +++ b/js/highstock.src.js @@ -14645,37 +14645,7 @@ extend(Point.prototype, { * configuration */ remove: function (redraw, animation) { - var point = this, - series = point.series, - points = series.points, - chart = series.chart, - i, - data = series.data; - - setAnimation(animation, chart); - redraw = pick(redraw, true); - - // fire the event with a default handler of removing the point - point.firePointEvent('remove', null, function () { - - // splice all the parallel arrays - i = inArray(point, data); - if (data.length === points.length) { - points.splice(i, 1); - } - data.splice(i, 1); - series.options.data.splice(i, 1); - series.updateParallelArrays(point, 'splice', i, 1); - - point.destroy(); - - // redraw - series.isDirty = true; - series.isDirtyData = true; - if (redraw) { - chart.redraw(); - } - }); + this.series.removePoint(inArray(this, this.series.data), redraw, animation); } }); @@ -14778,6 +14748,48 @@ extend(Series.prototype, { } }, + /** + * Remove a point (rendered or not), by index + */ + removePoint: function (i, redraw, animation) { // docs: new method on Series object. Sample created: series-removepoint + + var series = this, + data = series.data, + point = data[i], + points = series.points, + chart = series.chart, + remove = function () { + + if (data.length === points.length) { + points.splice(i, 1); + } + data.splice(i, 1); + series.options.data.splice(i, 1); + series.updateParallelArrays(point || { series: series }, 'splice', i, 1); + + if (point) { + point.destroy(); + } + + // redraw + series.isDirty = true; + series.isDirtyData = true; + if (redraw) { + chart.redraw(); + } + }; + + setAnimation(animation, chart); + redraw = pick(redraw, true); + + // Fire the event with a default handler of removing the point + if (point) { + point.firePointEvent('remove', null, remove); + } else { + remove(); + } + }, + /** * Remove a series and optionally redraw the chart * diff --git a/js/parts/Dynamics.js b/js/parts/Dynamics.js index 39d90fa08f5..82954c75cd7 100644 --- a/js/parts/Dynamics.js +++ b/js/parts/Dynamics.js @@ -214,37 +214,7 @@ extend(Point.prototype, { * configuration */ remove: function (redraw, animation) { - var point = this, - series = point.series, - points = series.points, - chart = series.chart, - i, - data = series.data; - - setAnimation(animation, chart); - redraw = pick(redraw, true); - - // fire the event with a default handler of removing the point - point.firePointEvent('remove', null, function () { - - // splice all the parallel arrays - i = inArray(point, data); - if (data.length === points.length) { - points.splice(i, 1); - } - data.splice(i, 1); - series.options.data.splice(i, 1); - series.updateParallelArrays(point, 'splice', i, 1); - - point.destroy(); - - // redraw - series.isDirty = true; - series.isDirtyData = true; - if (redraw) { - chart.redraw(); - } - }); + this.series.removePoint(inArray(this, this.series.data), redraw, animation); } }); @@ -347,6 +317,48 @@ extend(Series.prototype, { } }, + /** + * Remove a point (rendered or not), by index + */ + removePoint: function (i, redraw, animation) { // docs: new method on Series object. Sample created: series-removepoint + + var series = this, + data = series.data, + point = data[i], + points = series.points, + chart = series.chart, + remove = function () { + + if (data.length === points.length) { + points.splice(i, 1); + } + data.splice(i, 1); + series.options.data.splice(i, 1); + series.updateParallelArrays(point || { series: series }, 'splice', i, 1); + + if (point) { + point.destroy(); + } + + // redraw + series.isDirty = true; + series.isDirtyData = true; + if (redraw) { + chart.redraw(); + } + }; + + setAnimation(animation, chart); + redraw = pick(redraw, true); + + // Fire the event with a default handler of removing the point + if (point) { + point.firePointEvent('remove', null, remove); + } else { + remove(); + } + }, + /** * Remove a series and optionally redraw the chart * diff --git a/samples/highcharts/members/series-removepoint/demo.details b/samples/highcharts/members/series-removepoint/demo.details new file mode 100644 index 00000000000..3361d2e5f99 --- /dev/null +++ b/samples/highcharts/members/series-removepoint/demo.details @@ -0,0 +1,5 @@ +--- + name: Highcharts Demo + authors: + - Torstein Hønsi +... \ No newline at end of file diff --git a/samples/highcharts/members/series-removepoint/demo.html b/samples/highcharts/members/series-removepoint/demo.html new file mode 100644 index 00000000000..7d8633f167f --- /dev/null +++ b/samples/highcharts/members/series-removepoint/demo.html @@ -0,0 +1,4 @@ + + +
+ \ No newline at end of file diff --git a/samples/highcharts/members/series-removepoint/demo.js b/samples/highcharts/members/series-removepoint/demo.js new file mode 100644 index 00000000000..3b3b843e56b --- /dev/null +++ b/samples/highcharts/members/series-removepoint/demo.js @@ -0,0 +1,34 @@ +$(function () { + $('#container').highcharts({ + + title: { + text: 'Remove cropped point' + }, + + subtitle: { + text: 'Click button to remove a point [0, 0] and shift zoom to verify that it is removed' + }, + + xAxis: { + min: 100 + }, + + series: [{ + data: (function (arr, i) { + for (i = 0; i < 200; i++) { + arr.push(i); + } + return arr; + }([])), + cropThreshold: 100 + }] + + }); + + $('#remove').click(function () { + var chart = $('#container').highcharts(); + chart.series[0].removePoint(0); + + chart.xAxis[0].setExtremes(0, 100); // Verify that point [0, 0] is removed + }); +}); \ No newline at end of file