Skip to content

Commit

Permalink
oh-chart: Only include boundary and Item state if now between start a…
Browse files Browse the repository at this point in the history
…nd end time

Signed-off-by: Florian Hotze <dev@florianhotze.com>
  • Loading branch information
florian-h05 committed Nov 17, 2024
1 parent e199066 commit 6aad363
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,19 @@ export default {
return Promise.resolve(getter([]))
}

const boundary = seriesComponents[component.component].includeBoundary?.(component) || component.config.noBoundary !== true
const now = dayjs()
const isBetweenStartAndEnd = dayjs(this.startTime).subtract(5, 'minutes').isBefore(now) && dayjs(this.endTime).add(5, 'minutes').isAfter(now)

let boundary = seriesComponents[component.component].includeBoundary?.(component) !== undefined
? seriesComponents[component.component].includeBoundary(component)
: isBetweenStartAndEnd
if (component.config.noBoundary === true) boundary = false

let itemState = seriesComponents[component.component].includeItemState?.(component) !== undefined
? seriesComponents[component.component].includeItemState(component)
: isBetweenStartAndEnd
if (component.config.noItemState === true) itemState = false

const itemPromises = neededItems.map((neededItem) => {
if (this.items[neededItem]) return Promise.resolve(this.items[neededItem])
return this.$oh.api.get(`/rest/items/${neededItem}`).then((item) => {
Expand All @@ -176,7 +188,7 @@ export default {
starttime: seriesStartTime.toISOString(),
endtime: seriesEndTime.subtract(1, 'millisecond').toISOString(),
boundary,
itemState: component.config.noItemState !== true
itemState
}

return Promise.all([itemPromises[neededItem], this.$oh.api.get(url, query)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function dimensionFromDate (d, dimension, invert) {
}
}

function includeBoundaryFor (component) {
function includeBoundaryAndItemStateFor (component) {
return (!component || !component.config || component.config.aggregationFunction === 'diff_last') ? true : undefined
}

Expand All @@ -27,13 +27,16 @@ export default {
return [series.item]
},
includeBoundary (component) {
return includeBoundaryFor(component)
return includeBoundaryAndItemStateFor(component)
},
includeItemState (component) {
return includeBoundaryAndItemStateFor(component)
},
get (component, points, startTime, endTime, chart) {
let series = chart.evaluateExpression(ComponentId.get(component), component.config)
let dimension1 = series.dimension1
let dimension2 = series.dimension2
let boundary = includeBoundaryFor(component)
let boundary = includeBoundaryAndItemStateFor(component)

const itemPoints = points.find(p => p.name === series.item).data

Expand Down

0 comments on commit 6aad363

Please sign in to comment.