kiln / flourish-sdk

The SDK for developing Flourish templates
Other
80 stars 16 forks source link

CSV column parsers #27

Open moonthug opened 6 years ago

moonthug commented 6 years ago

At the moment all CSV data is added to the main data object as a string. The means that you either have to convert them all to ints, floats etc up front or later when you need to use them.

It would be great if you could specify a column or column range formatter.

Straight forward parseInt-ing.

  - dataset: growthBoundsColorMap
    key: from
    name: From
    type: column
    column: lookup_growth_bounds_color::A
    parser: parseInt

Custom functions that can be specified in the template.

  - dataset: growthBoundsColorMap
    key: to
    name: To
    type: column
    column: lookup_growth_bounds_color::B
    parser: divideByTwo

Chaining parsers together with arguments

  - dataset: growthBoundsColorMap
    key: color
    name: Color
    type: column
    column: lookup_growth_bounds_color::C
    parser:
      - hexToHSL
      - shiftHue
        - 10
      - darken
theduncanclark commented 6 years ago

Thanks! We have a plan to support column types (numbers, dates, strings, lat-lngs, etc) so this fits nicely with that. We hadn't thought about custom parsers but it's a cool idea so we'll definitely give it some thought. Thanks again :-)

moonthug commented 6 years ago

I think some of the custom 'parser's I mentioned are probably better considered 'formatter's that would happen after the initial parser function. So maybe another property on the config.

Anyway, great!