Snippets

Piotr Szrajber Smart M.App - synchronize row chart's colors with map colors

Created by Piotr Szrajber last modified
/*
* By default the row chart uses "keyAccessor" as its "colorAccessor", so that next bar's color is the next color from the palette.
* This code snippet changes row chart's coloring mode to make it the same as map widget's coloring, where bars are colored
* according to their value.
* 2017-02-06 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
*/

//gsp.ready(function(gsp) { /* uncomment for pasting in browser's javascript console */
    getWidgets(changeColors);

    function getWidgets(callback) {
        /* find the first choropleth and the first row chart - modify this function according to your needs... */
        gsp.bi.stage.findWidgets({
            descriptors: [{
                chartM: {
                    chart: "choropleth"
                }
            }, {
                chartM: {
                    chart: "row"
                }
            }]
        }, function(widgets) {
            if (widgets && widgets[0] && widgets[0][0] && widgets[1] && widgets[1][0])
                callback(widgets);
            else
                setTimeout(getWidgets, 300);
        });

    }

    function changeColors(widgets) {
        var choropleth = widgets[0][0],
            rowChart = widgets[1][0];

        var mapColors = choropleth.chart.colors();
        rowChart.chart.colors(mapColors);
        rowChart.chart.colorAccessor(rowChart.chart.valueAccessor());
        rowChart.chart.redraw();
    }

//}) /* uncomment for pasting in browser's javascript console */

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.