G1.mapviewer does not support Ordinal scales correctly
domain
gets calculated from
MapViewer.prototype._calculateMinMax = function (layer, metricFormula) {
var minVal, maxVal
layer.eachLayer(function (sublayer) {
var metricVal = metricFormula(sublayer.feature.properties)
if (!metricVal) return
if (!(maxVal && minVal)) maxVal = metricVal, minVal = metricVal
if (metricVal < minVal) {
minVal = metricVal
}
if (metricVal > maxVal) {
maxVal = metricVal
}
})
return [minVal, maxVal]
}
This would return [undefined, undefined]
incase the metric
provided in the mapviewer options is Qualitative data.
Implications:
Even if domain
is provided as array of unique categoricals and range
as array of colors, the first color in range are already mapped to undefined
value in domain. So, the domain mapping gets shifted by one place.
Possible Solutions:
Create a domain calculator module in G1, that can take a accessor
as parameter. Such that the input can be array of objects (collections), or an array itself. In mapviewer case, the input is an array of sublayer.feature.properties
.
This g1.domain
will be reused in g1.scales
module.
Note for Tejesh:
For discrete type scales (ordinal/band/point), if domain
option is not provided and metric
(Tejesh to make this as mandatory option) is provided, domain gets calculated internally irrespective of type of input data metric. If domain is provided but the provided domain does not span entire possible input values, discrete range values must be rotated after mapping provided domain values to discrete range.