Suffix for text output

Is it naive of me to think that one might allow the use of a JSONata specification inside the ui-text node as a method of doing all of this without additional nodes?

But just don't forget about the performance of the JSONata ...,

Quite possibly - although I really don't like the readability of JSONata - I find it very unintuitive.

Point acknowledged on the toFixed though - any thoughts @Steve-Mcl?

Still trying to think how we could safely re-introduce the value format field, and without hacks left-right and center as in D1.0

1 Like

100%! A man after my own heart!

This is not something that Mustache supports - but (IIRC) a hack workaround. In fact, I am pretty sure @dceejay has mentioned this recently.

One solution would be the use of filters (like the angular filters). There is such a concept for vue (example) but I remember reading recently they were dropped from Vue 3.

Vue has written the recommended approach now is to use computed however this does not help in cases like this where you are not coding but there is a 2nd alternative suggestion "globalProperties" in that link that might be useful (assuming the D1 mustache-ish syntax support is added to D2).

In short, it would mean we may be able to offer support for things like {{ $filters.formatNumber(payload, { fixed: 2, suffix: ' °C' }) }}

The thing is, it isn't really low-code nor is it JavaScript. Its not even JSONata, its another awkward workaround. Don't get me wrong I want a better way of formatting values but I am not certain the original D1 way was the best and so mimicking it in d2 may be worse current solution.


outlandish ideas:

# 1

How about a dashboard config section that accepts JS code where a user can add to a list of "filters". This set of filters would then be presented on the node and the user selects the appropriate filter for the data. Of course there would be a default set like "2 decimal places", "uppercase", "title case" etc but users could then generate their own "divide by 100 and suffix with ' volts'" filter.

# 2

How about (forgive me) permitting the option of msg. and JSONata for the fields that require formatting? Easier to implement BUT harder for users (and a chain around the necks of D2 devs for ever more)

# 3

Something else?

I am not sure there is much difference between it and JS nowadays. I have just tested running 1,000,000 times a function node containing

msg.payload = `${msg.payload.toFixed(2)} C`
return msg

and a Change node containing Set msg.payload to JSONata
$formatNumber(payload, "#0.00;(#0.00)") & " C"
and they both took 22 seconds on an i5 processor. That is 22 microseconds each, which is trivial. In fact I find that difficult to believe so if someone would like to check that would be interesting. I won't publish the flow as there is no point using that in case there is an error there.

Same here, but for simple stuff like this it is not that bad, and the current alternative of JS also gives beginners problems.

Not really any performance hit on formatnumber() as it is not mapping a large array.

I feel this is not a good reason to exclude an idea, your personnel preference sould be the last consideration.

Sometimes it's necessary to pass the payload fully formatted, for example the same field might sometimes show 4.9 mi/kWh, 49 MPG or 5.76 L/100km

Maybe we need a new node type which accepts payload & format (sprintf syntax springs to mind) and emits the formatted string?

Then no need to handle any of this in the dashboard widgets, and Jsonata speakers can use the change node.

You're absolutely right, though my job is to make Dashboard easy to use and as intuitive as possible.

What everyone is asking for here should be easy, I'm just not sure that JSONata is that answer as it doesn’t cover things like toFixed

1 Like

I refer you to

Just to note that this was for 1,000,000 operations.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.