Skip to content

Commit

Permalink
better pivot names
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Petzold committed Jan 11, 2024
1 parent 3c43545 commit 178bba6
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/widget-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,23 @@ export class WidgetValue extends LitElement {
// ?.sort((a, b) => a.order - b.order)
?.forEach((ds) => {
// pivot data
const distincts = [...new Set(ds.data?.map((d: Data) => d.pivot))].filter(
(d) => d
) as string[]
const distincts = [...new Set(ds.data?.map((d: Data) => d.pivot))].sort() as string[]
ds.needleValue = undefined
if (distincts.length > 1 || distincts[0] !== undefined) {
distincts.forEach((piv) => {
const pds: Dataseries = {
label: `${piv ?? ''} - ${ds.label ?? ''}`,
order: ds.order,
unit: ds.unit,
precision: ds.precision,
averageLatest: ds.averageLatest,
labelColor: ds.labelColor,
valueColor: ds.valueColor,
data: ds.data?.filter((d) => d.pivot === piv),
needleValue: undefined
}
this.dataSets.set(pds.label ?? '', pds)
})
} else {
this.dataSets.set(ds.label ?? '', ds)
}
distincts.forEach((piv) => {
const prefix = piv ? `${piv} - ` : ''
const pds: Dataseries = {
label: prefix + ds.label ?? '',
order: ds.order,
unit: ds.unit,
precision: ds.precision,
averageLatest: ds.averageLatest,
labelColor: ds.labelColor,
valueColor: ds.valueColor,
data: distincts.length === 1 ? ds.data : ds.data?.filter((d) => d.pivot === piv),
needleValue: undefined
}
this.dataSets.set(pds.label ?? '', pds)
})
})

// filter latest values and calculate average
Expand Down

0 comments on commit 178bba6

Please sign in to comment.