@easyv/charts 1.4.7 → 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.
@@ -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$sh = item.config.label.showLast,
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
- tickCount = _item$tickCount === void 0 ? 1 : _item$tickCount,
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
 
@@ -110,7 +126,7 @@ var _default = function _default(_ref) {
110
126
  var range = direction === 'horizontal' ? [start, end] : direction === 'vertical' ? [end, start] : [0, 0];
111
127
  var newDomain = domain;
112
128
 
113
- if (type !== 'ordinal' && !isNaN(domain[1])) {
129
+ if (type !== 'ordinal' && !isNaN(domain[1]) && !auto) {
114
130
  newDomain = getNewDomain(domain, mode, step);
115
131
  }
116
132
 
@@ -119,7 +135,7 @@ var _default = function _default(_ref) {
119
135
  if (type !== 'ordinal') scaler.clamp(true); //scaler.nice().clamp(true)
120
136
 
121
137
  var allTicks = ticks ? ticks : scaler.ticks ? scaler.ticks(tickCount) : scaler.domain();
122
- var _ticks = allTicks;
138
+ var _ticks = allTicks; //
123
139
 
124
140
  if (type === 'ordinal') {
125
141
  if (carousel === false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.4.7",
3
+ "version": "1.4.9",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -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'
@@ -95,11 +105,12 @@ export default ({ axes, context: { width, height } }) => {
95
105
  ? [end, start]
96
106
  : [0, 0];
97
107
  let newDomain = domain;
98
- if(type !== 'ordinal' && !isNaN(domain[1])){
108
+ if(type !== 'ordinal' && !isNaN(domain[1]) && !auto){
99
109
  newDomain = getNewDomain(domain, mode, step);
100
110
  }
101
111
 
102
112
  const scaler = scales[type]().domain(newDomain).range(range);
113
+
103
114
  scaler.type = type;
104
115
  if (type !== 'ordinal') scaler.clamp(true); //scaler.nice().clamp(true)
105
116
  const allTicks = ticks
@@ -108,6 +119,7 @@ export default ({ axes, context: { width, height } }) => {
108
119
  ? scaler.ticks(tickCount)
109
120
  : scaler.domain();
110
121
  let _ticks = allTicks;
122
+ //
111
123
  if (type === 'ordinal') {
112
124
  if (carousel === false) {
113
125
  _ticks = getTicksOfAxis(_ticks, +tickCount, showLast);