Skip to content

Commit 725dc8e

Browse files
committed
Minor UI fix
1 parent 9810820 commit 725dc8e

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/ui/src/components/document-analytics-layout/PlotDisplay.jsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ const PlotDisplay = ({ plotData }) => {
181181
...originalOptions,
182182
};
183183

184+
// Ensure plugins object exists
185+
if (!baseOptions.plugins) {
186+
baseOptions.plugins = {};
187+
}
188+
184189
// For pie and doughnut charts, we typically don't need scales
185190
if (chartType === 'pie' || chartType === 'doughnut') {
186191
const { scales, ...optionsWithoutScales } = baseOptions;
@@ -199,28 +204,51 @@ const PlotDisplay = ({ plotData }) => {
199204
},
200205
};
201206

207+
// Safely merge tooltip configuration
208+
const existingTooltip = baseOptions.plugins?.tooltip || {};
209+
const existingCallbacks = existingTooltip.callbacks || {};
210+
202211
return {
203212
...optionsWithoutScales,
204213
plugins: {
205214
...baseOptions.plugins,
206215
legend: legendConfig,
207216
tooltip: {
208217
enabled: true,
218+
...existingTooltip,
209219
callbacks: {
220+
...existingCallbacks,
210221
label(context) {
211-
const label = context.label || '';
212-
const value = context.parsed || 0;
213-
const total = context.dataset.data.reduce((sum, val) => sum + val, 0);
214-
const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : 0;
215-
return `${label}: ${value} (${percentage}%)`;
222+
try {
223+
const label = context.label || '';
224+
const value = context.parsed || 0;
225+
const total = context.dataset.data.reduce((sum, val) => sum + val, 0);
226+
const percentage = total > 0 ? ((value / total) * 100).toFixed(1) : 0;
227+
return `${label}: ${value} (${percentage}%)`;
228+
} catch (error) {
229+
console.error('Error in tooltip callback:', error);
230+
return context.label || 'Unknown';
231+
}
216232
},
217233
},
218-
...baseOptions.plugins?.tooltip,
219234
},
220235
},
221236
};
222237
}
223238

239+
// For other chart types, ensure tooltip callbacks are properly structured
240+
if (baseOptions.plugins?.tooltip?.callbacks) {
241+
const existingCallbacks = baseOptions.plugins.tooltip.callbacks;
242+
243+
// Validate that callbacks are functions
244+
Object.keys(existingCallbacks).forEach((callbackName) => {
245+
if (typeof existingCallbacks[callbackName] !== 'function') {
246+
console.warn(`Invalid tooltip callback '${callbackName}' - not a function`);
247+
delete existingCallbacks[callbackName];
248+
}
249+
});
250+
}
251+
224252
return baseOptions;
225253
};
226254

0 commit comments

Comments
 (0)