Power Chart - Showing transformed value in x-trace instead of integer value?

it would be possible with js injection, but seems like a lot of work for what a legend could solve

edit...
... and ofc i do a lot of work :stuck_out_tongue:

it works... but i'm a bit worried about client performance on big charts, so test it out! And let us know if its doable.
the onhover event didnt trigger enough to match the chart, so im doing a mutationobserver on it, but that kinda triggers to much...

give your chart a domid
and setup your value mapping
this binding goes into the markdown ofc with escaped html

def transform(self, value, quality, timestamp):
	#make the value the key to write too.
	chartDomId = "PowerTableId"
	mappingStatus = "{0:'stopped',1:'started'}"
	code =  "<img style='display:none' src='/favicon.ico' onload=\"const mappingStatus="+mappingStatus+"; const chart = document.getElementById('"+chartDomId+"'); const callback = (mutationList, observer) => {let textLabels = document.querySelectorAll('#"+chartDomId+" .ia_powerChartComponent__labelText.ia_powerChartComponent__xTrace__box__label > tspan'); textLabels.forEach(textLabel => {if(textLabel.textContent in mappingStatus){textLabel.textContent = mappingStatus[textLabel.textContent]; }})}; const observer = new MutationObserver(callback); observer.observe(chart, { attributes: false, childList: true, subtree: true })\"></img>"
	return code

dont forget to change the size of the trace box to match increased text lengths
image

5 Likes