diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyBarPlot.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyBarPlot.tsx index 9706ac09567..1c5175a0475 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyBarPlot.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyBarPlot.tsx @@ -2,26 +2,12 @@ import * as Plotly from 'plotly.js'; import React, {useEffect, useMemo, useRef} from 'react'; import {PLOT_GRID_COLOR} from '../../ecpConstants'; -import {RadarPlotData} from './PlotlyRadarPlot'; export const PlotlyBarPlot: React.FC<{ height: number; - data: RadarPlotData; + plotlyData: Plotly.Data; }> = props => { const divRef = useRef(null); - const plotlyData: Plotly.Data[] = useMemo(() => { - return Object.keys(props.data).map((key, i) => { - const {metrics, name, color} = props.data[key]; - return { - type: 'bar', - y: Object.values(metrics), - x: Object.keys(metrics), - name, - marker: {color}, - }; - }); - }, [props.data]); - const plotlyLayout: Partial = useMemo(() => { return { height: props.height - 40, @@ -30,7 +16,7 @@ export const PlotlyBarPlot: React.FC<{ l: 0, r: 0, b: 20, - t: 0, + t: 20, pad: 0, }, xaxis: { @@ -44,8 +30,17 @@ export const PlotlyBarPlot: React.FC<{ gridcolor: PLOT_GRID_COLOR, linecolor: PLOT_GRID_COLOR, }, + title: { + text: props.plotlyData.name ?? '', + font: {size: 14}, + xref: 'paper', + x: 0.5, + y: 1, // Position at the top + yanchor: 'top', + }, }; - }, [props.height]); + }, [props.height, props.plotlyData]); + const plotlyConfig = useMemo(() => { return { displayModeBar: false, @@ -57,11 +52,11 @@ export const PlotlyBarPlot: React.FC<{ useEffect(() => { Plotly.newPlot( divRef.current as any, - plotlyData, + [props.plotlyData], plotlyLayout, plotlyConfig ); - }, [plotlyConfig, plotlyData, plotlyLayout]); + }, [plotlyConfig, props.plotlyData, plotlyLayout]); return
; }; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyRadarPlot.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyRadarPlot.tsx index d459d1354f1..4d0aa39b29f 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyRadarPlot.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/PlotlyRadarPlot.tsx @@ -31,13 +31,13 @@ export const PlotlyRadarPlot: React.FC<{ }, [props.data]); const plotlyLayout: Partial = useMemo(() => { return { - height: props.height, + height: props.height - 40, showlegend: false, margin: { - l: 60, + l: 0, r: 0, - b: 30, - t: 30, + b: 20, + t: 20, pad: 0, }, polar: { diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/SummaryPlotsSection.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/SummaryPlotsSection.tsx index 5bfaa8fcb04..2d04a9a6443 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/SummaryPlotsSection.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CompareEvaluationsPage/sections/SummaryPlotsSection/SummaryPlotsSection.tsx @@ -52,9 +52,9 @@ export const SummaryPlots: React.FC<{ } }, [selectedMetrics, setSelectedMetrics, allMetricNames]); - // filter down the plotlyRadarData to only include the selected metrics, after - // computation, to allow quick addition/removal of metrics - const filteredPlotlyRadarData = useMemo(() => { + // filter down the data to only include the selected metrics, after + // computation, to allow quick addition/removal of metrics. + const filteredData = useMemo(() => { const filteredData: RadarPlotData = {}; for (const [callId, metricBin] of Object.entries(radarData)) { const metrics: {[metric: string]: number} = {}; @@ -74,71 +74,144 @@ export const SummaryPlots: React.FC<{ return filteredData; }, [radarData, selectedMetrics]); + const plots = useMemo(() => { + const plots = [ + , + ]; + + // transform the data to be a list of metrics for each callId + const metrics: {[metric: string]: {callIds: string[], values: number[], name: string, colors: string[]}} = {}; + for (const [callId, metricBin] of Object.entries(filteredData)) { + for (const [metric, value] of Object.entries(metricBin.metrics)) { + metrics[metric] = { + callIds: [...(metrics[metric]?.callIds ?? []), callId], + values: [...(metrics[metric]?.values ?? []), value], + name: metric, + colors: [...(metrics[metric]?.colors ?? []), metricBin.color], + }; + } + } + + for (const metric of Object.keys(metrics)) { + const metricBin = metrics[metric]; + const plotlyData: Plotly.Data = { + type: 'bar', + y: metricBin.values, + // x: metricBin.callIds, + xaxis: '', + name: metric, + marker: {color: metricBin.colors}, + }; + plots.push( + + ); + } + + return plots; + }, [filteredData]); + + const containerRef = useRef(null); + const [containerWidth, setContainerWidth] = useState(0); + + useEffect(() => { + const updateWidth = () => { + if (containerRef.current) { + setContainerWidth(containerRef.current.offsetWidth); + } + }; + + updateWidth(); // Initial width + + window.addEventListener('resize', updateWidth); + return () => window.removeEventListener('resize', updateWidth); + }, []); + + console.log('containerWidth', containerWidth); + + const plotsPerPage = useMemo(() => { + return Math.max(1, Math.floor(containerWidth / (PLOT_HEIGHT + 20))); // 20px for margin + }, [containerWidth]); + + const [currentPage, setCurrentPage] = useState(0); + + const totalPages = Math.ceil(plots.length / plotsPerPage); + + const handleNextPage = () => { + setCurrentPage((prevPage) => Math.min(prevPage + 1, totalPages - 1)); + }; + + const handlePrevPage = () => { + setCurrentPage((prevPage) => Math.max(prevPage - 1, 0)); + }; + + const startIndex = currentPage * plotsPerPage; + const endIndex = Math.min(startIndex + plotsPerPage, plots.length); + const currentPlots = plots.slice(startIndex, endIndex); + return ( - - - - Summary Metrics - - -
-
Configure displayed metrics
- -
-
-
- - - - - + Summary Metrics + + +
+
Configure displayed metrics
+ +
+
+
+
+ - - - - + {currentPlots.map((plot, index) => ( + + {plot} + + ))} + +
+ + + +