From 5f181ec76dff76be93a8c811a2f69cb4fbfbf384 Mon Sep 17 00:00:00 2001 From: Trdat Mkrtchyan Date: Thu, 6 Jul 2023 14:38:50 +0400 Subject: [PATCH] fix: removed redundant reinit after full update + fixed batch series update (#84) * fix: fixed dynamic updates of series in case if changed only data * fix: removed redundant reinit after full update + fixed batch series update --- demo/examples/dynamic-updates.html | 28 +++++++++++++++++++++ demo/examples/shared-crosshairs.html | 35 ++++++++++++++++++++++++++ src/YagrCore/mixins/batch-updates.ts | 1 - src/YagrCore/mixins/dynamic-updates.ts | 3 ++- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/demo/examples/dynamic-updates.html b/demo/examples/dynamic-updates.html index 540c15e..7be3175 100644 --- a/demo/examples/dynamic-updates.html +++ b/demo/examples/dynamic-updates.html @@ -65,6 +65,8 @@

Dynamic updates

+ +
@@ -376,6 +378,11 @@

Dynamic updates

color: 'green', id: '1', }, + { + data: [200, 100], + color: 'red', + id: '2', + }, ], }); @@ -392,6 +399,27 @@

Dynamic updates

], }); }; + + window.removeLines.onclick = () => { + yagr8.setConfig({ + timeline: [100000, 200000], + series: [], + }); + }; + + window.addLines.onclick = () => { + yagr8.setConfig({ + timeline: [100000, 200000], + series: [ + ...yagr8.config.series, + { + data: [(Math.random() * 100) >> 0, (Math.random() * 100) >> 0], + color: randomColor(), + id: ('1' + Math.random() * 100) >> 0, + }, + ], + }); + }; diff --git a/demo/examples/shared-crosshairs.html b/demo/examples/shared-crosshairs.html index 98d2144..15faabe 100644 --- a/demo/examples/shared-crosshairs.html +++ b/demo/examples/shared-crosshairs.html @@ -30,6 +30,13 @@

Shared crosshairs

+

Sync on dynamic update

+
+
+
+
+ + diff --git a/src/YagrCore/mixins/batch-updates.ts b/src/YagrCore/mixins/batch-updates.ts index 45705bd..349809b 100644 --- a/src/YagrCore/mixins/batch-updates.ts +++ b/src/YagrCore/mixins/batch-updates.ts @@ -95,7 +95,6 @@ export class BatchMixin { this.uplot.destroy(); this.uplot = new UPlot(this.options, this.series, this.initRender); this.plugins.legend?.redraw(); - this.init(); }) .inStage('listen'); } diff --git a/src/YagrCore/mixins/dynamic-updates.ts b/src/YagrCore/mixins/dynamic-updates.ts index 4500ded..adf87a6 100644 --- a/src/YagrCore/mixins/dynamic-updates.ts +++ b/src/YagrCore/mixins/dynamic-updates.ts @@ -347,8 +347,9 @@ function setSeriesImpl( this.config.timeline.splice(0, timeline.length); } } else { - /** If we're adding new series */ + /** If we're adding new series or removing */ if ( + series.length !== this.config.series.length || series.some(({id}) => { return this.config.series.find((s) => s.id !== id); })