Skip to content

Commit

Permalink
Added new method, Series.removePoint, to allow removing points that a…
Browse files Browse the repository at this point in the history
…re not instanciated on demand.
  • Loading branch information
TorsteinHonsi committed Nov 19, 2014
1 parent 1579365 commit 7377b2c
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 124 deletions.
74 changes: 43 additions & 31 deletions js/highcharts.src.js
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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
*
Expand Down
74 changes: 43 additions & 31 deletions js/highmaps.src.js
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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
*
Expand Down
74 changes: 43 additions & 31 deletions js/highstock.src.js
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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
*
Expand Down
74 changes: 43 additions & 31 deletions js/parts/Dynamics.js
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions samples/highcharts/members/series-removepoint/demo.details
@@ -0,0 +1,5 @@
---
name: Highcharts Demo
authors:
- Torstein Hønsi
...
4 changes: 4 additions & 0 deletions samples/highcharts/members/series-removepoint/demo.html
@@ -0,0 +1,4 @@
<script src="http://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px; min-width: 310px; max-width: 800px"></div>
<button id="remove" class="autocompare">Remove point and pan</button>

0 comments on commit 7377b2c

Please sign in to comment.