gpt4 book ai didi

javascript - 如何动态确定缩放函数的类型?

转载 作者:行者123 更新时间:2023-11-27 23:17:09 24 4
gpt4 key购买 nike

我有代码:

let scale = d3.scale.log();
//How to determine that 'scale' variable is a logarithmic scaling function?

scale = d3.scale.ordinal();
//In this case how to determine that 'scale' variable is an ordinal scaling function?

缩放函数的某些属性或某些方法可以帮助我吗?我需要此信息才能使用 HTML Canvas API 绘制比例特定轴。

最佳答案

如果您只需要确定它是否是序数尺度,您可以使用:

scale.hasOwnProperty("rangePoints")

只有序数尺度才有这种方法。

<小时/>

另一种想法,如果您正在创建比例,请自己跟踪它:

scale = d3.scale.log();
scale.type = "log";
scale = d3.scale.linear();
scale.type = "linear";

关于javascript - 如何动态确定缩放函数的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35726692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com