Vega-Lite: More Complex Sort Functions - vega-lite

https://vega.github.io/vega-lite/docs/sort.html
Is there a way to pass in a more complex sort to a vega lite chart? For example could I pass something like a javascript function in to work as a comparator?

As far as I know, it's not possible to directly pass in a custom sort function directly.
However, you could calculate a custom field using the calculate transformation to create a new field with the expression language (which is a subset of Javascript) , then use that field to perform your sort.
If you have a custom javascript function that you'd like to call from inside the expression language, you can register it using the Vega extension API, and then use it in your calculate transform.

Related

Is there any way to get a function pointer from a &str type in rust which is provided by the use

Is there any way to get a function pointer from a &str type in rust which is provided by the use.
Example: use provides a name of a function provided by the user i need some way to call the function preferably a closure or a function pointer
Rust is a static, compiled language. There is no access to functions by name at runtime. The functions may not even exist (they may be inlined, for example, or optimized away). Instead, what you need to do is create a HashMap of Strings to functions you would like to call at runtime, or use a match to dispatch by string.

Pass parameters to a vega-lite spec?

I'm looking for an idiomatic way to pass parameters into a vega-lite spec via vegaEmbed(). For example, I'd like to pass the data url, so that instead of my spec containing:
"data": {"url": "filename.json"},
it contained something like:
"data": {"url": parameters["dataURL"]},
At a high level, I want to display visualizations from external applications via a url, something like http://localhost/showViz.html?data=today.json&sort=ascending so it's not just about specifying the data source, I'm looking for a general mechanism to parameterize my specs.
I tried passing something via vegaEmbed's opt argument, but couldn't work-out how to access it from the vega-lite spec (either as usermeta or not). If the opt argument is the preferred way to do something like this, then my question devolves to "how do I reference opt and/or usermeta values from a vega-lite spec?".
No, there is no standard means to parametrize inputs that is built-in to Vega or Vega-Lite.
There are third-party tools that do something similar to what you have in mind, for example Vega Kibana, which provides a templating syntax for charts.
If you want to do this using native Vega/Vega-Lite, you can always use Javascript to modify the specification before passing it to the renderer, and/or use the vega-embed patch option to provide a javascript function that will patch the Vega specification (not Vega-Lite specification) before it is rendered.

How to make Simple-JSON variable template query in grafana?

I am trying to create a dynamic variable for a graph using a kdb+ database, which requires the Simple-JSON plug in. However, I am struggling to figure out how to write the query in the Query search bar under Variables on my Dashboard.
I have looked into the documentation found here but there is only a few mentions of the templating feature for variables in grafana, but nothing on how to do it.
https://github.com/grafana/simple-json-datasource/blob/master/README.md
You can write arbitrary text in the timeserie query, it doesn't need to be one of the hardcoded metrics that /search returns.
There is also the simpod json datasource plugin.
https://grafana.com/grafana/plugins/simpod-json-datasource
built on top of the Simple JSON Datasource. It has refactored code, additional features and active development.
One of the "additional features" is an "Additional JSON Data" tab where you can use variables. {"key": $variableValue}
It actually turns out that the adaptor for kdb+/grafana needs it's search function overloaded to be able to accept variables and return a string (or something that grafana can understand).

Need documentation on method setDataTable(table), Charts service

When using Charts service in GAS, you can create different type of charts and most of them have two methods setDataTable(...) to push data in:
method setDataTable(tableBuilder)
method setDataTable(table)
For the first one you create a DataTableBuilder object using Charts.newDataTable().
But the second one is not documented enough for me.
Does anyone know the specification of the object table to transmit to the function ?
It seems to me it can be an array or a map, but I had no success in using it.
Thanks,
The second method takes in a DataTable, which is just the result of calling DataTableBuilder.build(). Unfortunately it's not possible to construct a pure JavaScript object that it will accept, and you'll need to use the DataTableBuilder.

How to I pass Vector.<> from Flash with ExternalInterface

I have a custom container (C#) for the Flash ActiveX control and am passing data back and forth. Previously I would use ExternalInterface.call and pass an Array as a parameter. I would prefer to use the Vector class now that it is available, but it appears that when I do that the call is never made.
It is however made if it is embedded in IE. It appears that when in IE, Flash will send out JavaScript to execute rather than serializing to XML. My guess is that the Vector XML serialization isn't baked in, so Flash just ignores the call.
Anyone have any ideas? Other than just going back to using Array, I've already done that for now.
The docs note that:
Other built-in or custom classes -
ActionScript encodes other objects as
null or as an empty object. In either
case any property values are lost.
It's not completely clear what that means, since custom classes are also Objects - I guess only vanilla objects count? But at any rate it looks like Vector falls into that "other built-in classes" category, so you'll need to either use Array, or re-cast to Array before you pass the data.
you can use arrays with [ArrayElementType("type")] instead. or write a serialization function for Vector