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

In Vision we can transform the x-trace values, for example, translate an enum integer value into its corresponding text value (0 -> 'Stopped', 1 -> 'Starting', etc.)

Can we do this in Perspective? I'm guessing not at the moment... but if not, how feasible would this be to add?

0-8 means nothing to my operators :frowning: I need to show the descriptive values

1 Like

Hi nminchin,

Currently I don't think there is a way to do this in Perspective. I think it is a good idea to submit a feature request here.

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

1 Like