Skip to content

Commit

Permalink
datanow comes in real time
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcowD committed Oct 13, 2024
1 parent 2270b98 commit 49379c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
28 changes: 20 additions & 8 deletions ell-studio/src/components/graphing/ErrorBarPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const drawErrorBar = (ctx, x, y, errorLow, errorHigh, color, width) => {

const ErrorBarPlugin = {
id: 'errorBar',
beforeInit(chart) {
chart.errorBarData = {};
},
afterDatasetsDraw(chart, args, options) {
const { ctx } = chart;

Expand All @@ -59,17 +62,26 @@ const ErrorBarPlugin = {

let errorLow, errorHigh;
if (typeof dataset.errorBars[index] === 'object') {
// Calculate error bar lengths in pixels
errorLow = Math.abs(chart.scales.y.getPixelForValue(datapoint) -
chart.scales.y.getPixelForValue(dataset.errorBars[index].low));
errorHigh = Math.abs(chart.scales.y.getPixelForValue(datapoint) -
chart.scales.y.getPixelForValue(dataset.errorBars[index].high));
errorLow = dataset.errorBars[index].low;
errorHigh = dataset.errorBars[index].high;
} else {
errorLow = errorHigh = Math.abs(chart.scales.y.getPixelForValue(datapoint) -
chart.scales.y.getPixelForValue(datapoint + dataset.errorBars[index]));
errorLow = datapoint - dataset.errorBars[index];
errorHigh = datapoint + dataset.errorBars[index];
}

drawErrorBar(ctx, x, y, errorLow, errorHigh, dataset.borderColor, dataset.borderWidth || 1);
// Store error bar data for tooltip access
if (!chart.errorBarData[datasetIndex]) {
chart.errorBarData[datasetIndex] = [];
}
chart.errorBarData[datasetIndex][index] = { low: errorLow, high: errorHigh };

// Convert to pixel values for drawing
const errorLowPx = Math.abs(chart.scales.y.getPixelForValue(datapoint) -
chart.scales.y.getPixelForValue(errorLow));
const errorHighPx = Math.abs(chart.scales.y.getPixelForValue(datapoint) -
chart.scales.y.getPixelForValue(errorHigh));

drawErrorBar(ctx, x, y, errorLowPx, errorHighPx, dataset.borderColor, dataset.borderWidth || 1);
}
});
}
Expand Down
19 changes: 18 additions & 1 deletion ell-studio/src/components/graphing/GraphSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,27 @@ export const GraphRenderer = ({ graphId }) => {
...yAxisScale,
},
plugins: {
...sharedConfig.options.plugins,
tooltip: {
callbacks: {
label: function(context) {
const value = context.parsed.y;
let label = `${context.dataset.label}: ${value.toFixed(2)}`;

const chartErrorBarData = context.chart.errorBarData;
const errorData = chartErrorBarData?.[context.datasetIndex]?.[context.dataIndex];

if (errorData) {
label += `(95% CI: [${errorData.low.toFixed(2)}, ${errorData.high.toFixed(2)}])`;
}

return label;
}
}
},
errorBar: {
draw: true,
},
...sharedConfig.options.plugins,
},
};

Expand Down
1 change: 1 addition & 0 deletions ell-studio/src/hooks/useBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const useWebSocketConnection = () => {
queryClient.invalidateQueries({ queryKey: ["lmpDetails"] });
queryClient.invalidateQueries({ queryKey: ["evaluations"] });
queryClient.invalidateQueries({ queryKey: ["latestEvaluations"] });
queryClient.invalidateQueries({ queryKey: ["evaluation"] });
console.log("Database updated, invalidating queries");
}
};
Expand Down

0 comments on commit 49379c4

Please sign in to comment.