How to style indicator object ?
I am trying to styles to indicator object. I am following this documentation https://developers.sisense.com/display/API2/JavaScript+API+Reference#JavaScriptAPIReference-IndicatorObjectindicator and the javascript file in plugin contains the following code -> https://ideone.com/U1MwuC .
'initialized' event is not getting fired at all. Can you please show me the right way to style indicator object ? I am stuck here.
-
I'm no expert but I think you might be trying to register the event listener on the wrong type of object. The value of `widget` in the JavaScript API documentation you referenced is an instance of Sisense's JavaScript Widget class. In the code snippet you posted, your `widget`
var widget = $('.indicator_section span','widget[type=indicator]');
is a JQuery Wrapped Set object.
I'm not sure about how you're working with the Sisense JavaScript objects, but using Sisense.js to load a dashboard you _can_ do something like the following pseudo code:
...
Sisense.connect(sisenseInstanceUrl).then((app)=> {
app.dashboards.load(dashboardOid).then((dashboard) => {
let widget = dashboard.widgets.get(indicatorWidgetId);
widget.on("initialized", () => { /* Apply the indicator widget styles here */ });
});
}); -
Hi Anunay,
I believe Aaron is correct - it seems in your code you're getting the indicator widget's DOM element and then trying to register to the "initialized" event on it - but it doesn't have one, so all of the following code isn't really executed.
You need to use the actual "widget" instance, which you can get in one of the following ways:
Passing in the "widget" object from a widget script
Each widget in Sisense (and each dashboard, too) can have a unique Javascript script associated with it, accessible through the widget's menu "edit script" option.
Within said script, you have an injected object called "widget" which represents the current widget instance. You can pass this object to your plugin - For example:
// Plugin code:
prism.plugins = prism.plugins || {}; // I ensure there's a nice namespace for me to use in the prism global object
prism.plugins.styleIndicator = function (widgetInstance) {
widgetInstance.on('initialized', function() { /* do stuff */ });
};
// Widget script code:
prism.plugins.styleIndicator(widget);Using this method, you can "turn on" your plugin's logic for specific widgets. You can also take it a step further and have your plugin create a new menu item for each Indicator widget to turn the feature on and off, but I won't go into that because I believe in your case you do wish to automatically apply this logic to all indicator widgets.
BTW you could also do this on the dashboard level (using a combination of this method and the one below) to turn the feature on for all indicators of specific dashboards.
Getting the widget instance from a dashboard global event
You can subscribe to a global dashboard event, that is fired any time that any dashboard is loaded, using:
prism.on('dashboardloaded', function() { /* do stuff */ });
This event handler will receive the dashboard object as an argument, and that object will contain an array of widget objects which you can filter by type to get the indicators, and then apply any changes or subscribe to their events.
I hope one of these methods works for your needs and you can resolve this issue!
Please sign in to leave a comment.
Comments
2 comments