From 941f903a9cd06fe3be9a2d4aa6231e8275f5d030 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski <75446+jpawlowski@users.noreply.github.com> Date: Sun, 21 Dec 2025 17:39:12 +0000 Subject: [PATCH] fix(apexcharts): synchronize y-axis tick intervals for consistent grid alignment Problem: When using dual y-axes (price + hidden highlight for best-price overlay), ApexCharts calculates tick intervals independently for each axis. This caused misaligned horizontal grid lines - the grid follows the first y-axis ticks, but if the hidden highlight axis had different tick calculations, visual inconsistencies appeared (especially visible without best-price highlight). Solution: - Set tickAmount: 4 on BOTH y-axes to force identical tick intervals - Add forceNiceScale: true to ensure rounded tick values despite fixed min/max - Add showAlways: true to price axis in template modes to prevent axis disappearing when toggling series via legend Also add tooltip.shared: true to combine tooltips from all series at the same x-value into a single tooltip, reducing visual clutter at data points. Impact: Grid lines now align consistently regardless of which series are visible. Y-axis remains stable when toggling series in legend. --- .../services/get_apexcharts_yaml.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/custom_components/tibber_prices/services/get_apexcharts_yaml.py b/custom_components/tibber_prices/services/get_apexcharts_yaml.py index 864ae58..7283a05 100644 --- a/custom_components/tibber_prices/services/get_apexcharts_yaml.py +++ b/custom_components/tibber_prices/services/get_apexcharts_yaml.py @@ -546,6 +546,7 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: }, "tooltip": { "enabled": True, + "shared": True, # Combine tooltips from all series at same x-value "enabledOnSeries": [1, 2, 3, 4, 5] if highlight_best_price else [0, 1, 2, 3, 4], "marker": { "show": False, @@ -566,6 +567,10 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "max": 1, "show": False, # Hide this axis (only for highlight overlay) "opposite": True, + "apex_config": { + "forceNiceScale": True, + "tickAmount": 4, + }, }, ], "now": ( @@ -694,6 +699,8 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "title": {"text": price_unit}, "decimalsInFloat": 0 if use_subunit else 1, "forceNiceScale": True, + "showAlways": True, + "tickAmount": 4, }, } @@ -712,6 +719,8 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "title": {"text": price_unit}, "decimalsInFloat": 0 if use_subunit else 1, "forceNiceScale": True, + "showAlways": True, + "tickAmount": 4, }, } @@ -742,6 +751,10 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "max": 1, "show": False, "opposite": True, + "apex_config": { + "forceNiceScale": True, + "tickAmount": 4, + }, }, ], "apex_config": { @@ -851,6 +864,8 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "title": {"text": price_unit}, "decimalsInFloat": 0 if use_subunit else 1, "forceNiceScale": True, + "showAlways": True, + "tickAmount": 4, }, } @@ -869,6 +884,8 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "title": {"text": price_unit}, "decimalsInFloat": 0 if use_subunit else 1, "forceNiceScale": True, + "showAlways": True, + "tickAmount": 4, }, } @@ -901,6 +918,10 @@ async def handle_apexcharts_yaml(call: ServiceCall) -> dict[str, Any]: # noqa: "max": 1, "show": False, "opposite": True, + "apex_config": { + "forceNiceScale": True, + "tickAmount": 4, + }, }, ], "apex_config": {