kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
60 lines (57 loc) • 7.04 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPropertyByZoom = getPropertyByZoom;
exports.isDomainQuantiles = isDomainQuantiles;
exports.isDomainStops = isDomainStops;
exports.isIndexedField = isIndexedField;
exports.pruneQuantiles = pruneQuantiles;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _d3Array = require("d3-array");
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
// helper functions
function isDomainStops(domain) {
return (0, _typeof2["default"])(domain) === 'object' && domain !== null && Array.isArray(domain.stops) && Array.isArray(domain.z);
}
function isDomainQuantiles(domain) {
return (0, _typeof2["default"])(domain) === 'object' && domain !== null && Array.isArray(domain.quantiles) && Array.isArray(domain.z);
}
function isIndexedField(field) {
return Boolean(field && field.indexBy);
}
function getPropertyByZoom(config, defaultValue) {
if (!config || !config.enabled || !Array.isArray(config.stops)) {
return function () {
return defaultValue;
};
}
var stops = config.stops;
var zSteps = stops.map(function (st) {
return st[0];
});
return function (zoom) {
var i = (0, _d3Array.bisectLeft)(zSteps, zoom);
if (i === 0) {
return stops[i][1];
}
return stops[i - 1][1];
};
}
/**
* Remove null/0 values from the bottom of the quantiles. If the column has many nulls
* or 0s at the bottom of the quantiles, it will wash out color scales and produce
* meaningless "no value" legend entries. We want to keep the first 0 and no others.
* Operates in place.
*/
function pruneQuantiles(quantiles) {
var firstNonZeroIdx = quantiles.findIndex(function (d) {
return d !== null && d !== 0;
});
if (firstNonZeroIdx > 0) {
quantiles.splice(0, firstNonZeroIdx - 1);
}
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfZDNBcnJheSIsInJlcXVpcmUiLCJpc0RvbWFpblN0b3BzIiwiZG9tYWluIiwiX3R5cGVvZjIiLCJBcnJheS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