Skip to content

Skin ApexCharts from the active Cacti theme's rrdtheme colors - #53

Merged
TheWitness merged 3 commits into
mainfrom
fix/apexcharts-theme-skinning
Oct 8, 2026
Merged

TheWitness merged 3 commits into
mainfrom
fix/apexcharts-theme-skinning

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

The ApexCharts views (By Method / By Table bar + box charts, and the import
upload-progress donut) were skinned with a single hard-coded light palette and a
two-case light/dark theme switch. That switch only recognized a handful of
themes and mislabeled several of the core themes it did list — e.g.
paper-plane and deepness are dark themes but were rendered with dark text
and light gridlines, so chart labels were effectively invisible.

This change drives the chart surface colors from the active Cacti theme's own
include/themes/<theme>/rrdtheme.php
, the same source core uses for RRDtool
graph theming, so the charts match whatever theme (and dark/light color mode)
the user has selected.

Details

  • New slowlog_apex_theme() helper validates the selected theme against the
    themes allowlist (cacti_validate_theme() when available), includes that
    theme's rrdtheme.php, and honors the CactiColorMode cookie's
    rrdcolors_dark / rrdcolors_light variants when a theme defines them —
    mirroring lib/rrd.php.
  • The ApexCharts light/dark mode is inferred from the luminance of the
    theme's own font color, so all 11 current core themes (and any future ones)
    are covered without a hand-maintained theme-name list.
  • font and grid colors are normalized (RRDtool alpha suffixes / shorthand
    stripped) and applied as the chart foreColor and gridline borderColor for
    the bar charts, box charts, and the donut (track + value label).
  • Replaces the old hard-coded #e0e0e0 donut track and the brittle
    switch($selected_theme) mode mapping.

No behavioral change to data, imports, or chart contents — colors only.

Testing

  • php -l clean on both modified files.

The By Method/By Table charts and the import upload donut hard-coded a single light palette and a two-theme light/dark switch that mislabeled several core themes (e.g. paper-plane and deepness are dark but rendered with light text/grid). Derive the ApexCharts foreColor, gridline color and light/dark mode from the active theme's own include/themes/<theme>/rrdtheme.php - mirroring Cacti core's rrdtheme loading, honoring the CactiColorMode cookie's dark/light variants, and inferring mode from the theme font luminance so every current and future theme is covered.
@TheWitness
TheWitness requested review from bmfmancini and xmacan and a balanced review from Copilot October 8, 2026 20:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Theme inclusion should fail fast, and the new theme-resolution branches need unit coverage.

2 open findings
What changed in this PR

Updates ApexCharts to inherit colors from the active Cacti theme.

Changes:

  • Adds theme color resolution and normalization helpers.
  • Applies theme-derived foreground and grid colors across charts.
  • Infers ApexCharts light/dark mode from font luminance.
File Description
slowlog.php Applies resolved theme colors to bar, box, and donut charts.
includes/​slowlog_functions.php Adds theme loading, variant selection, and color normalization.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/slowlog_functions.php Outdated
Comment thread includes/functions.php
Address review: use require() with a cacti_path_is_within() containment guard (defense-in-depth on top of cacti_validate_theme) so a poisoned theme name can never steer the include outside include/themes - closing a CVE-class path-traversal vector - and fail fast instead of silently using default colors. Add tests/Unit/ApexThemeTest.php covering 3/6/8-digit and invalid color normalization, luminance-based light/dark mode, CactiColorMode dark/light variant selection, and the missing-file fallback; stub get_selected_theme() in the unit bootstrap. Fixes the 100% changed-line coverage gate.
Match the Cacti plugin naming convention. Updates the require in slowlog.php/import_log.php, the Pest coverage <source> list in phpunit.xml, every TestCase::loadPluginSource()/source-scan reference across the test suite, and the .github/copilot-instructions.md tree. Adds an includes/slowlog_functions.php tombstone to manifest.json so slowlog_prune_files() removes the old file from existing installs on upgrade (subdirectory tombstones are supported - the prune joins the relative path under the plugin dir and realpath-confines it).
@TheWitness
TheWitness merged commit 976e552 into main Oct 8, 2026
5 checks passed
@TheWitness
TheWitness deleted the fix/apexcharts-theme-skinning branch October 8, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants