Declarative mapping
As described in the chart interface page each chart implementation must define a
mapData
function that prepares the dataset for the rendering.
Each chart might need a different shape of data, but it's possible to identify some common patterns for transforming data.
For this purpose, we're introducing a "declarative mapping" approach, in which the rawgraphs chart interface can implement the mapData
as a plain object describing the "role" of each dimension in the data transformation.
caution
This API is still under definition and might change in the future versions.
#
Simple column pickingThis form of declarative mapping implements the operation of "translating" column names from the user dataset to the dimensions described in the charts.
Let's suppose we have a dataset like:
and a chart exposing two dimensions:
If we just want to "reduce" the dataset to a list of x
and y
based on column mappings,
the mapData
function could be written like
Using the declarative mapping, we can just write:
Which tells RAWGraphs to just pick the two columns mapped on x and y dimensions. Note that this implementation would also work for multi-valued dimensions, while the function shown above would not work in this case.
info
You can see an example of this kind of mapping in the core bubble chart used in the RAWGraphs app.