Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed redundant reinit after full update + fixed batch series update #84

Merged
merged 4 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions demo/examples/dynamic-updates.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ <h1>Dynamic updates</h1>
<div class="container">
<div id="chart8"></div>
<button id="changeForTooltip">Tooltip update</button>
<button id="removeLines">Remove lines</button>
<button id="addLines">Add lines</button>
</div>
</div>

Expand Down Expand Up @@ -376,6 +378,11 @@ <h1>Dynamic updates</h1>
color: 'green',
id: '1',
},
{
data: [200, 100],
color: 'red',
id: '2',
},
],
});

Expand All @@ -392,6 +399,27 @@ <h1>Dynamic updates</h1>
],
});
};

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,
},
],
});
};
</script>
</body>
</html>
35 changes: 35 additions & 0 deletions demo/examples/shared-crosshairs.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ <h1>Shared crosshairs</h1>
<div id="chart4" class="container right"></div>
</div>

<h2>Sync on dynamic update</h2>
<div class="grid">
<div id="chart5" class="container left"></div>
<div id="chart6" class="container right"></div>
</div>
<button id="update">Update</button>

<script>
const showTooltip = (y) => y.state.isMouseOver;

Expand Down Expand Up @@ -68,6 +75,34 @@ <h1>Shared crosshairs</h1>

y4.subscribe();
y3.subscribe();

const y5 = new Yagr(chart5, {
title: {text: 'Example 5'},
timeline: [1, 2, 3],
series: [{data: [1, 2, 3], color: 'red'}],
cursor: {sync: 'c'},
});

const y6 = new Yagr(chart6, {
title: {text: 'Example 6'},
timeline: [1, 2, 3],
series: [{data: [3, 2, 1], color: 'green'}],
cursor: {sync: 'c'},
});

y5.subscribe();
y6.subscribe();

update.onclick = () => {
y5.setConfig({
timeline: [1, 2, 3, 4],
series: [{data: [1, 2, 3, 4], color: 'red'}],
});
y6.setConfig({
timeline: [1, 2, 3, 4],
series: [{data: [1, 2, 3, 4], color: 'green'}],
});
};
</script>
</body>
</html>
1 change: 0 additions & 1 deletion src/YagrCore/mixins/batch-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export class BatchMixin<T extends MinimalValidConfig> {
this.uplot.destroy();
this.uplot = new UPlot(this.options, this.series, this.initRender);
this.plugins.legend?.redraw();
this.init();
})
.inStage('listen');
}
Expand Down
3 changes: 2 additions & 1 deletion src/YagrCore/mixins/dynamic-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down