From 82b90e20ac358c2fed2557411019f128587ebfbe Mon Sep 17 00:00:00 2001 From: Kevin Jackson <30411845+KevinJJackson@users.noreply.github.com> Date: Fri, 2 Aug 2024 10:42:09 -0400 Subject: [PATCH] enhancement/shared-plot-settings (#230) --- package.json | 2 +- .../batch-plot-configurations-bundle.js | 7 +- .../project/batch-plotting/batch-plotting.jsx | 2 +- .../chart-content/bullseye-plot.jsx | 122 +++++++++++------- .../chart-content/contour-plot.jsx | 15 ++- .../chart-content/scatter-line-plot.jsx | 4 +- .../components/batch-plot-chart-settings.jsx | 30 +++-- .../project/batch-plotting/helper.js | 13 +- .../instrument-timeseries-measurements.ts | 35 ++--- 9 files changed, 135 insertions(+), 95 deletions(-) diff --git a/package.json b/package.json index 056e8468..fd33ec96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hhd-ui", - "version": "0.16.0", + "version": "0.16.1", "private": true, "dependencies": { "@ag-grid-community/client-side-row-model": "^30.0.3", diff --git a/src/app-bundles/batch-plot-configurations-bundle.js b/src/app-bundles/batch-plot-configurations-bundle.js index 817e7c2e..b3c14806 100644 --- a/src/app-bundles/batch-plot-configurations-bundle.js +++ b/src/app-bundles/batch-plot-configurations-bundle.js @@ -71,12 +71,7 @@ export default createRestBundle({ const projectId = store.selectProjectsIdByRoute()?.projectId; const uri = `/projects/${projectId}/plot_configs/${uriMap[plotType]}${!id ? '' : `/${id}`}`; - const finalFormData = { - ...formData, - date_range: '1 year', - } - - method(uri, finalFormData, (err, _body) => { + method(uri, formData, (err, _body) => { if (err) { dispatch({ type: 'BATCH_PLOT_CONFIGURATION_SAVE_ERROR', payload: err }); } else { diff --git a/src/app-pages/project/batch-plotting/batch-plotting.jsx b/src/app-pages/project/batch-plotting/batch-plotting.jsx index 60b6964f..ee197f88 100644 --- a/src/app-pages/project/batch-plotting/batch-plotting.jsx +++ b/src/app-pages/project/batch-plotting/batch-plotting.jsx @@ -64,7 +64,7 @@ const BatchPlotting = connect( autoClose: false, onClose: () => { downloadFinalReport({ projectId, reportConfigId, jobId }); - } + }, } ); } diff --git a/src/app-pages/project/batch-plotting/chart-content/bullseye-plot.jsx b/src/app-pages/project/batch-plotting/chart-content/bullseye-plot.jsx index fb5a8f89..0285b1a7 100644 --- a/src/app-pages/project/batch-plotting/chart-content/bullseye-plot.jsx +++ b/src/app-pages/project/batch-plotting/chart-content/bullseye-plot.jsx @@ -1,8 +1,11 @@ -import React from 'react'; -import { Icon } from '@iconify/react'; +import React, { useState } from 'react'; +import { connect } from 'redux-bundler-react'; +import BatchPlotChartSettings from '../components/batch-plot-chart-settings.jsx'; import Chart from '../../../../app-components/chart/chart.jsx'; import { useGetBullseyeMeasurements } from '../../../../app-services/collections/instrument-timeseries-measurements.ts'; +import { determineDateRange } from '../helper.js'; +import { DateTime } from 'luxon'; const generateCircle = (maxValue, scalar, isLight) => { const scaled = maxValue * scalar; @@ -23,7 +26,7 @@ const generateCircle = (maxValue, scalar, isLight) => { }; }; -const generateBullseyeData = (display, measurements = []) => { +const generateBullseyeData = (_plotConfig, measurements = []) => { const x = measurements.map(el => el.x); const y = measurements.map(el => el.y); @@ -44,50 +47,60 @@ const generateBullseyeData = (display, measurements = []) => { }; }; -const BullseyePlot = ({ - plotConfig, -}) => { - const { project_id, display, id } = plotConfig || {}; +const BullseyePlot = connect( + 'doSaveBatchPlotConfiguration', + ({ + doSaveBatchPlotConfiguration, + plotConfig, + }) => { + const { auto_range, date_range, display, show_masked, show_comments, show_nonvalidated, plot_type, id, project_id } = plotConfig || {}; + + const [chartSettings, setChartSettings] = useState({ auto_range, display, show_masked, show_comments, show_nonvalidated, date_range, plot_type }); + const [dateRange, setDateRange] = useState(determineDateRange(date_range)); + const [threshold, setThreshold] = useState(3000); - const { data: measurements, isLoading } = useGetBullseyeMeasurements({ projectId: project_id, plotConfigId: id }); - const { data, totalMax } = generateBullseyeData(display, measurements); + const { data: measurements } = useGetBullseyeMeasurements({ + projectId: project_id, + plotConfigId: id, + before: DateTime.fromJSDate(dateRange[1]).toISO(), + after: DateTime.fromJSDate(dateRange[0]).toISO(), + }); + const { data, totalMax } = generateBullseyeData(plotConfig, measurements); - const config = { - repsonsive: true, - displaylogo: false, - displayModeBar: true, - scrollZoom: true, - }; + const config = { + repsonsive: true, + displaylogo: false, + displayModeBar: true, + scrollZoom: true, + }; - const layout = { - showlegend: true, - height: 800, - width: 800, - yaxis: { - showgrid: true, - title: `<-- South | North -->`, - }, - xaxis: { - showgrid: true, - title: `<-- West | East -->`, - }, - shapes: [ - generateCircle(totalMax, 0.25, true), - generateCircle(totalMax, 0.5, false), - generateCircle(totalMax, 0.75, true), - generateCircle(totalMax, 1, false), - generateCircle(totalMax, 1.25, true), - ], - }; + const layout = { + showlegend: false, + height: 800, + width: 800, + yaxis: { + showgrid: true, + title: `<-- South | North -->`, + }, + xaxis: { + showgrid: true, + title: `<-- West | East -->`, + }, + shapes: [ + generateCircle(totalMax, 0.25, true), + generateCircle(totalMax, 0.5, false), + generateCircle(totalMax, 0.75, true), + generateCircle(totalMax, 1, false), + generateCircle(totalMax, 1.25, true), + ], + }; - - return ( - <> - {isLoading ? ( -
- -
- ) : ( + const savePlotSettings = (params) => { + doSaveBatchPlotConfiguration(plot_type, id, { ...params }); + }; + + return ( + <>
- )} - - ); -}; + {chartSettings ? ( + <> +
+ + + ) : null} + + ); + }, +); export default BullseyePlot; diff --git a/src/app-pages/project/batch-plotting/chart-content/contour-plot.jsx b/src/app-pages/project/batch-plotting/chart-content/contour-plot.jsx index 36065a0d..eb2b3aaf 100644 --- a/src/app-pages/project/batch-plotting/chart-content/contour-plot.jsx +++ b/src/app-pages/project/batch-plotting/chart-content/contour-plot.jsx @@ -12,14 +12,25 @@ import Chart from '../../../../app-components/chart/chart'; import { useGetContourMeasurements, useGetMeasurementTimestamps } from '../../../../app-services/collections/instrument-timeseries-measurements.ts'; const generateContourData = (display, measurements) => { - const { time } = display || {}; + const { time, show_labels, contour_smoothing, gradient_smoothing } = display || {}; if (!time) return []; return [{ ...measurements, connectgaps: true, type: 'contour', - colorscale: 'Jet', + contours: { + line: { + smoothing: contour_smoothing ? 0.9 : 0, + }, + ...gradient_smoothing && { coloring: 'heatmap' }, + showlabels: show_labels, + labelfont: { + family: 'Raleway', + size: 12, + color: 'white', + }, + }, }]; }; diff --git a/src/app-pages/project/batch-plotting/chart-content/scatter-line-plot.jsx b/src/app-pages/project/batch-plotting/chart-content/scatter-line-plot.jsx index 112b542e..c8c6497d 100644 --- a/src/app-pages/project/batch-plotting/chart-content/scatter-line-plot.jsx +++ b/src/app-pages/project/batch-plotting/chart-content/scatter-line-plot.jsx @@ -34,7 +34,7 @@ const ScatterLinePlot = connect( const [dateRange, setDateRange] = useState([subDays(new Date(), 365), new Date()]); const [threshold, setThreshold] = useState(3000); - const [chartSettings, setChartSettings] = useState({ auto_range, display, show_masked, show_comments, show_nonvalidated, date_range }); + const [chartSettings, setChartSettings] = useState({ auto_range, display, show_masked, show_comments, show_nonvalidated, date_range, plot_type }); const chartData = useMemo(() => generateNewChartData(plotMeasurements, plotTimeseries, chartSettings, plotConfig), [plotMeasurements, activeId]); const withPrecipitation = plotTimeseries.some(ts => ts.parameter === 'precipitation'); @@ -99,7 +99,7 @@ const ScatterLinePlot = connect( if (activeId) { setThreshold(threshold); setDateRange(determineDateRange(date_range)); - setChartSettings({ auto_range, date_range, show_comments, show_nonvalidated, show_masked }); + setChartSettings({ auto_range, date_range, show_comments, show_nonvalidated, show_masked, plot_type }); } }, [activeId]); diff --git a/src/app-pages/project/batch-plotting/components/batch-plot-chart-settings.jsx b/src/app-pages/project/batch-plotting/components/batch-plot-chart-settings.jsx index 7c772b3d..0cb396df 100644 --- a/src/app-pages/project/batch-plotting/components/batch-plot-chart-settings.jsx +++ b/src/app-pages/project/batch-plotting/components/batch-plot-chart-settings.jsx @@ -16,8 +16,8 @@ import { determineDateRange } from '../helper'; const customDateFormat = (fromTime, endTime) => { const fromISO = fromTime.toISOString(); const endISO = endTime.toISOString(); - const fromDate = DateTime.fromISO(fromISO).toFormat('YYYY-MM-DD'); - const endDate = DateTime.fromISO(endISO).toFormat('YYYY-MM-DD'); + const fromDate = DateTime.fromISO(fromISO).toFormat('yyyy-MM-dd'); + const endDate = DateTime.fromISO(endISO).toFormat('yyyy-MM-dd'); return `${fromDate} ${endDate}`; }; @@ -61,14 +61,14 @@ const BatchPlotChartSettings = connect( threshold = 3000, setThreshold, savePlotSettings, - chartData, + chartData = {}, }) => { const [fromTime, endTime] = dateRange; - const { date_range, auto_range, show_comments, show_masked, show_nonvalidated } = chartSettings; + const { date_range, auto_range, show_comments, show_masked, show_nonvalidated, plot_type } = chartSettings; const [currentThreshold, setCurrentThreshold] = useState(threshold); const [csvData, setCsvData] = useState([]); - const [activeButton, setActiveButton] = useState(date_range); + const [activeButton, setActiveButton] = useState(['lifetime', '5 years', '1 year', '1 month'].includes(date_range) ? date_range : 'Custom'); const isDisplayAllActive = () => show_comments && show_masked && show_nonvalidated; @@ -77,7 +77,7 @@ const BatchPlotChartSettings = connect( }; useEffect(() => { - setDateRange(determineDateRange(activeButton)); + setDateRange(determineDateRange(activeButton === 'Custom' ? date_range : activeButton)); }, [activeButton]); return ( @@ -295,14 +295,16 @@ const BatchPlotChartSettings = connect( className='ml-2' /> -