@easyv/charts 1.4.8 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/hooks/useAxes.js +19 -3
- package/package.json +1 -1
- package/src/hooks/useAxes.js +13 -3
package/lib/hooks/useAxes.js
CHANGED
|
@@ -59,6 +59,17 @@ var getNewDomain = function getNewDomain(domain, mode, step) {
|
|
|
59
59
|
return newDomain;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
var getTickCount = function getTickCount(domain, count, decimal) {
|
|
63
|
+
var multiple = Math.pow(10, decimal);
|
|
64
|
+
var gap = domain[1] * multiple - domain[0] * multiple;
|
|
65
|
+
|
|
66
|
+
if (gap < count) {
|
|
67
|
+
return Math.max(2, 1 + gap);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return count;
|
|
71
|
+
};
|
|
72
|
+
|
|
62
73
|
var scales = {
|
|
63
74
|
linear: _d3Scale.scaleLinear,
|
|
64
75
|
log: _d3Scale.scaleLog,
|
|
@@ -83,13 +94,16 @@ var _default = function _default(_ref) {
|
|
|
83
94
|
var tmp = new Map();
|
|
84
95
|
var xAxisPositions = [];
|
|
85
96
|
axes.forEach(function (item) {
|
|
86
|
-
var _item$config$label
|
|
97
|
+
var _item$config$label = item.config.label,
|
|
98
|
+
_item$config$label$sh = _item$config$label.showLast,
|
|
87
99
|
showLast = _item$config$label$sh === void 0 ? false : _item$config$label$sh,
|
|
100
|
+
_item$config$label$de = _item$config$label.decimal,
|
|
101
|
+
decimal = _item$config$label$de === void 0 ? 0 : _item$config$label$de,
|
|
88
102
|
type = item.type,
|
|
89
103
|
orientation = item.orientation,
|
|
90
104
|
ticks = item.ticks,
|
|
91
105
|
_item$tickCount = item.tickCount,
|
|
92
|
-
|
|
106
|
+
count = _item$tickCount === void 0 ? 1 : _item$tickCount,
|
|
93
107
|
_item$step = item.step,
|
|
94
108
|
step = _item$step === void 0 ? 1 : _item$step,
|
|
95
109
|
domain = item.domain,
|
|
@@ -99,7 +113,9 @@ var _default = function _default(_ref) {
|
|
|
99
113
|
auto = item.auto,
|
|
100
114
|
mode = item.mode,
|
|
101
115
|
carousel = item.carousel,
|
|
102
|
-
config = item.config;
|
|
116
|
+
config = item.config; //计算真正需要的tickCount,如果domain区间太小,不能完全按照count来,需要减少count数
|
|
117
|
+
|
|
118
|
+
var tickCount = getTickCount(domain, count, decimal);
|
|
103
119
|
var direction = orientation === 'top' || orientation === 'bottom' ? 'horizontal' : orientation === 'left' || orientation === 'right' ? 'vertical' : '';
|
|
104
120
|
var length = direction === 'horizontal' ? width : direction === 'vertical' ? height : 0;
|
|
105
121
|
|
package/package.json
CHANGED
package/src/hooks/useAxes.js
CHANGED
|
@@ -30,11 +30,19 @@ const getNewDomain=(domain, mode, step)=>{
|
|
|
30
30
|
while(newDomain[1]<domain[1]){
|
|
31
31
|
newDomain[1]+=step
|
|
32
32
|
}
|
|
33
|
-
|
|
34
33
|
}
|
|
35
34
|
return newDomain;
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
const getTickCount=(domain, count, decimal)=>{
|
|
38
|
+
let multiple = Math.pow(10,decimal);
|
|
39
|
+
let gap = domain[1]*multiple-domain[0]*multiple;
|
|
40
|
+
if(gap<count){
|
|
41
|
+
return Math.max(2,1+gap);
|
|
42
|
+
}
|
|
43
|
+
return count;
|
|
44
|
+
}
|
|
45
|
+
|
|
38
46
|
const scales = {
|
|
39
47
|
linear: scaleLinear,
|
|
40
48
|
log: scaleLog,
|
|
@@ -56,11 +64,11 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
56
64
|
const xAxisPositions = [];
|
|
57
65
|
axes.forEach((item) => {
|
|
58
66
|
const {
|
|
59
|
-
config: { label: { showLast = false } },
|
|
67
|
+
config: { label: { showLast = false, decimal = 0 } },
|
|
60
68
|
type,
|
|
61
69
|
orientation,
|
|
62
70
|
ticks,
|
|
63
|
-
tickCount = 1,
|
|
71
|
+
tickCount :count = 1,
|
|
64
72
|
step = 1,
|
|
65
73
|
domain,
|
|
66
74
|
axisType,
|
|
@@ -71,6 +79,8 @@ export default ({ axes, context: { width, height } }) => {
|
|
|
71
79
|
config,
|
|
72
80
|
} = item;
|
|
73
81
|
|
|
82
|
+
//计算真正需要的tickCount,如果domain区间太小,不能完全按照count来,需要减少count数
|
|
83
|
+
const tickCount = getTickCount(domain,count,decimal);
|
|
74
84
|
const direction =
|
|
75
85
|
orientation === 'top' || orientation === 'bottom'
|
|
76
86
|
? 'horizontal'
|