@easyv/charts 1.3.13 → 1.3.14

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.
@@ -21,6 +21,44 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
21
21
 
22
22
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
23
 
24
+ var getCount = function getCount(num) {
25
+ var i = 0,
26
+ num_ = Math.abs(num);
27
+ if (num_ < 1) return i;
28
+
29
+ while (num_ > 10) {
30
+ i++;
31
+ num_ = Math.floor(num_ / 10);
32
+ }
33
+
34
+ return i;
35
+ };
36
+
37
+ var getNewDomain = function getNewDomain(domain, mode, step) {
38
+ var newDomain = [];
39
+ var min = domain[0],
40
+ max = domain[1];
41
+ var minCount = Math.pow(10, getCount(min)),
42
+ maxCount = Math.pow(10, getCount(max));
43
+
44
+ switch (mode) {
45
+ case 'count':
46
+ newDomain[0] = Math.floor(domain[0] / minCount) * minCount;
47
+ newDomain[1] = Math.ceil(domain[1] / maxCount) * maxCount;
48
+ break;
49
+
50
+ case 'step':
51
+ newDomain = [domain[0], domain[0]];
52
+
53
+ while (newDomain[1] < domain[1]) {
54
+ newDomain[1] += step;
55
+ }
56
+
57
+ }
58
+
59
+ return newDomain;
60
+ };
61
+
24
62
  var scales = {
25
63
  linear: _d3Scale.scaleLinear,
26
64
  log: _d3Scale.scaleLog,
@@ -70,7 +108,13 @@ var _default = function _default(_ref) {
70
108
  var start = _paddingOuter / 2;
71
109
  var end = length - start;
72
110
  var range = direction === 'horizontal' ? [start, end] : direction === 'vertical' ? [end, start] : [0, 0];
73
- var scaler = scales[type]().domain(domain).range(range);
111
+ var newDomain = domain;
112
+
113
+ if (type !== 'ordinal' && !isNaN(domain[1])) {
114
+ newDomain = getNewDomain(domain, mode, step);
115
+ }
116
+
117
+ var scaler = scales[type]().domain(newDomain).range(range);
74
118
  scaler.type = type;
75
119
  if (type !== 'ordinal') scaler.nice().clamp(true);
76
120
  var allTicks = ticks ? ticks : scaler.ticks ? scaler.ticks(tickCount) : scaler.domain();
@@ -88,7 +132,7 @@ var _default = function _default(_ref) {
88
132
  break;
89
133
 
90
134
  case 'step':
91
- _ticks = (0, _utils2.getYTicksByStep)(_ticks[_ticks.length - 1], _ticks[0], +step);
135
+ _ticks = (0, _utils2.getYTicksByStep)(newDomain[1], _ticks[0], +step);
92
136
  break;
93
137
  }
94
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -6,6 +6,36 @@ import {
6
6
  getYTicks,
7
7
  } from '@easyv/utils/lib/common/utils';
8
8
 
9
+ const getCount = (num)=>{
10
+ let i=0, num_ = Math.abs(num);
11
+ if(num_<1) return i;
12
+ while(num_>10){
13
+ i++;
14
+ num_=Math.floor(num_/10);
15
+ }
16
+ return i;
17
+ }
18
+
19
+ const getNewDomain=(domain, mode, step)=>{
20
+ let newDomain=[];
21
+ let min = domain[0], max = domain[1];
22
+ let minCount = Math.pow(10,getCount(min)), maxCount = Math.pow(10,getCount(max));
23
+
24
+ switch(mode){
25
+ case 'count':
26
+ newDomain[0] = Math.floor(domain[0]/minCount)*minCount;
27
+ newDomain[1] = Math.ceil(domain[1]/maxCount)*maxCount;
28
+ break;
29
+ case 'step':
30
+ newDomain = [domain[0],domain[0]];
31
+ while(newDomain[1]<domain[1]){
32
+ newDomain[1]+=step
33
+ }
34
+
35
+ }
36
+ return newDomain;
37
+ }
38
+
9
39
  const scales = {
10
40
  linear: scaleLinear,
11
41
  log: scaleLog,
@@ -66,8 +96,11 @@ export default ({ axes, context: { width, height } }) => {
66
96
  : direction === 'vertical'
67
97
  ? [end, start]
68
98
  : [0, 0];
69
-
70
- const scaler = scales[type]().domain(domain).range(range);
99
+ let newDomain = domain;
100
+ if(type !== 'ordinal' && !isNaN(domain[1])){
101
+ newDomain = getNewDomain(domain, mode, step);
102
+ }
103
+ const scaler = scales[type]().domain(newDomain).range(range);
71
104
  scaler.type = type;
72
105
 
73
106
  if (type !== 'ordinal') scaler.nice().clamp(true);
@@ -79,7 +112,6 @@ export default ({ axes, context: { width, height } }) => {
79
112
  : scaler.domain();
80
113
 
81
114
  let _ticks = allTicks;
82
-
83
115
  if (type === 'ordinal') {
84
116
  if (carousel === false) {
85
117
  _ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
@@ -96,7 +128,7 @@ export default ({ axes, context: { width, height } }) => {
96
128
  break;
97
129
  case 'step':
98
130
  _ticks = getYTicksByStep(
99
- _ticks[_ticks.length - 1],
131
+ newDomain[1],
100
132
  _ticks[0],
101
133
  +step
102
134
  );