From 56adf089861b308bb9bb354ad24ebdd3a807db40 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 20 Sep 2024 16:50:56 +0200 Subject: [PATCH] Fix plot issues --- .../js/query/components/job/JobDownload.js | 4 +++- .../assets/js/query/components/job/JobPlot.js | 12 +++++----- .../js/query/components/job/JobResults.js | 4 +++- .../components/job/plots/ColorScatter.js | 10 ++++----- .../components/job/plots/ColorScatterForm.js | 7 +++--- .../components/job/plots/ColorScatterPlot.js | 12 +++++----- .../query/components/job/plots/Histogram.js | 8 +++---- .../components/job/plots/HistogramForm.js | 3 +-- .../components/job/plots/HistogramPlot.js | 8 +++---- .../js/query/components/job/plots/Scatter.js | 12 +++++----- .../query/components/job/plots/ScatterForm.js | 4 ++-- .../query/components/job/plots/ScatterPlot.js | 12 +++++----- .../query/assets/js/query/hooks/queries.js | 22 ++++++++++--------- 13 files changed, 62 insertions(+), 56 deletions(-) diff --git a/daiquiri/query/assets/js/query/components/job/JobDownload.js b/daiquiri/query/assets/js/query/components/job/JobDownload.js index ed835525..037754f3 100644 --- a/daiquiri/query/assets/js/query/components/job/JobDownload.js +++ b/daiquiri/query/assets/js/query/components/job/JobDownload.js @@ -53,7 +53,7 @@ const JobDownload = ({ job }) => { } } - return ( + return job.phase == 'COMPLETED' ? (

{gettext('For further processing of the data, you can download the results table' + @@ -90,6 +90,8 @@ const JobDownload = ({ job }) => { ) }

+ ) : ( +

The query job did not complete successfully.

) } diff --git a/daiquiri/query/assets/js/query/components/job/JobPlot.js b/daiquiri/query/assets/js/query/components/job/JobPlot.js index 6c27a83d..f5f0095b 100644 --- a/daiquiri/query/assets/js/query/components/job/JobPlot.js +++ b/daiquiri/query/assets/js/query/components/job/JobPlot.js @@ -12,7 +12,7 @@ import JobPlotType from './JobPlotType' const JobPlot = ({ job }) => { - const [type, setType] = useState('histogram') + const [type, setType] = useState('scatter') const [columns, setColumns] = useState([]) useEffect(() => setColumns(job.columns.filter((column) => ( @@ -20,19 +20,21 @@ const JobPlot = ({ job }) => { !excludedUcds.some((ucd) => (!isNil(column.ucd) && column.ucd.split(';').includes(ucd))) ))), [job]) - return ( + return job.phase == 'COMPLETED' ? (
{ - (type == 'scatter') && + (type == 'scatter') && } { - (type == 'colorScatter') && + (type == 'colorScatter') && } { - (type == 'histogram') && + (type == 'histogram') && }
+ ) : ( +

The query job did not complete successfully.

) } diff --git a/daiquiri/query/assets/js/query/components/job/JobResults.js b/daiquiri/query/assets/js/query/components/job/JobResults.js index c426954d..c0afffb5 100644 --- a/daiquiri/query/assets/js/query/components/job/JobResults.js +++ b/daiquiri/query/assets/js/query/components/job/JobResults.js @@ -14,13 +14,15 @@ const JobResults = ({ job }) => { const { data: columns } = useJobColumnsQuery(job.id, params) const { data: rows } = useJobRowsQuery(job.id, params) - return ( + return job.phase == 'COMPLETED' ? ( + ) : ( +

The query job did not complete successfully.

) } diff --git a/daiquiri/query/assets/js/query/components/job/plots/ColorScatter.js b/daiquiri/query/assets/js/query/components/job/plots/ColorScatter.js index 745d9b4d..fc0ef2e3 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/ColorScatter.js +++ b/daiquiri/query/assets/js/query/components/job/plots/ColorScatter.js @@ -8,7 +8,7 @@ import { useJobPlotQuery } from '../../../hooks/queries' import ColorScatterForm from './ColorScatterForm' import ColorScatterPlot from './ColorScatterPlot' -const ColorScatter = ({ jobId, columns }) => { +const ColorScatter = ({ job, columns }) => { const [values, setValues] = useState({ x: { @@ -36,9 +36,9 @@ const ColorScatter = ({ jobId, columns }) => { } }), [columns]) - const { data: x } = useJobPlotQuery(jobId, values.x.column) - const { data: y } = useJobPlotQuery(jobId, values.y.column) - const { data: z } = useJobPlotQuery(jobId, values.z.column) + const { data: x } = useJobPlotQuery(job, values.x.column) + const { data: y } = useJobPlotQuery(job, values.y.column) + const { data: z } = useJobPlotQuery(job, values.z.column) return (
@@ -49,7 +49,7 @@ const ColorScatter = ({ jobId, columns }) => { } ColorScatter.propTypes = { - jobId: PropTypes.string.isRequired, + job: PropTypes.object.isRequired, columns: PropTypes.array.isRequired } diff --git a/daiquiri/query/assets/js/query/components/job/plots/ColorScatterForm.js b/daiquiri/query/assets/js/query/components/job/plots/ColorScatterForm.js index 3ac95615..ac34f85c 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/ColorScatterForm.js +++ b/daiquiri/query/assets/js/query/components/job/plots/ColorScatterForm.js @@ -17,7 +17,7 @@ const ColorScatterForm = ({ columns, values, setValues }) => { { setValues({...values, y: {...values.y, column: value.target.value}}) }}> - + { columns.map((column, columnIndex) => ) } @@ -51,7 +51,7 @@ const ColorScatterForm = ({ columns, values, setValues }) => { { setValues({...values, z: {...values.z, cmap: value.target.value}}) }}> - { cmaps.map((cmap, cmapIndex) => ) } diff --git a/daiquiri/query/assets/js/query/components/job/plots/ColorScatterPlot.js b/daiquiri/query/assets/js/query/components/job/plots/ColorScatterPlot.js index 26efe199..106bee53 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/ColorScatterPlot.js +++ b/daiquiri/query/assets/js/query/components/job/plots/ColorScatterPlot.js @@ -16,13 +16,13 @@ const ColorScatterPlot = ({ columns, values, x, y, z }) => { { ColorScatterPlot.propTypes = { columns: PropTypes.array.isRequired, values: PropTypes.object.isRequired, - x: PropTypes.object, - y: PropTypes.object, - z: PropTypes.object + x: PropTypes.array, + y: PropTypes.array, + z: PropTypes.array } export default ColorScatterPlot diff --git a/daiquiri/query/assets/js/query/components/job/plots/Histogram.js b/daiquiri/query/assets/js/query/components/job/plots/Histogram.js index 991226bc..c361f541 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/Histogram.js +++ b/daiquiri/query/assets/js/query/components/job/plots/Histogram.js @@ -8,7 +8,7 @@ import { useJobPlotQuery } from '../../../hooks/queries' import HistogramForm from './HistogramForm' import HistogramPlot from './HistogramPlot' -const Histogram = ({ jobId, columns }) => { +const Histogram = ({ job, columns }) => { const [values, setValues] = useState({ x: { @@ -29,8 +29,8 @@ const Histogram = ({ jobId, columns }) => { } }), [columns]) - const { data: x } = useJobPlotQuery(jobId, values.x.column) - const { data: s } = useJobPlotQuery(jobId, values.s.column) + const { data: x } = useJobPlotQuery(job, values.x.column) + const { data: s } = useJobPlotQuery(job, values.s.column) return (
@@ -41,7 +41,7 @@ const Histogram = ({ jobId, columns }) => { } Histogram.propTypes = { - jobId: PropTypes.string.isRequired, + job: PropTypes.object.isRequired, columns: PropTypes.array.isRequired } diff --git a/daiquiri/query/assets/js/query/components/job/plots/HistogramForm.js b/daiquiri/query/assets/js/query/components/job/plots/HistogramForm.js index a96806b1..f55661ad 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/HistogramForm.js +++ b/daiquiri/query/assets/js/query/components/job/plots/HistogramForm.js @@ -52,7 +52,7 @@ const HistogramForm = ({ columns, values, setValues }) => { { setValues({...values, s: {...values.s, operation: event.target.value}}) }}> - { operations.map((operation, operationIndex) => ) } diff --git a/daiquiri/query/assets/js/query/components/job/plots/HistogramPlot.js b/daiquiri/query/assets/js/query/components/job/plots/HistogramPlot.js index 7bdff779..84c8e7e7 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/HistogramPlot.js +++ b/daiquiri/query/assets/js/query/components/job/plots/HistogramPlot.js @@ -12,7 +12,7 @@ const HistogramPlot = ({ columns, values, x, s }) => { } else { const data = [ { - x: x.results, + x: x, type: 'histogram', nbinsx: values.bins } @@ -22,7 +22,7 @@ const HistogramPlot = ({ columns, values, x, s }) => { const operation = operations.find(operation => operation.name == values.s.operation) || operations[0] data.push({ - x: x.results.filter((value, index) => operation.operation(s.results[index], values.s.value)), + x: x.filter((value, index) => operation.operation(s[index], values.s.value)), type: 'histogram', nbinsx: values.bins }) @@ -76,8 +76,8 @@ const HistogramPlot = ({ columns, values, x, s }) => { HistogramPlot.propTypes = { columns: PropTypes.array.isRequired, values: PropTypes.object.isRequired, - x: PropTypes.object, - s: PropTypes.object, + x: PropTypes.array, + s: PropTypes.array, } export default HistogramPlot diff --git a/daiquiri/query/assets/js/query/components/job/plots/Scatter.js b/daiquiri/query/assets/js/query/components/job/plots/Scatter.js index c189887d..8192ba6d 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/Scatter.js +++ b/daiquiri/query/assets/js/query/components/job/plots/Scatter.js @@ -8,7 +8,7 @@ import { useJobPlotQuery } from '../../../hooks/queries' import ScatterForm from './ScatterForm' import ScatterPlot from './ScatterPlot' -const Scatter = ({ jobId, columns }) => { +const Scatter = ({ job, columns }) => { const [values, setValues] = useState({ x: { @@ -41,10 +41,10 @@ const Scatter = ({ jobId, columns }) => { } }), [columns]) - const { data: x } = useJobPlotQuery(jobId, values.x.column) - const { data: y1 } = useJobPlotQuery(jobId, values.y1.column) - const { data: y2 } = useJobPlotQuery(jobId, values.y2.column) - const { data: y3 } = useJobPlotQuery(jobId, values.y3.column) + const { data: x } = useJobPlotQuery(job, values.x.column) + const { data: y1 } = useJobPlotQuery(job, values.y1.column) + const { data: y2 } = useJobPlotQuery(job, values.y2.column) + const { data: y3 } = useJobPlotQuery(job, values.y3.column) return (
@@ -55,7 +55,7 @@ const Scatter = ({ jobId, columns }) => { } Scatter.propTypes = { - jobId: PropTypes.string.isRequired, + job: PropTypes.object.isRequired, columns: PropTypes.array.isRequired } diff --git a/daiquiri/query/assets/js/query/components/job/plots/ScatterForm.js b/daiquiri/query/assets/js/query/components/job/plots/ScatterForm.js index 86799909..67618155 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/ScatterForm.js +++ b/daiquiri/query/assets/js/query/components/job/plots/ScatterForm.js @@ -31,7 +31,7 @@ const ScatterForm = ({ columns, values, setValues }) => { { setValues({...values, [y]: {...values[y], column: value.target.value}}) }}> - + { columns.map((column, columnIndex) => ) } diff --git a/daiquiri/query/assets/js/query/components/job/plots/ScatterPlot.js b/daiquiri/query/assets/js/query/components/job/plots/ScatterPlot.js index b3b86898..599be8d6 100644 --- a/daiquiri/query/assets/js/query/components/job/plots/ScatterPlot.js +++ b/daiquiri/query/assets/js/query/components/job/plots/ScatterPlot.js @@ -14,8 +14,8 @@ const ScatterPlot = ({ columns, values, x, y1, y2, y3 }) => { return data } else { return [...data, { - x: x.results, - y: y.results, + x: x, + y: y, type: 'scattergl', mode: 'markers', marker: { @@ -82,10 +82,10 @@ const ScatterPlot = ({ columns, values, x, y1, y2, y3 }) => { ScatterPlot.propTypes = { columns: PropTypes.array.isRequired, values: PropTypes.object.isRequired, - x: PropTypes.object, - y1: PropTypes.object, - y2: PropTypes.object, - y3: PropTypes.object + x: PropTypes.array, + y1: PropTypes.array, + y2: PropTypes.array, + y3: PropTypes.array } export default ScatterPlot diff --git a/daiquiri/query/assets/js/query/hooks/queries.js b/daiquiri/query/assets/js/query/hooks/queries.js index 478a6124..e7e6f1e4 100644 --- a/daiquiri/query/assets/js/query/hooks/queries.js +++ b/daiquiri/query/assets/js/query/hooks/queries.js @@ -114,16 +114,18 @@ export const useJobRowsQuery = (jobId, params) => { }) } -export const useJobPlotQuery = (jobId, column) => { - return useQuery({ - queryKey: ['jobPlot', jobId, column], - queryFn: () => QueryApi.fetchJobRows(jobId, {column: column, page_size: 10000}).then((response) => { - response.min = Math.min.apply(null, response.results) - response.max = Math.max.apply(null, response.results) - return response - }), - placeholderData: keepPreviousData, - enabled: !isEmpty(column) +export const useJobPlotQuery = (job, column) => { + return useQuery({ + queryKey: ['jobPlot', job.id, column], + queryFn: () => { + if (job.columns.map(column => column.name).includes(column)) { + return QueryApi.fetchJobRows(job.id, {column: column, page_size: 10000}) + .then((response) => response.results) + } else { + return null + } + }, + placeholderData: keepPreviousData }) }