@antv/scale
Advanced tools
Comparing version 0.3.10 to 0.3.11
@@ -45,3 +45,3 @@ export declare type ScaleType = 'base' | 'linear' | 'cat' | 'log' | 'pow' | 'identity' | 'time' | 'timeCat'; | ||
/** tick格式化函数,会影响数据在坐标轴 axis、图例 legend、tooltip 上的显示 */ | ||
formatter: (v: any, k?: number) => any; | ||
formatter: (value: any, index?: number) => any; | ||
/** 计算 ticks 的算法 */ | ||
@@ -48,0 +48,0 @@ tickMethod: string | TickMethod; |
import { head, indexOf, size, last } from '@antv/util'; | ||
import { precisionAdd } from './math'; | ||
export var DEFAULT_Q = [1, 5, 2, 2.5, 4, 3]; | ||
@@ -51,2 +50,6 @@ export var ALL_Q = [1, 5, 2, 2.5, 4, 3, 1.5, 7, 6, 8, 9]; | ||
} | ||
// 解决 js 计算精度问题 | ||
function pretty(n) { | ||
return n < 1e-15 ? n : parseFloat(n.toFixed(15)); | ||
} | ||
/** | ||
@@ -142,16 +145,15 @@ * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes | ||
} | ||
var size = Math.floor((best.lmax - best.lmin) / best.lstep); | ||
var ticks = new Array(size); | ||
var i = 0; | ||
// 步长为浮点数时处理精度 | ||
var range = new Array(Math.floor((best.lmax - best.lmin) / best.lstep)); | ||
for (var tick = best.lmin; tick <= best.lmax; tick = precisionAdd(tick, best.lstep)) { | ||
range[i] = tick; | ||
for (var tick = best.lmin; tick <= best.lmax; tick += best.lstep) { | ||
ticks[i] = pretty(tick); | ||
i += 1; | ||
} | ||
return { | ||
min: Math.min(dMin, head(range)), | ||
max: Math.max(dMax, last(range)), | ||
ticks: range, | ||
min: Math.min(dMin, head(ticks)), | ||
max: Math.max(dMax, last(ticks)), | ||
ticks: ticks, | ||
}; | ||
} | ||
; | ||
//# sourceMappingURL=extended.js.map |
@@ -45,3 +45,3 @@ export declare type ScaleType = 'base' | 'linear' | 'cat' | 'log' | 'pow' | 'identity' | 'time' | 'timeCat'; | ||
/** tick格式化函数,会影响数据在坐标轴 axis、图例 legend、tooltip 上的显示 */ | ||
formatter: (v: any, k?: number) => any; | ||
formatter: (value: any, index?: number) => any; | ||
/** 计算 ticks 的算法 */ | ||
@@ -48,0 +48,0 @@ tickMethod: string | TickMethod; |
@@ -5,3 +5,2 @@ "use strict"; | ||
var util_1 = require("@antv/util"); | ||
var math_1 = require("./math"); | ||
exports.DEFAULT_Q = [1, 5, 2, 2.5, 4, 3]; | ||
@@ -55,2 +54,6 @@ exports.ALL_Q = [1, 5, 2, 2.5, 4, 3, 1.5, 7, 6, 8, 9]; | ||
} | ||
// 解决 js 计算精度问题 | ||
function pretty(n) { | ||
return n < 1e-15 ? n : parseFloat(n.toFixed(15)); | ||
} | ||
/** | ||
@@ -146,17 +149,16 @@ * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes | ||
} | ||
var size = Math.floor((best.lmax - best.lmin) / best.lstep); | ||
var ticks = new Array(size); | ||
var i = 0; | ||
// 步长为浮点数时处理精度 | ||
var range = new Array(Math.floor((best.lmax - best.lmin) / best.lstep)); | ||
for (var tick = best.lmin; tick <= best.lmax; tick = math_1.precisionAdd(tick, best.lstep)) { | ||
range[i] = tick; | ||
for (var tick = best.lmin; tick <= best.lmax; tick += best.lstep) { | ||
ticks[i] = pretty(tick); | ||
i += 1; | ||
} | ||
return { | ||
min: Math.min(dMin, util_1.head(range)), | ||
max: Math.max(dMax, util_1.last(range)), | ||
ticks: range, | ||
min: Math.min(dMin, util_1.head(ticks)), | ||
max: Math.max(dMax, util_1.last(ticks)), | ||
ticks: ticks, | ||
}; | ||
} | ||
exports.default = extended; | ||
; | ||
//# sourceMappingURL=extended.js.map |
{ | ||
"name": "@antv/scale", | ||
"version": "0.3.10", | ||
"version": "0.3.11", | ||
"description": "The scale module for G2", | ||
@@ -5,0 +5,0 @@ "author": "https://github.com/orgs/antvis/people", |
@@ -51,3 +51,3 @@ export type ScaleType = 'base' | 'linear' | 'cat' | 'log' | 'pow' | 'identity' | 'time' | 'timeCat'; | ||
/** tick格式化函数,会影响数据在坐标轴 axis、图例 legend、tooltip 上的显示 */ | ||
formatter: (v: any, k?: number) => any; | ||
formatter: (value: any, index?: number) => any; | ||
/** 计算 ticks 的算法 */ | ||
@@ -54,0 +54,0 @@ tickMethod: string | TickMethod; |
import { head, indexOf, size, last } from '@antv/util'; | ||
import { precisionAdd } from './math'; | ||
@@ -63,2 +62,7 @@ export const DEFAULT_Q = [1, 5, 2, 2.5, 4, 3]; | ||
// 解决 js 计算精度问题 | ||
function pretty(n: number) { | ||
return n < 1e-15 ? n : parseFloat(n.toFixed(15)); | ||
} | ||
/** | ||
@@ -80,3 +84,3 @@ * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes | ||
Q: number[] = DEFAULT_Q, | ||
w: [number, number, number, number] = [0.25, 0.2, 0.5, 0.05], | ||
w: [number, number, number, number] = [0.25, 0.2, 0.5, 0.05] | ||
): { min: number; max: number; ticks: number[] } { | ||
@@ -169,16 +173,16 @@ // nan 也会导致异常 | ||
const size = Math.floor((best.lmax - best.lmin) / best.lstep); | ||
const ticks = new Array(size); | ||
let i = 0; | ||
// 步长为浮点数时处理精度 | ||
const range = new Array(Math.floor((best.lmax - best.lmin) / best.lstep)); | ||
for (let tick = best.lmin; tick <= best.lmax; tick = precisionAdd(tick, best.lstep)) { | ||
range[i] = tick; | ||
for (let tick = best.lmin; tick <= best.lmax; tick += best.lstep) { | ||
ticks[i] = pretty(tick); | ||
i += 1; | ||
} | ||
return { | ||
min: Math.min(dMin, head(range)), | ||
max: Math.max(dMax, last(range)), | ||
ticks: range, | ||
min: Math.min(dMin, head(ticks)), | ||
max: Math.max(dMax, last(ticks)), | ||
ticks, | ||
}; | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
324129
6057