Custom Widget Script Styling Not Coming Through on sdk-ui Chart Component
I have a widget where I have edited the script to apply custom formatting (changing the “time” from being displayed in seconds => to minutes & seconds). However, when I display this widget in my React project with the <LineChart {...widget.getChartProps()}/> component from sdk-ui, the custom formatting is not showing up. Is there something special I need to do here to be able to see this custom script styling in the sdk-ui component? I’m not finding any community posts describing this problem or a solution.
ewoytowitz
Posted 2 years ago·Last reply 1 year ago
11 comments
DRay
·1 year agoHi haydenwitt. Do you still need help with this? If so I can reach out internally, or we have our live Office Hours in the Sisense Discord tomorrow at 1pm Central if you can stop in then and ask your question.
haydenwitt
·1 year agoI was able to get it to kind of work, but it's showing two tooltips now:
widget.on("beforeviewloaded", function(w, args) {
function convertRawTime(num) {
if (!num && num !== 0) return '0:00';
var sign = num < 0 ? '-' : '';
var hours = (parseInt(Math.abs(num) / 3600) % 24);
var minutes = parseInt(Math.abs(num) / 60) % 60;
var seconds = parseInt(Math.abs(num) % 60);
var minutesText = minutes < 10 ? "0" + minutes : minutes;
var secondsText = seconds < 10 ? "0" + seconds : seconds;
return sign + minutesText + ":" + secondsText;
}
// Format data labels
args.options.plotOptions.series.dataLabels.formatter = function() {
return convertRawTime(this.y);
}
// Format y-axis labels
args.options.yAxis[0].labels.formatter = function() {
return convertRawTime(this.value);
}
// Reset any existing tooltip settings
args.options.tooltip = null;
// Set new tooltip configuration
args.options.tooltip = {
enabled: true,
followPointer: false,
followTouchMove: false,
hideDelay: 0,
formatter: function() {
let total = this.total || this.y;
let percentage = ((this.y / total) * 100).toFixed(1);
let s = '<div style="min-width: 100px; color: rgb(91, 99, 114); font-size: 13px; line-height: 18px; margin: 4px 6px;">';
s += this.x + '<br/>';
s += '<hr class="csdk-border-t" style="margin: 7px 0px;">';
s += this.series.name + ': ' +
`<span style="color:${this.color}">` +
convertRawTime(this.y) +
` (${percentage}%)</span>`;
s += '</div>';
return s;
},
shared: false,
useHTML: true,
outside: false,
style: {
pointerEvents: 'none'
}
};
// Disable any chart-wide tooltip settings
if (args.options.plotOptions && args.options.plotOptions.series) {
args.options.plotOptions.series.tooltip = {
enabled: false
};
}
});
haydenwitt
·1 year agoAny tips on getting this to work for stacked bar charts?
ewoytowitz
OP2 years agoLooks great! The tooltip now matches the standard styling and has the formatting. Thank you Steve!
steve
·2 years agoHi ewoytowitz
Thanks for the great question!
The existing widget scripts will not affect Compose SDK behaviour, as scripts are executed in the Sisense Fusion application when the various lifecycle events happen.
The approach for Compose SDK is to allow you to apply customizations in your app code, instead of within widget scripts.
Here's an example of modifying an existing widget grouped by some date column, and changing both the aggregation granularity to minutes and also the display format.
I see that we might be missing the 'seconds' level of granularity in the DateLevels so we'll take a look into this.
I hope this helps, feel free to reply with more questions!
Thanks
Steve
ewoytowitz
OP2 years agoHi Steve, thank you for the information. I've got the return set up from your CodeExample in my code. The data that I am trying to change the format of is on the y-axis, and the existing values are 'calculatedmeasure' (instead of 'datelevel'). Below is what I've come up with so far to work with my data, but I'm not sure how to apply my desired formatting to the 'newVal'? Do you know how I could go about that? Also, I really need to include milliseconds in the desired formatting, so I'm looking to apply a format of HH:mm:ss.00 to the existing ss.00 format. Including a screenshot of what the chart looks like now, without the desired formatting, for context.
steve
·2 years agoewoytowitz thanks for the additional info
FYI i modified my post since you took influence from it, having some feedback from one of our team to simplify it a bit.
Ok now I understand your script is not about modifying the query itself, but modifying the format afterwards for presentation? e.g. dividing seconds by 60 to get minutes or something like this. Could you share a snippet of your widget script so we can understand the logic?
Steve
ewoytowitz
OP2 years agosteve
·2 years agoHi ewoytowitz
Alright, thanks for providing the example. Here is a Compose SDK version of the same, using `onBeforeRender` prop.
Hope it helps!
Steve
ewoytowitz
OP2 years agoAmazing! Thank you. That worked! Is there a way to apply the same formatting to the value in the "pop-up" that appears when you hover over the data point? The pop-up is showing the unformatted value (see attached image), and I'd like it to show up as the formatted time if possible.
steve
·2 years agoHi ewoytowitz
You can customise the tooltip using the same convertRawTime function, however by modifying the tooltip formatter function, you lose the Sisense style tooltips and will revert to highcharts default tooltips.
To avoid losing that style, I manually recreated the same tooltip structure that Sisense generates, but added the customRawTime function in there too, so this should solve your question.
You can add this to the onBeforeRender handler right before the return options; line
Please note some other types / configurations of charts might have different tooltip contents (e.g .stacked charts) so this function would need adapting in those cases.
Thanks
Steve