Skip to content

Commit

Permalink
Merge pull request moneymanagerex#6567 from n-stein/fix(moneymanagere…
Browse files Browse the repository at this point in the history
…x#6566)

fix(moneymanagerex#6566): localize pie chart legends
  • Loading branch information
whalley authored Mar 7, 2024
2 parents 1538773 + 06c58f4 commit cdfe950
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/reports/htmlbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,23 @@ void mmHTMLBuilder::addChart(const GraphData& gd)
htmlChart += ", dataLabels: { enabled: false }";
} else if (gd.type == GraphData::PIE || gd.type == GraphData::DONUT)
{
wxString locale = Model_Infotable::instance().GetStringInfo("LOCALE", "");

if (locale.IsEmpty())
locale = "undefined";
else
locale.Append("'").Prepend("'").Replace("_", "-");

htmlChart += ", legend: { formatter: function(seriesName, opts){ "
"var percent = (+opts.w.globals.seriesPercent[opts.seriesIndex]).toFixed(1); "
"percent = new Array((5 - percent.length)*2).join(' ') + percent; "
+ wxString::Format("var valueLength = chart_%s.reduce(function(a, b) {return (a.toString().length > b.toString().length ? a : b) }, []).toString().length; var value = chart_%s[opts.seriesIndex]; ", divid, divid)
+ "if (valueLength > value.toString().length) { value = new Array((valueLength - value.toString().length)*2).join(' ') + (parseInt(value) == value ? value : ' ' + value); } "
"percent = new Array((5 - percent.length)*2).join(' ') + percent; " +
wxString::Format("var localizedValues = opts.w.globals.series.map(function(value){ return value.toLocaleString(%s, {minimumFractionDigits: %i, "
"maximumFractionDigits: %i});});",
locale, precision, precision)

+ "var valueLength = localizedValues.reduce(function(a, b) {return Math.max(a, b.length) }, 0) + 1;" +
wxString::Format("var value = chart_%s[opts.seriesIndex].toLocaleString(%s, {minimumFractionDigits: %i, maximumFractionDigits: %i});", divid, locale, precision, precision) +
"value = new Array((valueLength - value.toString().length)*2 + value.split((1000).toLocaleString(" + wxString::Format("%s", locale) + ").charAt(1)).length - 1).join(' ') + value;"
"return['<strong>', percent + '%&nbsp;', value, '&nbsp;</strong>', seriesName] } }\n";
htmlChart += ", dataLabels: { enabled: true, style: { fontSize: '16px' }, dropShadow: { enabled: false } }\n";
}
Expand Down

0 comments on commit cdfe950

Please sign in to comment.