【v5】双轴的刻度线是否支持对齐 #5256
Replies: 5 comments 5 replies
-
还是没有什么好的解决方案。毕竟还是两个 min max 的 tick 计算。 |
Beta Was this translation helpful? Give feedback.
-
非常有用的一个 feature,隔壁 echarts 已经支持了,希望官方能考虑考虑。 |
Beta Was this translation helpful? Give feedback.
-
我想了解一下,目前 linear 的 tickCount 或 ticks 是怎么决定的。 |
Beta Was this translation helpful? Give feedback.
-
我发现有个坑爹的问题,现在的 tickMethod 是无法访问到 data 的。导致本来调用 chart.changeData 的地方,因为我要实现 tick 对齐,要改成 chat.options 或重新绘图的方式。看下有没有什么 workaround 😭 🙏 |
Beta Was this translation helpful? Give feedback.
-
我写了一个 alignTicks 的方案。 function getRangeAndFactor(start: number, stop: number) {
const maxNum = Math.max(Math.abs(start), Math.abs(stop));
const factor = Math.floor(Math.log(maxNum) / Math.LN10);
const range = [start, stop];
range[0] /= 10 ** factor;
range[1] /= 10 ** factor;
return {
range,
factor: 10 ** factor,
};
}
function calcAlignTickOptions(tickOpts: { min: number; max: number; tickCount: number }[]) {
// 1. 把所有轴的 tick [min, max] 映射到 [-10, 10] 区间
const rangeFactors = tickOpts.map((x) => getRangeAndFactor(x.min, x.max));
// 2. 计算共享的 range
const sharedRange = rangeFactors.reduce(
(ret, x) => [Math.min(x.range[0], ret[0]), Math.max(x.range[1], ret[1])],
[Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
);
// 3. 使用 factor 推算各个轴各自的 domain
const domains = rangeFactors.map((x) => [sharedRange[0] * x.factor, sharedRange[1] * x.factor]);
// 4. 取最大的 tickCount 作为共享的
const tickCount = tickOpts.reduce(
(ret, x) => Math.max(x.tickCount, ret),
Number.NEGATIVE_INFINITY,
);
// 5. 返回新的 domain 和 tickCount
return domains.map((_, i) => ({
domain: domains[i],
tickCount,
nice: false,
}));
} |
Beta Was this translation helpful? Give feedback.
-
我发现之前就有类似的对齐问题 #3459,不知道现在是否有解决方案
Beta Was this translation helpful? Give feedback.
All reactions