eurostat / gridviz

A package for visualizing gridded data 🌐
https://github.com/eurostat/gridviz
European Union Public License 1.2
199 stars 10 forks source link

Migrating LegoStyle tFun to V3 #142

Open joewdavies opened 1 week ago

joewdavies commented 1 week ago

How would I migrate Lego Style tFun to V3? the only example i could find uses thresholds:

    // get dataset if havent already
    if (!layer.dataset) getDataset(layer)

    //define style
    const styles = LegoStyle.get((cell) => cell[DATAFIELD], [100, 200, 500, 1000, 2000], ['#ffffd4', '#fee391', '#fec44f', '#fe9929', '#d95f0e', '#993404'])

    //define layer
    const gridLayer = new GridLayer(layer.dataset, styles, { minPixelsPerCell: 5, cellInfoHTML: TOOLTIPFUNCTION })

    //add layer to map
    gridvizMap.layers = [gridLayer]

    // redraw gridviz
    gridvizMap.redraw()

but the previous code did this:

    app.addLayerFromDataset(
        layer.dataset,
        LegoStyle.get(DATAFIELD, {
            tFun: (v, r, s, zf) => (v == 0 ? 0 : sExpRev((v - s.min) / (s.max - s.min), -7)),
            //colors: d3.schemeRdYlGn[10].reverse()
        }),
        {
            pixNb: 7,
            cellInfoHTML: TOOLTIPFUNCTION,
        }
    )