From c0fa353a17fc91d800c044e41da5d5d42233c1cf Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Fri, 12 Jun 2026 12:38:38 +0200 Subject: [PATCH] zoom in and zoom out of price chart --- .../CurrentPriceChart.tsx | 44 ++++++++++++++++--- typescript/frontend-marios2/src/lang/de.json | 1 + typescript/frontend-marios2/src/lang/en.json | 1 + typescript/frontend-marios2/src/lang/fr.json | 1 + typescript/frontend-marios2/src/lang/it.json | 1 + 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/CurrentPriceChart.tsx b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/CurrentPriceChart.tsx index bebdb4b24..6c0be17c9 100644 --- a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/CurrentPriceChart.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/CurrentPriceChart.tsx @@ -1,9 +1,10 @@ import React, { useEffect, useState } from 'react'; -import { Box, Typography } from '@mui/material'; +import { Box, Button, Typography } from '@mui/material'; import CircularProgress from '@mui/material/CircularProgress'; +import RestartAltIcon from '@mui/icons-material/RestartAlt'; import { FormattedMessage, useIntl } from 'react-intl'; import ReactApexChart from 'react-apexcharts'; -import { ApexOptions } from 'apexcharts'; +import ApexCharts, { ApexOptions } from 'apexcharts'; import { I_S3Credentials } from 'src/interfaces/S3Types'; import { UnixTime, TimeSpan } from 'src/dataCache/time'; import { @@ -17,6 +18,7 @@ interface CurrentPriceChartProps { } const HISTORY_DAYS = 7; +const CHART_ID = 'current-price-history'; function CurrentPriceChart(props: CurrentPriceChartProps) { const intl = useIntl(); @@ -49,6 +51,14 @@ function CurrentPriceChart(props: CurrentPriceChartProps) { }; }, [props.id]); + // Snap the x-axis back to the full history window after the user drag-zooms. + const handleResetZoom = () => { + if (!series || series.data.length === 0) return; + const minX = series.data[0][0]; + const maxX = series.data[series.data.length - 1][0]; + ApexCharts.exec(CHART_ID, 'zoomX', minX, maxX); + }; + const title = (