/* * Workaround for the bug with custom colors sorting in choropleth on the production environment * * 2017-05-15 Marcin KarpiĆski <marcin.karpinski@hexagongeospatial.com> */// Code snippet to make all choropleths with custom colors use alpabetical domain sort orderfunctioncastColors(dataStage,chartM){varinlinedColors=chartM.colors,domain;if(!inlinedColors||inlinedColors.length<=0)return;domain=this.getAlphabeticallySortedDomainValues(dataStage.facts(),chartM.values);this.colors(d3.scale.ordinal().range(inlinedColors).domain(domain));}functiongetDomainValues(values,key){this.data();returnvalues.dimension(function(d){returnd[key];}).group().all().map(function(d){returnd.key;}).sort();}functionfixColors(){// Wait for the map to be readyif(!document.querySelector(".leaflet-zoom-animated")){setTimeout(fixColors,500);}else{// Find all choroplets$GP.bi.stage.findWidgets({descriptors:[{chartM:{chart:"choropleth"}}]},function(widgets){varl=widgets.length;while(l--){varwidget=widgets[l];if(!Array.isArray(widget.chartM.colors))return;// Alphabetical domain order for all choropleths with custom colors.widget.chart.castColors=castColors;widget.chart.getAlphabeticallySortedDomainValues=getDomainValues;widget.chart.castColors(widget.chart.dataStage(),widget.chartM);widget.chart.redraw();}});}}fixColors();
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.