Skip to content

Commit 849b7ca

Browse files
authored
fix: use full Klipper key for thermal data storage (#1167)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent 273092d commit 849b7ca

File tree

5 files changed

+41
-45
lines changed

5 files changed

+41
-45
lines changed

src/components/widgets/thermals/TemperatureCard.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,17 @@ export default class TemperatureCard extends Mixins(StateMixin, BrowserMixin) {
162162
// If this has a target, toggle that too.
163163
if (this.chartVisible) {
164164
if ('target' in item) {
165-
this.thermalChartElement.legendToggleSelect(item.name + 'Target')
165+
this.thermalChartElement.legendToggleSelect(item.key + 'Target')
166166
}
167-
this.thermalChartElement.legendToggleSelect(item.name)
167+
this.thermalChartElement.legendToggleSelect(item.key)
168168
}
169169
}
170170
171171
legendTogglePowerSelect (item: Heater | Fan) {
172172
if (this.chartVisible) {
173173
const name = ('speed' in item)
174-
? item.name + 'Speed'
175-
: item.name + 'Power'
174+
? item.key + 'Speed'
175+
: item.key + 'Power'
176176
this.thermalChartElement.legendToggleSelect(name)
177177
}
178178
}

src/components/widgets/thermals/TemperatureTargets.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<tbody v-if="klippyReady">
2929
<tr
3030
v-for="item in heaters"
31-
:key="item.name"
31+
:key="item.key"
3232
>
3333
<td>
3434
<v-icon
@@ -40,7 +40,7 @@
4040
</td>
4141
<td class="temp-name">
4242
<span
43-
:class="{ 'active': !(item.name in chartSelectedLegends) || chartSelectedLegends[item.name] }"
43+
:class="{ 'active': !(item.key in chartSelectedLegends) || chartSelectedLegends[item.key] }"
4444
class="legend-item"
4545
@click="$emit('legendClick', item)"
4646
>
@@ -49,7 +49,7 @@
4949
</td>
5050
<td class="temp-power">
5151
<span
52-
:class="{ 'active': chartSelectedLegends[item.name + 'Power'] }"
52+
:class="{ 'active': chartSelectedLegends[item.key + 'Power'] }"
5353
class="legend-item"
5454
@click="$emit('legendPowerClick', item)"
5555
>
@@ -64,7 +64,7 @@
6464
class="rate-of-change"
6565
>
6666
<span
67-
:class="{ 'active': chartSelectedLegends[item.name + 'Power'] }"
67+
:class="{ 'active': chartSelectedLegends[item.key + 'Power'] }"
6868
class="legend-item"
6969
>
7070
<span>{{ getRateOfChange(item) }}<small>&deg;C/s</small></span>
@@ -97,7 +97,7 @@
9797
</tr>
9898
<tr
9999
v-for="item in fans"
100-
:key="item.name"
100+
:key="item.key"
101101
>
102102
<td>
103103
<v-icon
@@ -110,7 +110,7 @@
110110
</td>
111111
<td class="temp-name">
112112
<span
113-
:class="{ 'active': !(item.name in chartSelectedLegends) || chartSelectedLegends[item.name] }"
113+
:class="{ 'active': !(item.key in chartSelectedLegends) || chartSelectedLegends[item.key] }"
114114
class="legend-item"
115115
@click="$emit('legendClick', item)"
116116
>
@@ -120,7 +120,7 @@
120120
<td class="temp-power">
121121
<span
122122
v-if="item.speed"
123-
:class="{ 'active': chartSelectedLegends[item.name + 'Speed'] }"
123+
:class="{ 'active': chartSelectedLegends[item.key + 'Speed'] }"
124124
class="legend-item"
125125
@click="$emit('legendPowerClick', item)"
126126
>
@@ -138,7 +138,7 @@
138138
class="rate-of-change"
139139
>
140140
<span
141-
:class="{ 'active': chartSelectedLegends[item.name + 'Power'] }"
141+
:class="{ 'active': chartSelectedLegends[item.key + 'Power'] }"
142142
class="legend-item"
143143
>
144144
<span>{{ getRateOfChange(item) }}<small>&deg;C/s</small></span>
@@ -179,7 +179,7 @@
179179
</tr>
180180
<tr
181181
v-for="item in sensors"
182-
:key="item.name"
182+
:key="item.key"
183183
>
184184
<td>
185185
<v-icon
@@ -191,7 +191,7 @@
191191
</td>
192192
<td class="temp-name">
193193
<span
194-
:class="{ 'active': !(item.name in chartSelectedLegends) || chartSelectedLegends[item.name] }"
194+
:class="{ 'active': !(item.key in chartSelectedLegends) || chartSelectedLegends[item.key] }"
195195
class="legend-item"
196196
@click="$emit('legendClick', item)"
197197
>
@@ -314,14 +314,14 @@ export default class TemperatureTargets extends Mixins(StateMixin) {
314314
getRateOfChange (item: Heater | Sensor) {
315315
const recentChartData = this.chartData
316316
.slice(-5)
317-
const filteredChartData = takeRightWhile(recentChartData, x => x[item.name] != null)
317+
const filteredChartData = takeRightWhile(recentChartData, x => x[item.key] != null)
318318
319319
let rateOfChange = 0
320320
if (filteredChartData.length >= 2) {
321321
const curr = filteredChartData[filteredChartData.length - 1]
322322
const prev = filteredChartData[0]
323323
324-
rateOfChange = (+curr[item.name] - +prev[item.name]) / (+curr.date - +prev.date) * 1000
324+
rateOfChange = (+curr[item.key] - +prev[item.key]) / (+curr.date - +prev.date) * 1000
325325
326326
if (Math.abs(rateOfChange) < 0.05) {
327327
rateOfChange = 0 // prevent constant change of sign

src/components/widgets/thermals/ThermalChart.vue

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,10 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
8888
const keys = this.$store.getters['printer/getChartableSensors'] as string[]
8989
9090
keys.forEach((key) => {
91-
const label = key.split(' ', 2).pop() || ''
92-
93-
this.series.push(this.createSeries(label, key))
94-
if (dataKeys.includes(label + 'Target')) this.series.push(this.createSeries(label + 'Target', key))
95-
if (dataKeys.includes(label + 'Power')) this.series.push(this.createSeries(label + 'Power', key))
96-
if (dataKeys.includes(label + 'Speed')) this.series.push(this.createSeries(label + 'Speed', key))
91+
this.series.push(this.createSeries(key))
92+
if (dataKeys.includes(`${key}Target`)) this.series.push(this.createSeries(`${key}Target`))
93+
if (dataKeys.includes(`${key}Power`)) this.series.push(this.createSeries(`${key}Power`))
94+
if (dataKeys.includes(`${key}Speed`)) this.series.push(this.createSeries(`${key}Speed`))
9795
})
9896
}
9997
@@ -171,11 +169,12 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
171169
param.seriesName &&
172170
param.value[param.seriesName] != null
173171
) {
172+
const name = param.seriesName.split(' ', 2).pop()
174173
text += `
175174
<div>
176175
${param.marker}
177176
<span style="font-size:${fontSize}px;color:${fontColor};font-weight:400;margin-left:2px">
178-
${this.$filters.startCase(param.seriesName)}:
177+
${this.$filters.startCase(name)}:
179178
</span>
180179
<span style="float:right;margin-left:20px;font-size:${fontSize}px;color:${fontColor};font-weight:900">
181180
${param.value[param.seriesName].toFixed(2)}<small>°C</small>`
@@ -289,13 +288,13 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
289288
return options
290289
}
291290
292-
createSeries (label: string, key: string) {
291+
createSeries (key: string) {
293292
// Grab the color
294293
const color = this.$colorset.next(getKlipperType(key), key)
295294
296295
// Base properties
297296
const series: any = {
298-
name: label,
297+
name: key,
299298
// id,
300299
type: 'line',
301300
yAxisIndex: 0,
@@ -314,11 +313,11 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
314313
opacity: 1
315314
},
316315
areaStyle: { opacity: 0.05 },
317-
encode: { x: 'date', y: label }
316+
encode: { x: 'date', y: key }
318317
}
319318
320319
// If this is a target, adjust its display.
321-
if (label.toLowerCase().endsWith('target')) {
320+
if (key.toLowerCase().endsWith('target')) {
322321
series.yAxisIndex = 0
323322
series.emphasis.lineStyle.width = 1
324323
series.lineStyle.width = 1
@@ -329,8 +328,8 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
329328
330329
// If this is a power or speed, adjust its display.
331330
if (
332-
label.toLowerCase().endsWith('power') ||
333-
label.toLowerCase().endsWith('speed')
331+
key.toLowerCase().endsWith('power') ||
332+
key.toLowerCase().endsWith('speed')
334333
) {
335334
series.yAxisIndex = 1
336335
series.emphasis.lineStyle.width = 1
@@ -342,12 +341,12 @@ export default class ThermalChart extends Mixins(BrowserMixin) {
342341
343342
// Set the initial legend state (power and speed default off)
344343
const storedLegends = this.$store.getters['charts/getSelectedLegends']
345-
if (storedLegends[label] !== undefined) {
346-
this.initialSelected[label] = storedLegends[label]
344+
if (storedLegends[key] !== undefined) {
345+
this.initialSelected[key] = storedLegends[key]
347346
} else {
348-
this.initialSelected[label] = !(
349-
label.toLowerCase().endsWith('power') ||
350-
label.toLowerCase().endsWith('speed')
347+
this.initialSelected[key] = !(
348+
key.toLowerCase().endsWith('power') ||
349+
key.toLowerCase().endsWith('speed')
351350
)
352351
}
353352

src/store/chart_helpers.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,14 @@ export const handleAddChartEntry = (retention: number, state: RootState, commit:
132132
const keys: string[] = getters.getChartableSensors
133133

134134
keys.forEach((key) => {
135-
const label = key.split(' ', 2).pop() || ''
136135
const temp = state.printer.printer[key].temperature
137136
const target = state.printer.printer[key].target
138137
const power = state.printer.printer[key].power
139138
const speed = state.printer.printer[key].speed
140-
r[label] = temp
141-
if (target != null) r[`${label}Target`] = target
142-
if (power != null) r[`${label}Power`] = power
143-
if (speed != null) r[`${label}Speed`] = speed
139+
r[key] = temp
140+
if (target != null) r[`${key}Target`] = target
141+
if (power != null) r[`${key}Power`] = power
142+
if (speed != null) r[`${key}Speed`] = speed
144143
})
145144

146145
return r

src/store/charts/actions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ export const actions: ActionTree<ChartState, RootState> = {
7171
date
7272
}
7373
keys.forEach(key => {
74-
const label = key.split(' ', 2).pop() || ''
75-
7674
if (rootState.printer.printer[key]) {
77-
r[label] = payload[key].temperatures[i]
78-
if ('targets' in payload[key]) r[`${label}Target`] = payload[key].targets[i]
79-
if ('powers' in payload[key]) r[`${label}Power`] = payload[key].powers[i]
80-
if ('speeds' in payload[key]) r[`${label}Speed`] = payload[key].speeds[i]
75+
r[key] = payload[key].temperatures[i]
76+
if ('targets' in payload[key]) r[`${key}Target`] = payload[key].targets[i]
77+
if ('powers' in payload[key]) r[`${key}Power`] = payload[key].powers[i]
78+
if ('speeds' in payload[key]) r[`${key}Speed`] = payload[key].speeds[i]
8179
}
8280
})
8381
d.push(r)

0 commit comments

Comments
 (0)