Field selectors are now dropdowns populated from the panel's actual
data frames. Each option shows 'fieldName (refId)' so users can
distinguish fields from different queries (A, B, C, etc.).
The selected value uses a 'refId:fieldName' composite key so the
panel can unambiguously resolve the correct field even when multiple
queries return fields with the same name.
Data extraction now searches across ALL series (not just series[0]),
fixing the core bug where selecting a field from query B/C had no
effect because the code only looked at the first data frame.
Field resolution priority:
1. Exact 'refId:fieldName' match (from dropdown selection)
2. Fuzzy match by field name, display name, frame name, or refId
3. For charge field only: fallback to first numeric field ('Auto')
Dropdowns also support allowCustomValue for manual entry and
isClearable to reset.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Field pickers:
- Replaced addFieldNamePicker with addTextInput for all field
selectors (charge, load, state, time remaining). The FieldNamePicker
component was silently failing to render in some Grafana versions.
Text inputs are universally supported and let users type the exact
field name from their data source.
Time remaining:
- New 'Enable time remaining' toggle + field name in Field Mapping
- Reads the last value from the configured field (expects minutes)
- Displays as a styled card with clock icon and human-readable
duration (e.g. '2h 15m', '45 min', '< 1 min')
Auto-revert horizontal orientation:
- When orientation is set to horizontal but the panel width is < 300px,
automatically switches to vertical so the battery + side content
still fit. The preference is stored, so it reverts back when the
panel is resized larger.
Icon:
- Replaced generic Grafana scaffold logo with a battery SVG icon
that shows in the visualisation picker and panel header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When no state field is configured, the panel now uses a least-squares
slope over the most recent ≤ 50 data points to determine whether the
battery is charging, on battery, or stable — instead of relying on the
overall first-to-last rate which could be misleading over long ranges.
Priority order for state resolution:
1. Explicit state field (if enabled and configured)
2. Inferred trend from last ≤ 50 points (always computed)
The slope threshold (0.01) avoids flicker from sensor noise.
Status badge now shows 'On Battery' instead of 'Discharging'.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
- Responsive layout adapts to any panel size (mobile to widescreen)
- Auto-switches between column/row layout based on dimensions
- Gracefully degrades in tiny panels (hides stats, keeps battery)
- Font sizes scale dynamically to available space
- New configurable options via Grafana panel editor:
- Colours category: low/mid/high battery colours
- Thresholds category: configurable low/high % boundaries (was hardcoded 30/70)
- Appearance category: gradient fill, orientation (vertical/horizontal),
charging animation, border width
- Display category: individual show/hide toggles for percentage, rate,
low/high stats, charging status
- Data category: decimal places, regression toggle
- Fixed bugs:
- Gradient ID now unique per panel instance (fixes multi-panel dashboards)
- Battery fill uses clipPath so it respects rounded corners
- Proper 'No data' empty state
- Horizontal battery orientation for wide/short panels
- Pulse animation when charging (configurable)
- Status badge with themed colours (charging/discharging/stable)
- Moved options interface to shared types.ts
- Updated stale e2e tests to match current component
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>