Commit 134a32344eda0fec00530abf48e9ce50772a1ab0
Committed by
Igor Kulikov
1 parent
1ebb669c
Add two separate options to enable labels and/or percentages in 'flot-pie' widget (#1882)
Showing
2 changed files
with
14 additions
and
4 deletions
@@ -74,7 +74,7 @@ | @@ -74,7 +74,7 @@ | ||
74 | "controllerScript": "self.onInit = function() {\n self.ctx.flot = new TbFlot(self.ctx, 'pie'); \n}\n\nself.onDataUpdated = function() {\n self.ctx.flot.update();\n}\n\nself.onResize = function() {\n self.ctx.flot.resize();\n}\n\nself.onEditModeChanged = function() {\n self.ctx.flot.checkMouseEvents();\n}\n\nself.onMobileModeChanged = function() {\n self.ctx.flot.checkMouseEvents();\n}\n\nself.getSettingsSchema = function() {\n return TbFlot.pieSettingsSchema;\n}\n\nself.getDataKeySettingsSchema = function() {\n return TbFlot.pieDatakeySettingsSchema;\n}\n\nself.onDestroy = function() {\n self.ctx.flot.destroy();\n}\n", | 74 | "controllerScript": "self.onInit = function() {\n self.ctx.flot = new TbFlot(self.ctx, 'pie'); \n}\n\nself.onDataUpdated = function() {\n self.ctx.flot.update();\n}\n\nself.onResize = function() {\n self.ctx.flot.resize();\n}\n\nself.onEditModeChanged = function() {\n self.ctx.flot.checkMouseEvents();\n}\n\nself.onMobileModeChanged = function() {\n self.ctx.flot.checkMouseEvents();\n}\n\nself.getSettingsSchema = function() {\n return TbFlot.pieSettingsSchema;\n}\n\nself.getDataKeySettingsSchema = function() {\n return TbFlot.pieDatakeySettingsSchema;\n}\n\nself.onDestroy = function() {\n self.ctx.flot.destroy();\n}\n", |
75 | "settingsSchema": "{}\n", | 75 | "settingsSchema": "{}\n", |
76 | "dataKeySettingsSchema": "{}\n", | 76 | "dataKeySettingsSchema": "{}\n", |
77 | - "defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"function\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"First\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.15479322438769105,\"funcBody\":\"var value = (prevValue-50) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+50;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Second\",\"color\":\"#4caf50\",\"settings\":{},\"_hash\":0.6114638304362894,\"funcBody\":\"var value = (prevValue-20) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+20;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Third\",\"color\":\"#f44336\",\"settings\":{},\"_hash\":0.9955906536344441,\"funcBody\":\"var value = (prevValue-40) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+40;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Fourth\",\"color\":\"#ffc107\",\"settings\":{},\"_hash\":0.9430835931647599,\"funcBody\":\"var value = (prevValue-50) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+50;\"}]}],\"timewindow\":{\"realtime\":{\"timewindowMs\":60000}},\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"radius\":1,\"fontColor\":\"#545454\",\"fontSize\":10,\"decimals\":1,\"legend\":{\"show\":true,\"position\":\"nw\",\"labelBoxBorderColor\":\"#CCCCCC\",\"backgroundColor\":\"#F0F0F0\",\"backgroundOpacity\":0.85},\"innerRadius\":0,\"showLabels\":true,\"stroke\":{\"width\":5},\"tilt\":1,\"animatedPie\":false},\"title\":\"Pie - Flot\",\"dropShadow\":true,\"enableFullscreen\":true,\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400}}" | 77 | + "defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"function\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"First\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.15479322438769105,\"funcBody\":\"var value = (prevValue-50) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+50;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Second\",\"color\":\"#4caf50\",\"settings\":{},\"_hash\":0.6114638304362894,\"funcBody\":\"var value = (prevValue-20) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+20;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Third\",\"color\":\"#f44336\",\"settings\":{},\"_hash\":0.9955906536344441,\"funcBody\":\"var value = (prevValue-40) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+40;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Fourth\",\"color\":\"#ffc107\",\"settings\":{},\"_hash\":0.9430835931647599,\"funcBody\":\"var value = (prevValue-50) + Math.random() * 2 - 1;\\nif (value < 0) {\\n\\tvalue = 0;\\n} else if (value > 100) {\\n\\tvalue = 100;\\n}\\nreturn value+50;\"}]}],\"timewindow\":{\"realtime\":{\"timewindowMs\":60000}},\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"radius\":1,\"fontColor\":\"#545454\",\"fontSize\":10,\"decimals\":1,\"legend\":{\"show\":true,\"position\":\"nw\",\"labelBoxBorderColor\":\"#CCCCCC\",\"backgroundColor\":\"#F0F0F0\",\"backgroundOpacity\":0.85},\"innerRadius\":0,\"showLabels\":true,\"showPercentages\":true,\"stroke\":{\"width\":5},\"tilt\":1,\"animatedPie\":false},\"title\":\"Pie - Flot\",\"dropShadow\":true,\"enableFullscreen\":true,\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400}}" |
78 | } | 78 | } |
79 | }, | 79 | }, |
80 | { | 80 | { |
@@ -170,4 +170,4 @@ | @@ -170,4 +170,4 @@ | ||
170 | } | 170 | } |
171 | } | 171 | } |
172 | ] | 172 | ] |
173 | -} | ||
173 | +} |
@@ -350,7 +350,7 @@ export default class TbFlot { | @@ -350,7 +350,7 @@ export default class TbFlot { | ||
350 | pie: { | 350 | pie: { |
351 | show: true, | 351 | show: true, |
352 | label: { | 352 | label: { |
353 | - show: settings.showLabels === true | 353 | + show: settings.showLabels || settings.showPercentages |
354 | }, | 354 | }, |
355 | radius: settings.radius || 1, | 355 | radius: settings.radius || 1, |
356 | innerRadius: settings.innerRadius || 0, | 356 | innerRadius: settings.innerRadius || 0, |
@@ -373,7 +373,11 @@ export default class TbFlot { | @@ -373,7 +373,11 @@ export default class TbFlot { | ||
373 | 373 | ||
374 | if (options.series.pie.label.show) { | 374 | if (options.series.pie.label.show) { |
375 | options.series.pie.label.formatter = function (label, series) { | 375 | options.series.pie.label.formatter = function (label, series) { |
376 | - return "<div class='pie-label'>" + series.dataKey.label + "<br/>" + Math.round(series.percent) + "%</div>"; | 376 | + return "<div class='pie-label'>" + |
377 | + (settings.showLabels ? series.dataKey.label : "") + | ||
378 | + (settings.showLabels && settings.showPercentages ? "<br/>" : "") + | ||
379 | + (settings.showPercentages ? Math.round(series.percent) + "%" : "") + | ||
380 | + "</div>"; | ||
377 | } | 381 | } |
378 | options.series.pie.label.radius = 3/4; | 382 | options.series.pie.label.radius = 3/4; |
379 | options.series.pie.label.background = { | 383 | options.series.pie.label.background = { |
@@ -791,6 +795,11 @@ export default class TbFlot { | @@ -791,6 +795,11 @@ export default class TbFlot { | ||
791 | "type": "boolean", | 795 | "type": "boolean", |
792 | "default": false | 796 | "default": false |
793 | }, | 797 | }, |
798 | + "showPercentages": { | ||
799 | + "title": "Show percentages", | ||
800 | + "type": "boolean", | ||
801 | + "default": false | ||
802 | + }, | ||
794 | "fontColor": { | 803 | "fontColor": { |
795 | "title": "Font color", | 804 | "title": "Font color", |
796 | "type": "string", | 805 | "type": "string", |
@@ -820,6 +829,7 @@ export default class TbFlot { | @@ -820,6 +829,7 @@ export default class TbFlot { | ||
820 | ] | 829 | ] |
821 | }, | 830 | }, |
822 | "showLabels", | 831 | "showLabels", |
832 | + "showPercentages", | ||
823 | { | 833 | { |
824 | "key": "fontColor", | 834 | "key": "fontColor", |
825 | "type": "color" | 835 | "type": "color" |