From 46234d6be178efdfa7a8906286c678e430c2c824 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 19 Jul 2021 17:17:30 +0500 Subject: [PATCH] =?UTF-8?q?=D0=93=D1=80=D0=B0=D1=84=D0=B8=D0=BA=20=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=B8=D1=82=D0=B8=D0=BA=D0=B8=20=D0=93=D0=BB?= =?UTF-8?q?=D1=83=D0=B1=D0=B8=D0=BD=D0=B0-=D0=94=D0=B5=D0=BD=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AnalyticDepthToDayColumn.jsx | 0 src/components/charts/ChartDepthToDay.jsx | 54 +++++++++++++++++++ src/components/charts/ChartDepthToDayBase.tsx | 0 3 files changed, 54 insertions(+) create mode 100644 src/components/AnalyticDepthToDayColumn.jsx create mode 100644 src/components/charts/ChartDepthToDay.jsx create mode 100644 src/components/charts/ChartDepthToDayBase.tsx diff --git a/src/components/AnalyticDepthToDayColumn.jsx b/src/components/AnalyticDepthToDayColumn.jsx new file mode 100644 index 0000000..e69de29 diff --git a/src/components/charts/ChartDepthToDay.jsx b/src/components/charts/ChartDepthToDay.jsx new file mode 100644 index 0000000..efdff61 --- /dev/null +++ b/src/components/charts/ChartDepthToDay.jsx @@ -0,0 +1,54 @@ +import { useEffect, useState} from 'react' +import {GetRandomColor} from "./ChartTimeArchive" +import {ChartDepthToDayBase} from "./ChartDepthToDayBase"; +import {ChartTimeBase} from "./ChartTimeBase"; + +const CreateDataset = (lineConfig) => { + let color = lineConfig.borderColor + ?? lineConfig.backgroundColor + ?? lineConfig.color + ?? GetRandomColor() + + let dataset = { + label: lineConfig.label, + data: [], + backgroundColor: lineConfig.backgroundColor ?? color, + borderColor: lineConfig.borderColor ?? color, + borderWidth: lineConfig.borderWidth ?? 1, + borderDash: lineConfig.dash ?? [], + } + return dataset +} + +export const ChartAnalyticDepthToDay = ({lines, data, yDisplay, rangeDate, chartRatio}) => { + const [analyticDataParams, setAnalyticDataParams] = useState({data:{datasets:[]}}) + let startOfDay = new Date().setHours(0,0,0,0) + + useEffect(() => { + if ((!lines) + || (!data)) + return + + let newDatasets = lines.map(lineCfg => { + let dataset = CreateDataset(lineCfg) + dataset.data = data.map(dataItem => { + return { + x: new Date(dataItem[lineCfg.xAccessorName??'date']), + y: dataItem[lineCfg.yAccessorName], + } + }) + return dataset + }) + + let newParams = { + xStart: startOfDay, + displayLabels: yDisplay??false, + data: { + datasets: newDatasets + } + } + setAnalyticDataParams(newParams) + }, [data, lines, yDisplay, rangeDate, chartRatio]) + + return () +} \ No newline at end of file diff --git a/src/components/charts/ChartDepthToDayBase.tsx b/src/components/charts/ChartDepthToDayBase.tsx new file mode 100644 index 0000000..e69de29