Plugin - Custom Coloring of Bar and Column Chart Type Widgets (barChartCustomColor)
Summary: Jeremy Friedel, Jeremy Friedel, introduces a plugin named barChartCustomColor, designed to modify the color scheme of bar and column chart-type widgets in Sisense dashboards. This plugin aligns chart colors with the dashboard's color palette for consistent styling. Installation requires placing the plugin in the Sisense plugins folder and enabling it through the Admin section. By setting widget scripts to changeColor, users can apply the color scheme to individual widgets or the entire dashboard. The plugin employs the processresult widget event to adjust colors and supports a customizable color dictionary for overriding default color settings. Jeremy invites users to share feedback and suggest other types of plugins they are interested in.
This can be modified with custom logic as needed, for example, based on widget title or ordering in the dashboard. If this option is enabled for a type of widget this plugin does not apply to, it will simply be ignored by the plugin. This plugin ignores widgets with Break By's or Date Categories, or widgets that are not bar or column chart-type widgets.
The color scheme is based on the current dashboard palette.
Changing the dashboard palette using the standard Sisense palette UI will result in a matching change of all widgets in the dashboard where this plugin is enabled.
The config file of this plugin includes an option called colorDictionary, this can be used to override the standard palette color for all instances this value appears as the bar category, for all widgets this plugin is enabled for, regardless of the dashboard palette. Any standard HTML color naming format may be used in the dictionary config value.
For example, if the colorDictionary is set to:
Then the ABC bar or column will be yellow in the widget, regardless of the current widget palette or positioning. This will apply to all widgets where this plugin is active.
Jeremy Friedel
OP5 months agoThe main.js file of the plugin:
// Change Coloring of Bar Chart and Column Charts // For charts without Break By's and which have widget.changeColor set to true via script. import { config } from './config.6'; if (window.prism) { prismObject = window.prism; } // If v1 Sisense.js, use internal scope prism else { prismObject = window.Sisense.internalScope.prism; } prismObject.run([ () => { prismObject.on('dashboardloaded', customColors); function customColors(_, { dashboard }) { dashboard.on('widgetprocessresult', function (_, dashboardWidgetObj) { localColorDictionary = config.colorDictionary; var palette = dashboard.style.getPalette().colors; function getColor(cat) { return localColorDictionary[cat]; } function checkDictionary(curCategory, ord) { var curColor = getColor(curCategory); if (curColor == null) { localColorDictionary[curCategory] = palette[ord % palette.length]; } } // Make color change of charts without Break By function chartColorChange() { if (!dashboardWidgetObj.result.series.length) { return; } var initialLength = dashboardWidgetObj.result.series[0].data.length; for (let i = 0; i < initialLength; i++) { if (dashboardWidgetObj.result.series[0].data[i].selectionData && dashboardWidgetObj.result.series[0].data[i].selectionData[0]) { var curCategory = dashboardWidgetObj.result.series[0].data[i].selectionData[0]; checkDictionary(curCategory, i); dashboardWidgetObj.result.series[0].data[i].color = getColor(curCategory); } } } // Whether Break By is used and active function panelActive(panels, targetPanel) { var breaks = panels.filter(function (entry) { if (entry.title == targetPanel) { return entry; } }); if (breaks[0].items.length == 0) { return false; } else { return true; } } // Whether Category Panel is of Date type function isNotDateXAxis(panels) { return (panels[0].items && panels[0].items.length > 0 && panels[0].items[0].jaql && panels[0].items[0].jaql.datatype && panels[0].items[0].jaql.datatype != "datetime"); } // Modify to remove or change widget types or add additonal conditions if ((dashboardWidgetObj.widget.manifest.name == "chart/column" || dashboardWidgetObj.widget.manifest.name == "chart/bar") && dashboardWidgetObj.widget.changeColor && !panelActive(dashboardWidgetObj.widget.metadata.panels, "break by") && isNotDateXAxis(dashboardWidgetObj.widget.metadata.panels) ) { chartColorChange(); } }); } } ]);