Skip to content

Commit ddb6d79

Browse files
authored
feat: add pause functionality in ThermalChart (#1859)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent a83f891 commit ddb6d79

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

src/components/ui/AppChart.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
ref="chart"
1010
style="overflow: initial;"
1111
:option="opts"
12-
:update-options="{ notMerge: true }"
13-
:init-options="{ renderer: 'canvas' }"
12+
:update-options="updateOptions"
13+
:init-options="initOptions"
1414
autoresize
1515
/>
1616
</div>
@@ -39,6 +39,12 @@ export default class AppChart extends Vue {
3939
@Ref('chart')
4040
readonly chart!: ECharts
4141
42+
// Stable references so component re-renders don't make vue-echarts dispose/
43+
// re-init the chart or re-apply the options, both of which would wipe the
44+
// imperatively-set dataset and blank the chart.
45+
readonly updateOptions = Object.freeze({ notMerge: true })
46+
readonly initOptions = Object.freeze({ renderer: 'canvas' })
47+
4248
ready = false
4349
4450
@Watch('data')

src/components/widgets/bedmesh/BedMeshChart.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<e-chart
99
ref="chart"
1010
:option="opts"
11-
:update-options="{ notMerge: false }"
12-
:init-options="{ renderer: 'canvas' }"
11+
:update-options="updateOptions"
12+
:init-options="initOptions"
1313
autoresize
1414
/>
1515

@@ -44,6 +44,11 @@ export default class BedMeshChart extends Mixins(BrowserMixin) {
4444
@Ref('chart')
4545
readonly chart!: ECharts
4646
47+
// Stable references so component re-renders don't make vue-echarts dispose/
48+
// re-init the chart, which would reset the 3D camera (rotation/zoom) state.
49+
readonly updateOptions = Object.freeze({ notMerge: false })
50+
readonly initOptions = Object.freeze({ renderer: 'canvas' })
51+
4752
get flatSurface (): boolean {
4853
return this.$typedState.mesh.flatSurface
4954
}

src/components/widgets/thermals/ThermalChart.vue

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,31 @@
99
ref="chart"
1010
style="overflow: initial;"
1111
:option="options"
12-
:update-options="{ notMerge: true }"
13-
:init-options="{ renderer: 'canvas' }"
12+
:update-options="updateOptions"
13+
:init-options="initOptions"
1414
autoresize
1515
@legendselectchanged="handleLegendSelectChanged"
1616
@legendselected="handleLegendSelectChanged"
1717
@legendunselected="handleLegendSelectChanged"
1818
/>
19+
20+
<div class="chart-options">
21+
<v-tooltip bottom>
22+
<template #activator="{ on, attrs }">
23+
<v-btn
24+
v-bind="attrs"
25+
icon
26+
small
27+
tabindex="-1"
28+
v-on="on"
29+
@click="togglePause"
30+
>
31+
<v-icon>{{ paused ? '$resume' : '$pause' }}</v-icon>
32+
</v-btn>
33+
</template>
34+
<span>{{ paused ? $t('app.general.btn.resume') : $t('app.general.btn.pause') }}</span>
35+
</v-tooltip>
36+
</div>
1937
</div>
2038
</template>
2139

@@ -34,10 +52,25 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
3452
@Ref('chart')
3553
readonly chart!: ECharts
3654
55+
// Stable references so component re-renders (e.g. toggling pause) don't cause
56+
// vue-echarts to dispose/re-init the chart or re-apply the options, both of
57+
// which would wipe the imperatively-set dataset and blank the chart.
58+
readonly updateOptions = Object.freeze({ notMerge: true })
59+
readonly initOptions = Object.freeze({ renderer: 'canvas' })
60+
3761
loading = false
62+
paused = false
3863
series: LineSeriesOption[] = []
3964
initialSelected: Record<string, boolean> = {}
4065
66+
togglePause () {
67+
this.paused = !this.paused
68+
69+
if (!this.paused) {
70+
this.onDataChange(this.chartData)
71+
}
72+
}
73+
4174
handleLegendSelectChanged (event: { selected: Record<string, boolean> }) {
4275
this.$typedDispatch('charts/saveSelectedLegends', event.selected)
4376
@@ -73,7 +106,11 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
73106
74107
@Watch('chartData')
75108
onDataChange (data: any) {
76-
if (this.chart && !this.loading) {
109+
if (
110+
this.chart &&
111+
!this.loading &&
112+
!this.paused
113+
) {
77114
this.chart.setOption({
78115
dataset: {
79116
source: data
@@ -433,6 +470,16 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
433470

434471
<style lang='scss' scoped>
435472
.chart {
473+
position: relative;
436474
width: 100%;
437475
}
476+
477+
.chart-options {
478+
position: absolute;
479+
top: 0;
480+
right: 0;
481+
padding: 2px 0px;
482+
margin-right: 16px;
483+
z-index: 1;
484+
}
438485
</style>

0 commit comments

Comments
 (0)