diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.js b/frappe/desk/doctype/dashboard_chart/dashboard_chart.js index a130c1d6cf..275028fc15 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.js +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.js @@ -59,6 +59,10 @@ frappe.ui.form.on('Dashboard Chart', { if (frm.doc.report_name) { frm.trigger('set_chart_report_filters'); } + + if (!frappe.boot.developer_mode) { + frm.set_df_property("custom_options", "hidden", 1); + } }, source: function(frm) { diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.json b/frappe/desk/doctype/dashboard_chart/dashboard_chart.json index 676cdbe24a..cd32292783 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.json +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.json @@ -33,6 +33,7 @@ "type", "column_break_2", "color", + "custom_options", "section_break_10", "last_synced_on" ], @@ -124,7 +125,7 @@ "fieldname": "type", "fieldtype": "Select", "label": "Type", - "options": "Line\nBar\nPercentage\nPie", + "options": "Line\nBar\nPercentage\nPie\nDonut", "reqd": 1 }, { @@ -213,10 +214,16 @@ "label": "Y Axis", "mandatory_depends_on": "eval:doc.report_name && !doc.is_custom", "options": "Dashboard Chart Field" + }, + { + "description": "Ex: \"colors\": [\"#d1d8dd\", \"#ff5858\"]", + "fieldname": "custom_options", + "fieldtype": "Code", + "label": "Custom Options" } ], "links": [], - "modified": "2020-04-08 18:54:36.739183", + "modified": "2020-04-20 23:49:11.389909", "modified_by": "Administrator", "module": "Desk", "name": "Dashboard Chart", diff --git a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py index b2a6f0a0ff..36a75bd9d5 100644 --- a/frappe/desk/doctype/dashboard_chart/dashboard_chart.py +++ b/frappe/desk/doctype/dashboard_chart/dashboard_chart.py @@ -97,6 +97,10 @@ def create_report_chart(args): _doc = frappe.new_doc('Dashboard Chart') _doc.update(args) + + if (args.get("custom_options")): + _doc.custom_options = json.dumps(args.get("custom_options")) + if frappe.db.exists('Dashboard Chart', args.chart_name): args.chart_name = append_number_if_name_exists('Dashboard Chart', args.chart_name) _doc.chart_name = args.chart_name @@ -108,6 +112,7 @@ def create_report_chart(args): @frappe.whitelist() def add_chart_to_dashboard(args): args = frappe.parse_json(args) + dashboard = frappe.get_doc('Dashboard', args.dashboard) dashboard_link = frappe.new_doc('Dashboard Chart Link') dashboard_link.chart = args.chart_name @@ -362,6 +367,8 @@ class DashboardChart(Document): self.check_required_field() self.check_document_type() + self.validate_custom_options() + def check_required_field(self): if not self.document_type: frappe.throw(_("Document type is required to create a dashboard chart")) @@ -378,3 +385,10 @@ class DashboardChart(Document): def check_document_type(self): if frappe.get_meta(self.document_type).issingle: frappe.throw("You cannot create a dashboard chart from single DocTypes") + + def validate_custom_options(self): + if self.custom_options: + try: + json.loads(self.custom_options) + except ValueError as error: + frappe.throw("Invalid json added in the custom options: %s" % error) \ No newline at end of file diff --git a/frappe/public/js/frappe/views/reports/query_report.js b/frappe/public/js/frappe/views/reports/query_report.js index be24273cb5..5105494862 100644 --- a/frappe/public/js/frappe/views/reports/query_report.js +++ b/frappe/public/js/frappe/views/reports/query_report.js @@ -183,7 +183,6 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList { } create_dashboard_chart(chart_args, dashboard_name, chart_name) { - let args = { 'dashboard': dashboard_name || null, 'chart_type': 'Report', @@ -191,8 +190,15 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList { 'type': chart_args.chart_type || frappe.model.unscrub(chart_args.type), 'color': chart_args.color, 'filters_json': JSON.stringify(this.get_filter_values()), + 'custom_options': {} }; + for (let key in chart_args) { + if (key != "data") { + args['custom_options'][key] = chart_args[key]; + } + } + if (this.chart_fields) { let x_field_title = toTitle(chart_args.x_field); let y_field_title = toTitle(chart_args.y_fields[0]); diff --git a/frappe/public/js/frappe/widgets/chart_widget.js b/frappe/public/js/frappe/widgets/chart_widget.js index 9c03f08523..313b0ea293 100644 --- a/frappe/public/js/frappe/widgets/chart_widget.js +++ b/frappe/public/js/frappe/widgets/chart_widget.js @@ -457,7 +457,8 @@ export default class ChartWidget extends Widget { Line: "line", Bar: "bar", Percentage: "percentage", - Pie: "pie" + Pie: "pie", + Donut: "donut" }; let colors = []; @@ -490,6 +491,14 @@ export default class ChartWidget extends Widget { shortenYAxisNumbers: 1 } }; + + if (this.chart_doc.custom_options) { + let custom_options = JSON.parse(this.chart_doc.custom_options); + for (let key in custom_options) { + chart_args[key] = custom_options[key]; + } + } + if (!this.dashboard_chart) { this.dashboard_chart = new frappe.Chart( this.chart_wrapper[0],