Add field selectors for charge, load, and state metrics

Field Mapping options (new category at top of editor):
- Charge field: pick which numeric field drives the battery level
  (falls back to first number field if unset)
- Enable load metric: toggle + field picker for a load/power draw
  percentage, displayed as a themed semi-circular gauge arc beside
  the battery (green < 50%, amber 50-80%, red > 80%)
- Enable state field: toggle + field picker + user-defined values
  for charging/discharging so the panel uses an explicit data field
  rather than computing state from the rate of change

Visual integration:
- Load gauge renders in a card with the battery, scales responsively,
  and collapses to a compact text line in small panels
- State field drives the status badge, gradient direction, and
  charging animation (overrides computed rate when enabled)
- All new options use showIf for conditional visibility in the editor

Also fixed deprecation warnings by replacing .toArray() with
Array.from() for Grafana 12+ compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Andy Dixon
2026-04-24 13:15:21 +01:00
co-authored by Copilot
parent 942a390248
commit da80da71d1
3 changed files with 322 additions and 62 deletions
+9
View File
@@ -1,6 +1,15 @@
export type BatteryOrientation = 'vertical' | 'horizontal';
export interface ChargeVizOptions {
// Field selectors
chargeField: string;
enableLoad: boolean;
loadField: string;
enableStateField: boolean;
stateField: string;
stateChargingValue: string;
stateDischargingValue: string;
// Colours
lowColour: string;
midColour: string;