Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): draw a scatter at zero without the empty-state text
marcotebb0381a5b37c5
diff --git a/mcp-host/src/workflow/__tests__/internalTools.charts.rendering.test.ts b/mcp-host/src/workflow/__tests__/internalTools.charts.rendering.test.tsindex e0512fa76..1a0e1ff4e 100644--- a/mcp-host/src/workflow/__tests__/internalTools.charts.rendering.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.charts.rendering.test.ts@@ -741,6 +741,52 @@ describe('colors follow their points', () => {})})+describe('empty state', () => {+ /** The ids of the plugins the chart `args` is drawn with. */+ async function pluginsOf(args: Record<string, unknown>): Promise<string[]> {+ const seen: string[][] = []+ const draw = Chart.prototype.draw+ const spy = vi.spyOn(Chart.prototype, 'draw').mockImplementation(function (this: Chart) {+ seen.push((this.config.plugins ?? []).map(plugin => plugin.id))+ return draw.call(this)+ })+ try {+ const r = await findTool('clerum__generate_chart').execute(args, outputDir)+ expect(r.success, r.error).toBe(true)+ } finally {+ spy.mockRestore()+ }+ return seen[seen.length - 1]+ }++ it.each([+ [+ 'scatter',+ [+ { x: 1, y: 0 },+ { x: 2, y: 0 },+ ],+ ],+ ['bubble', [{ x: 1, y: 0, r: 5 }]],+ ])('draws a %s whose points sit at zero without the empty-state text', async (type, data) => {+ const plugins = await pluginsOf({+ filename: `${type}-zero.png`,+ type,+ data: { datasets: [{ label: 'S', data }] },+ })+ expect(plugins).not.toContain('clerumEmptyState')+ })++ it('still marks a bar chart whose values are all zero as empty', async () => {+ const plugins = await pluginsOf({+ filename: 'bar-zero.png',+ type: 'bar',+ data: { labels: ['a', 'b'], datasets: [{ label: 'S', data: [0, 0] }] },+ })+ expect(plugins).toContain('clerumEmptyState')+ })+})+describe('axes and points', () => {interface Drawn {scales: Record<string, { min: number; max: number }>diff --git a/mcp-host/src/workflow/chartGenerator.ts b/mcp-host/src/workflow/chartGenerator.tsindex d2f0e06e5..7b77803d4 100644--- a/mcp-host/src/workflow/chartGenerator.ts+++ b/mcp-host/src/workflow/chartGenerator.ts@@ -529,8 +529,22 @@ function resolveValueFormat(raw: unknown): ValueFormat {return allowed.includes(v) ? v : 'auto'}-/** True when every plotted number is absent or zero, so nothing would be drawn. */-function isVisuallyEmpty(datasets: ChartDataset[]): boolean {+/**+ * True when nothing would be drawn: every plotted number is absent or zero,+ * or, on a scatter or bubble chart (`xy`), no point has both coordinates. A+ * point is drawn wherever it sits, at zero too.+ */+function isVisuallyEmpty(datasets: ChartDataset[], xy: boolean): boolean {+ if (xy) {+ return !datasets.some(ds =>+ (ds.data as unknown[]).some(point => {+ const at = point as { x?: unknown; y?: unknown } | null+ return (+ typeof at === 'object' && at !== null && Number.isFinite(at.x) && Number.isFinite(at.y)+ )+ })+ )+ }let sawNumber = falsefor (const ds of datasets) {for (const point of ds.data as unknown[]) {@@ -780,7 +794,7 @@ export async function runGenerateChart(}))}- if (isVisuallyEmpty(themedDatasets)) {+ if (isVisuallyEmpty(themedDatasets, chartTypeRaw === 'scatter' || chartTypeRaw === 'bubble')) {plugins.push(emptyStatePlugin('No data to display', theme.textColor))}