Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createScale(field, data) {
const self = this;
const def = self._getDef(field);
let scale;
const validData = data || [];
const firstValue = Util.Array.firstValue(validData, field);
if (Util.isNumber(field) || (Util.isNil(firstValue)) && !def) {
scale = Scale.identity({
value: field,
field: field.toString(),
values: [ field ]
});
} else { // 如果已经定义过这个度量
let type;
if (def) {
type = def.type;
}
type = type || self._getDefaultType(field, validData);
const cfg = self._getScaleCfg(type, field, validData);
if (def) {
Util.mix(cfg, def);
}
scale = Scale[type](cfg);
}