Просмотр исходного кода

fix: let charts handle aggregation (#18293) (#18295)

Currently we are doing aggregation of remaining slices manually BUT this
breaks basic principle of DRY:

- dashboard chart decides how many groups to consider
- frappe charts has different maxSlices config

This results in mess like frappe computing "Other" and Frappe charts
computing "rest" separately.

Fix: Just pass all data to charts and let it figure out the "Rest".
(cherry picked from commit d597acb5e2)

Co-authored-by: Ankush Menat <ankush@frappe.io>
version-14
mergify[bot] 2 лет назад
committed by GitHub
Родитель
Сommit
e0974c53ab
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
2 измененных файлов: 2 добавлений и 8 удалений
  1. +0
    -7
      frappe/desk/doctype/dashboard_chart/dashboard_chart.py
  2. +2
    -1
      frappe/public/js/frappe/widgets/chart_widget.js

+ 0
- 7
frappe/desk/doctype/dashboard_chart/dashboard_chart.py Просмотреть файл

@@ -293,13 +293,6 @@ def get_group_by_chart_config(chart, filters):
) )


if data: if data:
if chart.number_of_groups and chart.number_of_groups < len(data):
other_count = 0
for i in range(chart.number_of_groups - 1, len(data)):
other_count += data[i]["count"]
data = data[0 : chart.number_of_groups - 1]
data.append({"name": "Other", "count": other_count})

chart_config = { chart_config = {
"labels": [item["name"] if item["name"] else "Not Specified" for item in data], "labels": [item["name"] if item["name"] else "Not Specified" for item in data],
"datasets": [{"name": chart.name, "values": [item["count"] for item in data]}], "datasets": [{"name": chart.name, "values": [item["count"] for item in data]}],


+ 2
- 1
frappe/public/js/frappe/widgets/chart_widget.js Просмотреть файл

@@ -571,12 +571,13 @@ export default class ChartWidget extends Widget {
Heatmap: "heatmap", Heatmap: "heatmap",
}; };


let max_slices = ["Pie", "Donut"].includes(this.chart_doc.type) ? 6 : 9;
let chart_args = { let chart_args = {
data: this.data, data: this.data,
type: chart_type_map[this.chart_doc.type], type: chart_type_map[this.chart_doc.type],
colors: colors, colors: colors,
height: this.height, height: this.height,
maxSlices: ["Pie", "Donut"].includes(this.chart_doc.type) ? 6 : 9,
maxSlices: this.chart_doc.number_of_groups || max_slices,
axisOptions: { axisOptions: {
xIsSeries: this.chart_doc.timeseries, xIsSeries: this.chart_doc.timeseries,
shortenYAxisNumbers: 1, shortenYAxisNumbers: 1,


Загрузка…
Отмена
Сохранить