Files
WebApp/src/app/dashboard/dashboard.figures.ts
T
Angel Capetillo Zavala fa143a7746 Update: Exportar a PDF
2026-09-25 12:08:08 -06:00

58 lines
2.4 KiB
TypeScript

import type { AnalysisResult } from './dashboard.mock';
import type { ChartFigure } from './plotly-chart';
const ink = '#081839';
const grid = '#e9ede5';
const green = '#6f821c';
const darkGreen = '#465d1e';
const teal = '#5f9ea0';
const font = { family: 'Roboto, sans-serif', color: ink, size: 12 };
export function createChartFigures(result: AnalysisResult): { bars: ChartFigure; donut: ChartFigure; line: ChartFigure } {
const bars: ChartFigure = {
data: [{
type: 'bar',
x: result.charts.categories.map((item) => item.label),
y: result.charts.categories.map((item) => item.value),
marker: { color: [green, darkGreen, teal, '#a8c243'] },
hovertemplate: '%{x}: %{y}<extra></extra>',
}],
layout: {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font,
margin: { l: 36, r: 12, t: 12, b: 48 }, showlegend: false,
xaxis: { showgrid: false, linecolor: grid, automargin: true },
yaxis: { showgrid: true, gridcolor: grid, zeroline: false, rangemode: 'tozero', automargin: true },
},
};
const donut: ChartFigure = {
data: [{
type: 'pie', hole: 0.62,
labels: result.charts.composition.map((item) => item.label),
values: result.charts.composition.map((item) => item.value),
marker: { colors: [green, teal, '#b5c69b'] },
textinfo: 'none', hovertemplate: '%{label}: %{value}<extra></extra>', sort: false,
}],
layout: {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font,
margin: { l: 8, r: 8, t: 8, b: 8 },
showlegend: true, legend: { orientation: 'h', x: 0.5, xanchor: 'center', y: -0.06, font: { color: ink, size: 11 } },
},
};
const line: ChartFigure = {
data: [{
type: 'scatter', mode: 'lines+markers',
x: result.charts.periods.map((item) => item.label),
y: result.charts.periods.map((item) => item.value),
line: { color: darkGreen, width: 3 }, marker: { color: green, size: 8 },
hovertemplate: '%{x}: %{y}<extra></extra>',
}],
layout: {
paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font,
margin: { l: 36, r: 16, t: 12, b: 48 }, showlegend: false,
xaxis: { showgrid: false, linecolor: grid, automargin: true },
yaxis: { showgrid: true, gridcolor: grid, zeroline: false, rangemode: 'tozero', automargin: true },
},
};
return { bars, donut, line };
}