From 4d06ef68b72cd99777b18f6c7b7e0aa32cf32c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Wiedemann?= Date: Thu, 18 Feb 2021 15:30:29 +0000 Subject: [PATCH] fix: extremas was not working with `invert: true` Fixes #96 --- .devcontainer/ui-lovelace.yaml | 13 ++++++++++--- src/apexcharts-card.ts | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.devcontainer/ui-lovelace.yaml b/.devcontainer/ui-lovelace.yaml index 5b3ac07..89c64e2 100644 --- a/.devcontainer/ui-lovelace.yaml +++ b/.devcontainer/ui-lovelace.yaml @@ -54,10 +54,17 @@ views: show: extremas: true - entity: sensor.random_0_1000 - name: Sensor 2 - type: area - offset: -1d + name: Sensor 1 invert: true + type: area + curve: straight + show: + extremas: true + # - entity: sensor.random_0_1000 + # name: Sensor 2 + # type: area + # offset: -1d + # invert: true graph_span: 15min cache: true layout: minimal diff --git a/src/apexcharts-card.ts b/src/apexcharts-card.ts index 8bca46b..8d85a0e 100644 --- a/src/apexcharts-card.ts +++ b/src/apexcharts-card.ts @@ -630,8 +630,8 @@ class ChartsCard extends LitElement { const txtColor = computeTextColor(bgColor); if (!min[0] || !max[0]) return []; return [ - this._getPointAnnotationStyle(min, bgColor, txtColor, serie, index), - this._getPointAnnotationStyle(max, bgColor, txtColor, serie, index), + this._getPointAnnotationStyle(min, bgColor, txtColor, serie, index, serie.invert), + this._getPointAnnotationStyle(max, bgColor, txtColor, serie, index, serie.invert), ]; } else { return []; @@ -646,10 +646,11 @@ class ChartsCard extends LitElement { txtColor: string, serie: ChartCardSeriesConfig, index: number, + invert = false, ) { return { x: value[0], - y: value[1], + y: invert && value[1] ? -value[1] : value[1], seriesIndex: index, marker: { strokeColor: bgColor,