Files
lan-manager/web/node_modules/@antv/scale/lib/util/pretty.js
openclaw 0a5f6a8047 Initial commit: Lan-manager project code
- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs

Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
2026-04-20 00:52:58 +08:00

59 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var pretty_number_1 = require("./pretty-number");
function pretty(min, max, m) {
if (m === void 0) { m = 5; }
if (min === max) {
return {
max: max,
min: min,
ticks: [min],
};
}
var n = m < 0 ? 0 : Math.round(m);
if (n === 0)
return { max: max, min: min, ticks: [] };
/*
R pretty:
https://svn.r-project.org/R/trunk/src/appl/pretty.c
https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/pretty
*/
var h = 1.5; // high.u.bias
var h5 = 0.5 + 1.5 * h; // u5.bias
// 反正我也不会调参,跳过所有判断步骤
var d = max - min;
var c = d / n;
// 当d非常小的时候触发但似乎没什么用
// const min_n = Math.floor(n / 3);
// const shrink_sml = Math.pow(2, 5);
// if (Math.log10(d) < -2) {
// c = (_.max([ Math.abs(max), Math.abs(min) ]) * shrink_sml) / min_n;
// }
var base = Math.pow(10, Math.floor(Math.log10(c)));
var unit = base;
if (2 * base - c < h * (c - unit)) {
unit = 2 * base;
if (5 * base - c < h5 * (c - unit)) {
unit = 5 * base;
if (10 * base - c < h * (c - unit)) {
unit = 10 * base;
}
}
}
var nu = Math.ceil(max / unit);
var ns = Math.floor(min / unit);
var hi = Math.max(nu * unit, max);
var lo = Math.min(ns * unit, min);
var size = Math.floor((hi - lo) / unit) + 1;
var ticks = new Array(size);
for (var i = 0; i < size; i++) {
ticks[i] = pretty_number_1.prettyNumber(lo + i * unit);
}
return {
min: lo,
max: hi,
ticks: ticks,
};
}
exports.default = pretty;
//# sourceMappingURL=pretty.js.map