@esfaenza/es-charts 20.3.13 → 20.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1819,6 +1819,7 @@ class PieChartService {
|
|
|
1819
1819
|
//#region Carico il Grafico
|
|
1820
1820
|
this.ChartRoot?.dispose();
|
|
1821
1821
|
this.ChartRoot = am5.Root.new(settings.Name);
|
|
1822
|
+
this.applyLocale(settings);
|
|
1822
1823
|
let ChartContainer = this.ChartRoot.container.children.push(am5.Container.new(this.ChartRoot, {
|
|
1823
1824
|
width: am5.percent(100),
|
|
1824
1825
|
height: am5.percent(100),
|
|
@@ -1955,9 +1956,14 @@ class PieChartService {
|
|
|
1955
1956
|
else if (settings.LabelsTruncate)
|
|
1956
1957
|
series.labels.template.setAll({ oversizedBehavior: "truncate" });
|
|
1957
1958
|
}
|
|
1959
|
+
// I dati vanno assegnati PRIMA di calcolare il totale e registrare gli handler: altrimenti i dataItems
|
|
1960
|
+
// non esistono ancora e il totale verrebbe calcolato su una serie vuota (restando a 0)
|
|
1961
|
+
series.data.setAll(dataConverted.values);
|
|
1958
1962
|
// Configurazione "Mostra Totale"
|
|
1959
1963
|
if (settings.Total?.Show) {
|
|
1960
|
-
|
|
1964
|
+
// La label va agganciata al seriesContainer (la cui origine e il centro della torta) e centrata su
|
|
1965
|
+
// di esso: cosi compare esattamente al centro della ciambella, come nella versione amCharts4
|
|
1966
|
+
let label = this.ChartInstance.seriesContainer.children.push(am5.Label.new(this.ChartRoot, {
|
|
1961
1967
|
centerX: am5.p50,
|
|
1962
1968
|
centerY: am5.p50,
|
|
1963
1969
|
textAlign: "center"
|
|
@@ -1969,7 +1975,9 @@ class PieChartService {
|
|
|
1969
1975
|
return;
|
|
1970
1976
|
total += di.get("valueWorking") ?? di.get("value") ?? 0;
|
|
1971
1977
|
});
|
|
1972
|
-
|
|
1978
|
+
// Tronco a 2 decimali e formatto coi separatori del locale (es. "11.506.370,17")
|
|
1979
|
+
let truncated = Math.trunc(total * 100) / 100;
|
|
1980
|
+
let sumString = this.ChartRoot.numberFormatter.format(truncated, "#,###.00");
|
|
1973
1981
|
let fs = 28;
|
|
1974
1982
|
if (sumString.length >= 9)
|
|
1975
1983
|
fs = 18;
|
|
@@ -1978,7 +1986,7 @@ class PieChartService {
|
|
|
1978
1986
|
else if (sumString.length == 7)
|
|
1979
1987
|
fs = 23;
|
|
1980
1988
|
label.set("html", `<div style="text-align:center">
|
|
1981
|
-
<div style="font-size:${settings.Total?.TitleSize || 18}px">Totale
|
|
1989
|
+
<div style="font-size:${settings.Total?.TitleSize || 18}px">Totale:</div>
|
|
1982
1990
|
<div style="font-weight:bold;font-size:${settings.Total?.NumberSize || fs}px">
|
|
1983
1991
|
<span>${sumString}${settings.Total?.UnitOfMeasure ? " " + settings.Total.UnitOfMeasure : ""}</span>
|
|
1984
1992
|
</div>
|
|
@@ -1990,11 +1998,11 @@ class PieChartService {
|
|
|
1990
1998
|
di.on("valueWorking", updateTotal);
|
|
1991
1999
|
});
|
|
1992
2000
|
}
|
|
1993
|
-
series.data.setAll(dataConverted.values);
|
|
1994
2001
|
if (settings.Legend) {
|
|
2002
|
+
// Valore formattato coi separatori del locale e due decimali (es. "4.662.970,79"), come in amCharts4
|
|
1995
2003
|
series.setAll({
|
|
1996
|
-
legendLabelText: "{category}
|
|
1997
|
-
legendValueText: "{value}"
|
|
2004
|
+
legendLabelText: "{category}",
|
|
2005
|
+
legendValueText: "{value.formatNumber('#,###.00')}"
|
|
1998
2006
|
});
|
|
1999
2007
|
this.ChartLegend.data.setAll(series.dataItems);
|
|
2000
2008
|
}
|
|
@@ -2005,6 +2013,16 @@ class PieChartService {
|
|
|
2005
2013
|
}
|
|
2006
2014
|
return this;
|
|
2007
2015
|
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Applica il locale italiano al root del grafico quando richiesto, cosi che il numberFormatter usi i
|
|
2018
|
+
* separatori corretti (es. 4.662.970,79). Senza questo amCharts5 userebbe il formato di default (4,662,970).
|
|
2019
|
+
*
|
|
2020
|
+
* @param {PieChartSettings} settings Impostazioni del grafico (da cui si legge il Locale)
|
|
2021
|
+
*/
|
|
2022
|
+
applyLocale(settings) {
|
|
2023
|
+
if ((settings.Locale ?? "").toLowerCase().startsWith("it"))
|
|
2024
|
+
this.ChartRoot.locale = am5locales_it_IT;
|
|
2025
|
+
}
|
|
2008
2026
|
/** @ignore */
|
|
2009
2027
|
setSelection(from, to) { }
|
|
2010
2028
|
/** @ignore */
|