Skip to content

Commit 15b7b1d

Browse files
committed
WIP
Added support for discrete items to use oh-state-series on a separate grid BUG: Had to add this.showChart = false in updateItems in order for echarts to update the options w/o error when there are multiple unit y-axis value-series. However, with that change, when selecting additional items from the item list - it now generates a Vue rendterItem error. Signed-off-by: Jeff James <[email protected]>
1 parent 863832e commit 15b7b1d

File tree

3 files changed

+60
-48
lines changed

3 files changed

+60
-48
lines changed

bundles/org.openhab.ui/web/src/assets/i18n/analyzer/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"analyzer.series.table.type.bar": "Bar",
1414
"analyzer.series.table.type.line": "Line",
1515
"analyzer.series.table.type.area": "Area",
16+
"analyzer.series.table.type.state": "State",
1617
"analyzer.series.table.type.heatmap": "Heatmap",
1718
"analyzer.series.table.na": "N/A",
1819
"analyzer.coords": "Coords",

bundles/org.openhab.ui/web/src/pages/analyzer/analyzer.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
<f7-segmented round>
7070
<f7-button v-if="!options.discrete && coordSystem === 'aggregate' && aggregateDimensions === 1" small outline style="width: 60px" :fill="options.type === 'bar'" @click="options.type = 'bar'" v-t="'analyzer.series.table.type.bar'" />
7171
<f7-button v-if="!options.discrete && coordSystem !== 'calendar' && aggregateDimensions === 1" small outline style="width: 60px" :fill="options.type === 'line'" @click="options.type = 'line'" v-t="'analyzer.series.table.type.line'" />
72-
<f7-button v-if="coordSystem === 'time' || (coordSystem === 'aggregate' && aggregateDimensions === 1)" small outline style="width: 60px" :fill="options.type === 'area'" @click="options.type = 'area'" v-t="'analyzer.series.table.type.area'" />
72+
<f7-button v-if="!options.discrete && coordSystem === 'time' || (coordSystem === 'aggregate' && aggregateDimensions === 1)" small outline style="width: 60px" :fill="options.type === 'area'" @click="options.type = 'area'" v-t="'analyzer.series.table.type.area'" />
73+
<f7-button v-if="options.discrete && coordSystem === 'time' || (coordSystem === 'aggregate' && aggregateDimensions === 1)" small outline style="width: 60px" :fill="options.type === 'state'" @click="options.type = 'state'" v-t="'analyzer.series.table.type.state'" />
7374
<f7-button v-if="coordSystem === 'calendar' || (coordSystem === 'aggregate' && aggregateDimensions === 2)" small fill outline style="width: 90px" v-t="'analyzer.series.table.type.heatmap'" />
7475
</f7-segmented>
7576
</td>
@@ -261,6 +262,7 @@ export default {
261262
items: null,
262263
seriesOptions: {},
263264
valueAxesOptions: {},
265+
categoryAxisValues: [],
264266
orientation: (this.$device.desktop || this.$device.ipad) ? 'horizontal' : 'vertical',
265267
period: 'D',
266268
chartType: '',
@@ -335,9 +337,11 @@ export default {
335337
updateItems (itemNames) {
336338
this.itemNames = itemNames
337339
const promises = itemNames.map((n) => this.$oh.api.get('/rest/items/' + n))
340+
this.showChart = false
338341
return Promise.all(promises).then((resp) => {
339342
this.$set(this, 'items', [])
340343
this.$set(this, 'valueAxesOptions', [])
344+
this.$set(this, 'categoryAxisValues', [])
341345
resp.forEach((item) => {
342346
this.items.push(item)
343347
@@ -363,6 +367,9 @@ export default {
363367
this.valueAxesOptions.push({ name: unit, unit, split: 'line' })
364368
this.$set(seriesOptions, 'valueAxisIndex', this.valueAxesOptions.length - 1)
365369
}
370+
} else if (seriesOptions.type === 'state') {
371+
this.categoryAxisValues.unshift(item.name)
372+
this.$set(seriesOptions, 'yValue', this.categoryAxisValues.length - 1)
366373
}
367374
})
368375
this.$set(this, 'items', resp)
@@ -383,11 +390,11 @@ export default {
383390
discrete: true
384391
}
385392
386-
if (item.type.indexOf('Number') === 0 || item.type === 'Dimmer') seriesOptions.discrete = false
387-
if (item.groupType && (item.groupType.indexOf('Number') === 0 || item.groupType === 'Dimmer')) seriesOptions.discrete = false
393+
if (item.type.indexOf('Number') === 0) seriesOptions.discrete = false
394+
if (item.groupType && (item.groupType.indexOf('Number') === 0)) seriesOptions.discrete = false
388395
if (!seriesOptions.discrete && this.coordSystem === 'aggregate' && this.aggregateDimensions === 1) seriesOptions.type = 'bar'
389396
if (!seriesOptions.discrete && (this.coordSystem === 'calendar' || (this.coordSystem === 'aggregate' && this.aggregateDimensions === 2))) seriesOptions.type = 'heatmap'
390-
if (seriesOptions.discrete) seriesOptions.type = 'area'
397+
if (seriesOptions.discrete) seriesOptions.type = 'state'
391398
392399
this.$set(this.seriesOptions, item.name, seriesOptions)
393400
},

bundles/org.openhab.ui/web/src/pages/analyzer/chart-time.js

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,47 @@ export default {
99
slots: {}
1010
}
1111

12-
page.slots.grid = [{ component: 'oh-chart-grid', config: { includeLabels: true } }]
12+
let valueGrid = (analyzer.valueAxesOptions.length > 0)
13+
let categoryGrid = (analyzer.categoryAxisValues.length > 0)
1314

14-
page.slots.xAxis = [
15-
{
16-
component: 'oh-time-axis',
17-
config: {
18-
gridIndex: 0
19-
}
20-
}
21-
]
15+
page.slots.grid = []
16+
page.slots.xAxis = []
17+
page.slots.yAxis = []
18+
page.slots.series = []
2219

23-
page.slots.yAxis = analyzer.valueAxesOptions.map((a) => {
24-
return {
25-
component: 'oh-value-axis',
20+
if (valueGrid) {
21+
page.slots.grid.push({ component: 'oh-chart-grid', config: { includeLabels: true, bottom: (categoryGrid) ? '55%' : 60 } })
22+
page.slots.xAxis.push({ component: 'oh-time-axis', config: { gridIndex: 0 } })
23+
analyzer.valueAxesOptions.forEach((a) => {
24+
page.slots.yAxis.push({
25+
component: 'oh-value-axis',
26+
config: {
27+
gridIndex: 0,
28+
name: a.name || a.unit,
29+
...(a.min && a.min !== '') && { min: parseFloat(a.min) },
30+
...(a.max && a.max !== '') && { max: parseFloat(a.max) },
31+
scale: a.scale,
32+
...(a.split === 'none' || a.split === 'area' || a.split === 'area+minor') && { splitLine: { show: false } },
33+
...(a.split === 'line+minor' || a.split === 'area+minor' || a.split === 'all') && { minorTick: { show: true }, minorSplitLine: { show: true } },
34+
...(a.split === 'area' || a.split === 'line+area' || a.split === 'area+minor' || a.split === 'all') && { splitArea: { show: true } }
35+
}
36+
})
37+
})
38+
}
39+
40+
let categoryGridIndex = (valueGrid) ? 1 : 0
41+
if (categoryGrid) {
42+
page.slots.grid.push({ component: 'oh-chart-grid', config: { includeLabels: true, top: (valueGrid) ? '55%' : 60 } })
43+
page.slots.xAxis.push({ component: 'oh-time-axis', config: { gridIndex: categoryGridIndex } })
44+
page.slots.yAxis.push({
45+
component: 'oh-category-axis',
2646
config: {
27-
gridIndex: 0,
28-
name: a.name || a.unit,
29-
...(a.min && a.min !== '') && { min: parseFloat(a.min) },
30-
...(a.max && a.max !== '') && { max: parseFloat(a.max) },
31-
scale: a.scale,
32-
...(a.split === 'none' || a.split === 'area' || a.split === 'area+minor') && { splitLine: { show: false } },
33-
...(a.split === 'line+minor' || a.split === 'area+minor' || a.split === 'all') && { minorTick: { show: true }, minorSplitLine: { show: true } },
34-
...(a.split === 'area' || a.split === 'line+area' || a.split === 'area+minor' || a.split === 'all') && { splitArea: { show: true } }
47+
data: analyzer.categoryAxisValues.map((itemName) => analyzer.items.find((item) => item.name === itemName).label),
48+
gridIndex: categoryGridIndex
3549
}
36-
}
37-
})
50+
})
51+
}
52+
3853
if (page.slots.yAxis.length === 0) {
3954
// add a default axis if none was found (for instance, only discrete values)
4055
page.slots.yAxis.push({
@@ -49,29 +64,18 @@ export default {
4964
const seriesOptions = analyzer.seriesOptions[item.name]
5065

5166
if (seriesOptions.discrete) {
52-
return {
53-
component: 'oh-time-series',
67+
let series = {
68+
component: 'oh-state-series',
5469
config: {
55-
name: seriesOptions.name,
56-
gridIndex: 0,
57-
xAxisIndex: 0,
58-
yAxisIndex: 0,
59-
type: 'line',
60-
areaStyle: seriesOptions.type === 'area' ? {} : undefined
61-
},
62-
slots: {
63-
markArea: [
64-
{
65-
component: 'oh-mark-area',
66-
config: {
67-
name: item.name,
68-
item: item.name,
69-
silent: seriesOptions.silent
70-
}
71-
}
72-
]
70+
item: item.name,
71+
name: item.label,
72+
xAxisIndex: categoryGridIndex,
73+
yAxisIndex: page.slots.yAxis.length - 1,
74+
yValue: seriesOptions.yValue
7375
}
7476
}
77+
78+
return series
7579
}
7680

7781
const markLine = (seriesOptions.markers === 'avg' || seriesOptions.markers === 'all') ? {
@@ -93,7 +97,6 @@ export default {
9397
component: 'oh-time-series',
9498
config: {
9599
name: seriesOptions.name,
96-
gridIndex: 0,
97100
xAxisIndex: 0,
98101
yAxisIndex: seriesOptions.valueAxisIndex,
99102
type: 'line',
@@ -129,7 +132,8 @@ export default {
129132
{
130133
component: 'oh-chart-datazoom',
131134
config: {
132-
type: 'inside'
135+
type: 'inside',
136+
xAxisIndex: (categoryGrid) ? [0, 1] : 0
133137
}
134138
}
135139
]

0 commit comments

Comments
 (0)