Acknowledgment: This tutorial is based on Vega's documentation.
The very essence of a plot is the data behind it, and thus the information it is trying to convey. In this tutorial, I'm going to talk about how to get the data into Plotrb.
A Data class does not have many attributes (and it's not supposed to). The goal is to let you import the data as effortlessly as possible.
The name of the data set must be unique, so that you may reference it at other places of Plotrb.
Use an existing data set as source of the new data set.
You can pass in the name of the other data.
You can also pass in other data object directly.
some_data = Plotrb::Data.new.name('some_data') new_data = Plotrb::Data.new.name('new_data').source(some_data)
The actual data can come from a url, for example a json file from some web service.
url, the data may also come from a local file, for example a csv file in another directory.
The data do not necessarily have to come from external sources. Instead of referencing the data source, you can also pass in the actual data values directly to Plotrb.
Currently, Plotrb supports several value types. You can pass in the values as an array.
You can also pass in a hash.
data.values(foo: 1, bar: 2, baz: 3)
Or you can pass in JSON as string directly.
Specify the transforms to be performed on the data.
As of now, Plotrb supports five types of data formats, namely
To assign specific attribtues for a format, you have to define the format first.
You can also use the following grammar.
(Manipulating attributes for a format must be done inside a block, as you will see in the following examples.)
parsedefines the data type for each field of the data set. Valid data types are
data.as_csv do parse 'foo' => :number, 'bar' => :date end
Meanwhile, you can always do the following,
data.as_csv do as_number 'foo' as_date 'bar' end
data.as_csv do number 'foo', 'bar' date 'baz' end
Set the JSON property containing the desired data.
Specify the name of the TopoJSON object to convert to a GeoJSON feature collection.
Specify the name of the TopoJSON object to convert to a mesh.
Set the JSON property that contains an array of children nodes for each intermediate node.
comments powered by Disqus