Merge pull request #17520 from ankush/country_specific_short_numbers

feat: country specific number shortening in charts
This commit is contained in:
Ankush Menat 2022-07-18 19:06:20 +05:30 committed by GitHub
commit afba6a4815
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 12 deletions

View file

@ -554,7 +554,8 @@ frappe.ui.form.Dashboard = class FormDashboard {
colors: ['green'],
truncateLegends: 1,
axisOptions: {
shortenYAxisNumbers: 1
shortenYAxisNumbers: 1,
numberFormatter: frappe.utils.format_chart_axis_number,
}
});
this.show();

View file

@ -1145,7 +1145,12 @@ Object.assign(frappe.utils, {
{
divisor: 1.0e+5,
symbol: 'Lakh'
}],
},
{
divisor: 1.0e+3,
symbol: 'K',
}
],
'':
[{
divisor: 1.0e+12,
@ -1205,7 +1210,8 @@ Object.assign(frappe.utils, {
axisOptions: {
xIsSeries: 1,
shortenYAxisNumbers: 1,
xAxisMode: 'tick'
xAxisMode: 'tick',
numberFormatter: frappe.utils.format_chart_axis_number,
}
};
@ -1220,6 +1226,11 @@ Object.assign(frappe.utils, {
return new frappe.Chart(wrapper, chart_args);
},
format_chart_axis_number(label, country) {
const default_country = frappe.sys_defaults.country;
return frappe.utils.shorten_number(label, country || default_country, 3);
},
generate_route(item) {
const type = item.type.toLowerCase();
if (type === "doctype") {

View file

@ -944,10 +944,10 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
};
}
options.axisOptions = {
shortenYAxisNumbers: 1
shortenYAxisNumbers: 1,
numberFormatter: frappe.utils.format_chart_axis_number,
};
options.height = 280;
return options;
}

View file

@ -30,7 +30,8 @@ frappe.report_utils = {
colors: colors,
axisOptions: {
shortenYAxisNumbers: 1,
xAxisMode: 'tick'
xAxisMode: 'tick',
numberFormatter: frappe.utils.format_chart_axis_number,
}
};

View file

@ -529,7 +529,8 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
truncateLegends: 1,
colors: ['#70E078', 'light-blue', 'orange', 'red'],
axisOptions: {
shortenYAxisNumbers: 1
shortenYAxisNumbers: 1,
numberFormatter: frappe.utils.format_chart_axis_number,
},
tooltipOptions: {
formatTooltipY: value => frappe.format(value, get_df(this.chart_args.y_axes[0]), { always_show_decimals: true, inline: true }, get_doc(value.doc))

View file

@ -589,6 +589,10 @@ details > summary:focus {
background-color: var(--diff-removed);
}
.chart-wrapper {
padding: 1em;
}
// REDESIGN TODO: Handling of broken images?
// img.no-image:before {
// .img-background();

View file

@ -32,7 +32,7 @@
"driver.js": "^0.9.8",
"editorjs-undo": "0.1.6",
"fast-deep-equal": "^2.0.1",
"frappe-charts": "^2.0.0-rc13",
"frappe-charts": "2.0.0-rc22",
"frappe-datatable": "^1.16.4",
"frappe-gantt": "^0.6.0",
"highlight.js": "^10.4.1",

View file

@ -1256,10 +1256,10 @@ fraction.js@^4.1.2:
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.2.0.tgz#448e5109a313a3527f5a3ab2119ec4cf0e0e2950"
integrity sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==
frappe-charts@^2.0.0-rc13:
version "2.0.0-rc13"
resolved "https://registry.yarnpkg.com/frappe-charts/-/frappe-charts-2.0.0-rc13.tgz#fdb251d7ae311c41e38f90a3ae108070ec6b9072"
integrity sha512-Bv7IfllIrjRbKWHn5b769dOSenqdBixAr6m5kurf8ZUOJSLOgK4HOXItJ7BA8n9PvviH9/k5DaloisjLM2Bm1w==
frappe-charts@^2.0.0-rc22:
version "2.0.0-rc22"
resolved "https://registry.yarnpkg.com/frappe-charts/-/frappe-charts-2.0.0-rc22.tgz#9a5a747febdc381a1d4d7af96e89cf519dfba8c0"
integrity sha512-N7f/8979wJCKjusOinaUYfMxB80YnfuVLrSkjpj4LtyqS0BGS6SuJxUnb7Jl4RWUFEIs7zEhideIKnyLeFZF4Q==
frappe-datatable@^1.16.4:
version "1.16.4"