@bokeh/bokehjs
Version:
Interactive, novel data visualization
42 lines • 1.47 kB
JavaScript
import { BasicTickFormatter } from "./basic_tick_formatter";
import { LatLon } from "../../core/enums";
import { wgs84_mercator } from "../../core/util/projections";
const zero_threshold = 1e-12; // degrees; about 0.1 micrometers at the equator
function normalize_zeroish(value) {
return Math.abs(value) < zero_threshold ? 0 : value;
}
export class MercatorTickFormatter extends BasicTickFormatter {
static __name__ = "MercatorTickFormatter";
constructor(attrs) {
super(attrs);
}
static {
this.define(({ Nullable }) => ({
dimension: [Nullable(LatLon), null],
}));
}
doFormat(ticks, opts) {
if (this.dimension == null) {
throw new Error("MercatorTickFormatter.dimension not configured");
}
if (ticks.length == 0) {
return [];
}
const n = ticks.length;
const proj_ticks = new Array(n);
if (this.dimension == "lon") {
for (let i = 0; i < n; i++) {
const [lon] = wgs84_mercator.invert(ticks[i], opts.loc);
proj_ticks[i] = normalize_zeroish(lon);
}
}
else {
for (let i = 0; i < n; i++) {
const [, lat] = wgs84_mercator.invert(opts.loc, ticks[i]);
proj_ticks[i] = normalize_zeroish(lat);
}
}
return super.doFormat(proj_ticks, opts);
}
}
//# sourceMappingURL=mercator_tick_formatter.js.map