fix(cama): recuperar el tamaño responsivo de la dona BI-RADS
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
<div class="figures">
|
<div class="figures">
|
||||||
<section class="figure"><h3>{{ par.unidades.examenes | titlecase }} por categoría, {{ m.periodo }}</h3>
|
<section class="figure"><h3>{{ par.unidades.examenes | titlecase }} por categoría, {{ m.periodo }}</h3>
|
||||||
@if (total) {
|
@if (total) {
|
||||||
<app-plotly-chart [figure]="donutFigure!" class="donut-chart" [showNotes]="false" [label]="indicador.titulo + ', dona, ' + m.periodo" />
|
<app-plotly-chart [figure]="donutFigure!" class="donut-chart" (widthChanged)="ajustarAnchoDona($event)" [showNotes]="false" [label]="indicador.titulo + ', dona, ' + m.periodo" />
|
||||||
} @else { <p role="status">{{ total === null ? 'Dona no disponible: hay celdas suprimidas o sin dato.' : 'Sin ' + par.unidades.examenes + ' en el periodo.' }}</p> }
|
} @else { <p role="status">{{ total === null ? 'Dona no disponible: hay celdas suprimidas o sin dato.' : 'Sin ' + par.unidades.examenes + ' en el periodo.' }}</p> }
|
||||||
@if (m.sinDato) { <p class="note">Fuera de la dona: {{ texto(m.sinDato) }} {{ par.unidades.examenes }} sin categoría.</p> }
|
@if (m.sinDato) { <p class="note">Fuera de la dona: {{ texto(m.sinDato) }} {{ par.unidades.examenes }} sin categoría.</p> }
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ h3 { font-size: 1rem; font-weight: 500; line-height: 1.5; }
|
|||||||
@media (min-width: 1100px) { .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
@media (min-width: 1100px) { .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||||||
app-plotly-chart { --plot-height: 400px; }
|
app-plotly-chart { --plot-height: 400px; }
|
||||||
// Keep space for the outside labels and let the existing plot viewport scroll on very narrow cards.
|
// Keep space for the outside labels and let the existing plot viewport scroll on very narrow cards.
|
||||||
.donut-chart { --plot-min-width: 390px; }
|
.donut-chart { --plot-min-width: 230px; }
|
||||||
summary { cursor: pointer; padding-block: .75rem; }
|
summary { cursor: pointer; padding-block: .75rem; }
|
||||||
summary:focus-visible, .table-scroll:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; }
|
summary:focus-visible, .table-scroll:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; }
|
||||||
.table-scroll { overflow: auto; }
|
.table-scroll { overflow: auto; }
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export class IndicadorConteosPareados implements OnChanges, OnDestroy {
|
|||||||
private subscription?: Subscription;
|
private subscription?: Subscription;
|
||||||
private key = '';
|
private key = '';
|
||||||
private loaded = false;
|
private loaded = false;
|
||||||
|
private anchoDona = 390;
|
||||||
|
|
||||||
get model(): ModeloConteos | undefined { return this.pages[this.periodIndex]; }
|
get model(): ModeloConteos | undefined { return this.pages[this.periodIndex]; }
|
||||||
get total() { return this.model ? totalExamenes(this.model) : null; }
|
get total() { return this.model ? totalExamenes(this.model) : null; }
|
||||||
@@ -104,10 +105,16 @@ export class IndicadorConteosPareados implements OnChanges, OnDestroy {
|
|||||||
if (![1, -1].includes(step) || !this.pages[this.periodIndex + step]) return;
|
if (![1, -1].includes(step) || !this.pages[this.periodIndex + step]) return;
|
||||||
this.periodIndex += step; this.draw();
|
this.periodIndex += step; this.draw();
|
||||||
}
|
}
|
||||||
|
ajustarAnchoDona(ancho: number) {
|
||||||
|
if (ancho === this.anchoDona) return;
|
||||||
|
this.anchoDona = ancho;
|
||||||
|
const m = this.model;
|
||||||
|
if (m) this.donutFigure = donaConteos(m, this.par, this.tema, ancho);
|
||||||
|
}
|
||||||
private draw() {
|
private draw() {
|
||||||
const m = this.model;
|
const m = this.model;
|
||||||
if (!m) return;
|
if (!m) return;
|
||||||
this.donutFigure = donaConteos(m, this.par, this.tema);
|
this.donutFigure = donaConteos(m, this.par, this.tema, this.anchoDona);
|
||||||
this.barsFigure = barrasConteos(m, this.par, this.tema);
|
this.barsFigure = barrasConteos(m, this.par, this.tema);
|
||||||
this.changeDetector.markForCheck();
|
this.changeDetector.markForCheck();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,12 +108,20 @@ export function modelosConteos(par: ParConteos, examenes: IndicadorDatos, pacien
|
|||||||
export const totalExamenes = (m: ModeloConteos) => sumar(m.examenes.map(c => c.n));
|
export const totalExamenes = (m: ModeloConteos) => sumar(m.examenes.map(c => c.n));
|
||||||
|
|
||||||
const ALTO_DONA = 400, MARGEN_DONA = 8;
|
const ALTO_DONA = 400, MARGEN_DONA = 8;
|
||||||
const RADIO_DONA = (ALTO_DONA - 2 * MARGEN_DONA) * .2;
|
const DIAMETRO_MAXIMO_DONA = 270;
|
||||||
|
|
||||||
export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema): PlotlyFigure {
|
export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema, ancho = 390): PlotlyFigure {
|
||||||
const total = totalExamenes(m);
|
const total = totalExamenes(m);
|
||||||
if (!total) return { data: [], layout: {} };
|
if (!total) return { data: [], layout: {} };
|
||||||
const p = c2Theme(tema), n = m.examenes.map(c => c.n!);
|
const p = c2Theme(tema), n = m.examenes.map(c => c.n!);
|
||||||
|
// Fit both label columns before sizing the ring. Use the same radius for Plotly and the guide lines.
|
||||||
|
const margenEtiquetas = Math.min(90, 59 + Math.max(0, ancho - 230) * .2);
|
||||||
|
const diametro = Math.max(1, Math.min(DIAMETRO_MAXIMO_DONA, ancho - 2 * (MARGEN_DONA + margenEtiquetas)));
|
||||||
|
const radio = diametro / 2;
|
||||||
|
const fraccionVertical = radio / (ALTO_DONA - 2 * MARGEN_DONA);
|
||||||
|
const fuenteEtiqueta = Math.round(8 + (margenEtiquetas - 59) / 10);
|
||||||
|
const fuenteUnidad = Math.min(11, Math.max(7, Math.round(radio / 7)));
|
||||||
|
const separacionCentro = fuenteUnidad === 7 ? 6 : fuenteUnidad < 11 ? 7 : 8;
|
||||||
const etiquetas = m.examenes.map(c => escapar(c.etiqueta));
|
const etiquetas = m.examenes.map(c => escapar(c.etiqueta));
|
||||||
const porcentajes = n.map(v => percentNumber(100 * v / total));
|
const porcentajes = n.map(v => percentNumber(100 * v / total));
|
||||||
const centro = { x: .5, y: .5, xref: 'paper', yref: 'paper', showarrow: false };
|
const centro = { x: .5, y: .5, xref: 'paper', yref: 'paper', showarrow: false };
|
||||||
@@ -124,7 +132,7 @@ export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema): Plot
|
|||||||
const angulo = 2 * Math.PI * (acumulado + valor / 2) / total;
|
const angulo = 2 * Math.PI * (acumulado + valor / 2) / total;
|
||||||
acumulado += valor;
|
acumulado += valor;
|
||||||
if (!valor) return [];
|
if (!valor) return [];
|
||||||
const x = RADIO_DONA * Math.sin(angulo), y = RADIO_DONA * Math.cos(angulo);
|
const x = radio * Math.sin(angulo), y = radio * Math.cos(angulo);
|
||||||
return [{ i, x, y }];
|
return [{ i, x, y }];
|
||||||
});
|
});
|
||||||
const llamadas = [-1, 1].flatMap(lado => {
|
const llamadas = [-1, 1].flatMap(lado => {
|
||||||
@@ -133,26 +141,26 @@ export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema): Plot
|
|||||||
const altura = (columna.length - 1 - 2 * fila) * 24;
|
const altura = (columna.length - 1 - 2 * fila) * 24;
|
||||||
const texto = etiquetas[i].replace(' (sin subcategoría)', '<br>(sin<br>subcategoría)');
|
const texto = etiquetas[i].replace(' (sin subcategoría)', '<br>(sin<br>subcategoría)');
|
||||||
return {
|
return {
|
||||||
annotation: { ...centro, xshift: lado * 105, yshift: altura,
|
annotation: { ...centro, xshift: lado * (radio + 10), yshift: altura,
|
||||||
xanchor: lado < 0 ? 'right' : 'left', align: lado < 0 ? 'right' : 'left',
|
xanchor: lado < 0 ? 'right' : 'left', align: lado < 0 ? 'right' : 'left',
|
||||||
font: { size: 11, color: p.text }, text: texto + '<br>' + porcentajes[i] + ' %' },
|
font: { size: fuenteEtiqueta, color: p.text }, text: texto + '<br>' + porcentajes[i] + ' %' },
|
||||||
shape: { type: 'path', xref: 'paper', yref: 'paper', xsizemode: 'pixel', ysizemode: 'pixel',
|
shape: { type: 'path', xref: 'paper', yref: 'paper', xsizemode: 'pixel', ysizemode: 'pixel',
|
||||||
xanchor: .5, yanchor: .5, line: { color: p.text, width: 1 },
|
xanchor: .5, yanchor: .5, line: { color: p.text, width: 1 },
|
||||||
path: 'M ' + Math.round(x) + ',' + Math.round(y) + ' L ' + lado * 86 + ',' + y + ' L ' + lado * 101 + ',' + altura },
|
path: 'M ' + Math.round(x) + ',' + Math.round(y) + ' L ' + lado * (radio + 3) + ',' + y + ' L ' + lado * (radio + 8) + ',' + altura },
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return { data: [{ type: 'pie', hole: .54, sort: false, direction: 'clockwise', values: n, labels: etiquetas,
|
return { data: [{ type: 'pie', hole: .54, sort: false, direction: 'clockwise', values: n, labels: etiquetas,
|
||||||
marker: { colors: m.examenes.map(c => c.color), line: { color: p.background, width: 2 } }, textinfo: 'none',
|
marker: { colors: m.examenes.map(c => c.color), line: { color: p.background, width: 2 } }, textinfo: 'none',
|
||||||
domain: { x: [0, 1], y: [.3, .7] },
|
domain: { x: [0, 1], y: [.5 - fraccionVertical, .5 + fraccionVertical] },
|
||||||
customdata: n.map((v, i) => [miles(v), porcentajes[i]]),
|
customdata: n.map((v, i) => [miles(v), porcentajes[i]]),
|
||||||
hovertemplate: '%{value}<extra></extra>' }],
|
hovertemplate: '%{value}<extra></extra>' }],
|
||||||
layout: { autosize: true, height: ALTO_DONA, showlegend: false, paper_bgcolor: p.background, font: { color: p.text },
|
layout: { autosize: true, height: ALTO_DONA, showlegend: false, paper_bgcolor: p.background, font: { color: p.text },
|
||||||
margin: { t: MARGEN_DONA, b: MARGEN_DONA, l: MARGEN_DONA, r: MARGEN_DONA },
|
margin: { t: MARGEN_DONA, b: MARGEN_DONA, l: MARGEN_DONA, r: MARGEN_DONA },
|
||||||
shapes: llamadas.map(({ shape }) => shape),
|
shapes: llamadas.map(({ shape }) => shape),
|
||||||
annotations: [
|
annotations: [
|
||||||
{ ...centro, yshift: 8, font: { size: 14, color: p.text }, text: `<b>${miles(total)}</b>` },
|
{ ...centro, yshift: separacionCentro, font: { size: fuenteUnidad + 3, color: p.text }, text: `<b>${miles(total)}</b>` },
|
||||||
{ ...centro, yshift: -8, font: { size: 11, color: p.text }, text: par.unidades.examenes },
|
{ ...centro, yshift: -separacionCentro, font: { size: fuenteUnidad, color: p.text }, text: par.unidades.examenes },
|
||||||
...llamadas.map(({ annotation }) => annotation),
|
...llamadas.map(({ annotation }) => annotation),
|
||||||
] }, config: { displayModeBar: false } };
|
] }, config: { displayModeBar: false } };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user