From 8ebf870f41088c4aae1eeb89770e19773612cd52 Mon Sep 17 00:00:00 2001 From: alberto Date: Tue, 1 Dec 2026 17:23:53 -0600 Subject: [PATCH] Plot axes are built fresh for every chart The module-level axis defaults were shared by every chart, and Plotly writes its detected axis type, range and autorange back into the layout it is given, so one chart's category axis and range leaked into the others (count axes typed as categories, percent ranges ignored). Each layout now gets its own axis objects. --- src/app/indicadores/figures.ts | 7 ++++++- src/app/plot.ts | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/app/indicadores/figures.ts b/src/app/indicadores/figures.ts index 4b8ae2f..832ed55 100644 --- a/src/app/indicadores/figures.ts +++ b/src/app/indicadores/figures.ts @@ -5,7 +5,12 @@ import type { Catalog, Category, HistoryPanel } from './pages'; const OLIVE = '#A8C243'; const ROSE = '#C24269'; export const SHORT = '.1~f'; -export const percentAxis = { ticksuffix: ' %', tickformat: '.0f', hoverformat: SHORT }; +export const percentAxis = { + type: 'linear' as const, + ticksuffix: ' %', + tickformat: '.0f', + hoverformat: SHORT, +}; const count = (n: number) => n.toLocaleString('es-MX'); const percent = (n: number) => (Math.round(n * 10) / 10).toLocaleString('es-MX'); diff --git a/src/app/plot.ts b/src/app/plot.ts index bd4a226..22f38eb 100644 --- a/src/app/plot.ts +++ b/src/app/plot.ts @@ -23,11 +23,11 @@ const LAYOUT: Partial = { legend: { orientation: 'h', x: 0, xanchor: 'left', y: 1.02, yanchor: 'bottom' }, hoverlabel: { font: { family: 'Roboto, Arial, sans-serif', size: 13 } }, }; -const AXIS = { +const axisDefaults = (): Partial => ({ automargin: true, title: { standoff: 12 }, ticklabelstandoff: 4, -} as Partial; +}); function layoutOf(layout: Partial = {}): Partial { const axes = Object.fromEntries( @@ -36,13 +36,14 @@ function layoutOf(layout: Partial = {}): Partial { .map(([k, v]) => { const axis = (v ?? {}) as Partial; const title = typeof axis.title === 'string' ? { text: axis.title } : axis.title; - return [k, { ...AXIS, ...axis, title: { ...AXIS.title, ...title } }]; + const base = axisDefaults(); + return [k, { ...base, ...axis, title: { ...base.title, ...title } }]; }), ); return { ...LAYOUT, - xaxis: AXIS, - yaxis: AXIS, + xaxis: axisDefaults(), + yaxis: axisDefaults(), ...layout, ...axes, legend: { ...LAYOUT.legend, ...layout.legend },