@easyv/charts 1.5.4 → 1.5.6

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.
@@ -199,6 +199,8 @@ var Label = function Label(_ref5) {
199
199
  translateX = _ref5$config$translat.x,
200
200
  translateY = _ref5$config$translat.y,
201
201
  font = _ref5$config.font,
202
+ _ref5$config$textAlig = _ref5$config.textAlign,
203
+ textAlign = _ref5$config$textAlig === void 0 ? "center" : _ref5$config$textAlig,
202
204
  _ref5$config$appearan = _ref5$config.appearance;
203
205
  _ref5$config$appearan = _ref5$config$appearan === void 0 ? defaultAppearance : _ref5$config$appearan;
204
206
  var width = _ref5$config$appearan.width,
@@ -241,8 +243,8 @@ var Label = function Label(_ref5) {
241
243
  style: {
242
244
  width: width,
243
245
  transform: transform,
244
- textAlign: "center",
245
- justifyContent: "center"
246
+ textAlign: textAlign,
247
+ justifyContent: textAlign == "left" ? "flex-start" : textAlign == "right" ? "flex-end" : "center"
246
248
  }
247
249
  })));
248
250
  };
@@ -120,7 +120,8 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
120
120
  _ref3$yAxis = _ref3.yAxis,
121
121
  yScaler = _ref3$yAxis.scaler,
122
122
  isClipAxis = _ref3$yAxis.isClipAxis,
123
- clipValue = _ref3$yAxis.clipValue;
123
+ clipValue = _ref3$yAxis.clipValue,
124
+ reverse = _ref3$yAxis.reverse;
124
125
  if (!data.length) return null;
125
126
  var step = isControlChart ? controlStep : normalStep;
126
127
  var xScaler = isControlChart ? controlDragScaler : normalScaler;
@@ -192,7 +193,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
192
193
  };
193
194
 
194
195
  if (isNaN(positionX)) return null;
195
- var positionY = y < 0 ? y1 : y2;
196
+ var positionY = reverse ? y > 0 ? y1 : y2 : y < 0 ? y1 : y2;
196
197
  var attr = getAttr({
197
198
  isVertical: isVertical,
198
199
  x: positionX,
@@ -15,8 +15,6 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
15
15
 
16
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
17
 
18
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
19
-
20
18
  var _react = _interopRequireWildcard(require("react"));
21
19
 
22
20
  var _d3v = require("d3v7");
@@ -25,8 +23,6 @@ var _utils = require("../utils");
25
23
 
26
24
  var _ = require(".");
27
25
 
28
- var _excluded = ["data"];
29
-
30
26
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
27
 
32
28
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -40,33 +36,32 @@ var defined = function defined(d) {
40
36
  };
41
37
 
42
38
  var getLineData = function getLineData(data, connectNulls) {
43
- return connectNulls ? data.map(function (_ref) {
44
- var data = _ref.data,
45
- item = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
46
- return _objectSpread(_objectSpread({}, item), {}, {
47
- data: _objectSpread(_objectSpread({}, data), {}, {
48
- y: +data.y
39
+ return data.flatMap(function (d) {
40
+ var y = d.data.y;
41
+ return isNaN(y) ? connectNulls ? [] : _objectSpread(_objectSpread({}, d), {}, {
42
+ data: _objectSpread(_objectSpread({}, d.data), {}, {
43
+ y: null
49
44
  })
50
- });
51
- }) : data;
45
+ }) : d;
46
+ });
52
47
  };
53
48
 
54
- var Area = function Area(_ref2) {
55
- var data = _ref2.data,
56
- config = _ref2.config,
57
- _ref2$config = _ref2.config,
58
- id = _ref2$config.id,
59
- fill = _ref2$config.fill,
60
- type = _ref2$config.type,
61
- url = _ref2$config.url,
62
- opacity = _ref2$config.opacity,
63
- _ref2$config$size = _ref2$config.size,
64
- patternW = _ref2$config$size.width,
65
- patternH = _ref2$config$size.height,
66
- curve = _ref2$config.curve,
67
- tension = _ref2$config.tension,
68
- xScaler = _ref2.xScaler,
69
- yScaler = _ref2.yScaler;
49
+ var Area = function Area(_ref) {
50
+ var data = _ref.data,
51
+ config = _ref.config,
52
+ _ref$config = _ref.config,
53
+ id = _ref$config.id,
54
+ fill = _ref$config.fill,
55
+ type = _ref$config.type,
56
+ url = _ref$config.url,
57
+ opacity = _ref$config.opacity,
58
+ _ref$config$size = _ref$config.size,
59
+ patternW = _ref$config$size.width,
60
+ patternH = _ref$config$size.height,
61
+ curve = _ref$config.curve,
62
+ tension = _ref$config.tension,
63
+ xScaler = _ref.xScaler,
64
+ yScaler = _ref.yScaler;
70
65
 
71
66
  var _yScaler$range = yScaler.range(),
72
67
  _yScaler$range2 = (0, _slicedToArray2["default"])(_yScaler$range, 1),
@@ -76,15 +71,14 @@ var Area = function Area(_ref2) {
76
71
  return (0, _utils.getColorList)(fill);
77
72
  }, [fill]);
78
73
  var areaGen = (0, _react.useMemo)(function () {
79
- var areaGen = (0, _d3v.area)().x(function (_ref3) {
80
- var x = _ref3.data.x;
74
+ var areaGen = (0, _d3v.area)().x(function (_ref2) {
75
+ var x = _ref2.data.x;
81
76
  return xScaler(x);
82
- }).y1(function (_ref4) {
83
- var y = _ref4.data.y;
77
+ }).y1(function (_ref3) {
78
+ var y = _ref3.data.y;
84
79
  return yScaler(y);
85
- }) // .y0(height)
86
- .y0(function (_ref5) {
87
- (0, _objectDestructuringEmpty2["default"])(_ref5);
80
+ }).y0(function (_ref4) {
81
+ (0, _objectDestructuringEmpty2["default"])(_ref4);
88
82
  return yScaler(0);
89
83
  }).defined(defined);
90
84
  curve && areaGen.curve(_d3v.curveCatmullRom.alpha(tension));
@@ -115,35 +109,35 @@ var Area = function Area(_ref2) {
115
109
  })));
116
110
  };
117
111
 
118
- var _default = /*#__PURE__*/(0, _react.memo)(function (_ref6) {
119
- var type = _ref6.type,
120
- _ref6$config$line = _ref6.config.line,
121
- lineType = _ref6$config$line.type,
122
- lineWidth = _ref6$config$line.lineWidth,
123
- curve = _ref6$config$line.curve,
124
- tension = _ref6$config$line.tension,
125
- connectNulls = _ref6$config$line.connectNulls,
126
- lineShadow = _ref6$config$line.lineShadow,
127
- lighter = _ref6$config$line.lighter,
128
- _ref6$line = _ref6.line,
129
- lineId = _ref6$line.id,
130
- stroke = _ref6$line.stroke,
131
- area = _ref6.area,
132
- data = _ref6.data,
133
- _ref6$xAxis = _ref6.xAxis,
134
- xScaler = _ref6$xAxis.scaler,
135
- direction = _ref6$xAxis.direction,
136
- yScaler = _ref6.yAxis.scaler;
112
+ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
113
+ var type = _ref5.type,
114
+ _ref5$config$line = _ref5.config.line,
115
+ lineType = _ref5$config$line.type,
116
+ lineWidth = _ref5$config$line.lineWidth,
117
+ curve = _ref5$config$line.curve,
118
+ tension = _ref5$config$line.tension,
119
+ connectNulls = _ref5$config$line.connectNulls,
120
+ lineShadow = _ref5$config$line.lineShadow,
121
+ lighter = _ref5$config$line.lighter,
122
+ _ref5$line = _ref5.line,
123
+ lineId = _ref5$line.id,
124
+ stroke = _ref5$line.stroke,
125
+ area = _ref5.area,
126
+ data = _ref5.data,
127
+ _ref5$xAxis = _ref5.xAxis,
128
+ xScaler = _ref5$xAxis.scaler,
129
+ direction = _ref5$xAxis.direction,
130
+ yScaler = _ref5.yAxis.scaler;
137
131
  if (!data.length) return null;
138
132
  var ticks = xScaler.domain();
139
133
  var sortData = (0, _react.useMemo)(function () {
140
- var usefulData = data.filter(function (_ref7) {
141
- var x = _ref7.data.x;
134
+ var usefulData = data.filter(function (_ref6) {
135
+ var x = _ref6.data.x;
142
136
  return ticks.indexOf(x) > -1;
143
137
  });
144
- return usefulData.sort(function (_ref8, _ref9) {
145
- var a = _ref8.data.x;
146
- var b = _ref9.data.x;
138
+ return usefulData.sort(function (_ref7, _ref8) {
139
+ var a = _ref7.data.x;
140
+ var b = _ref8.data.x;
147
141
  return ticks.indexOf(a) - ticks.indexOf(b);
148
142
  });
149
143
  }, [data, ticks]);
@@ -154,17 +148,17 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref6) {
154
148
 
155
149
  var lineGen = (0, _react.useMemo)(function () {
156
150
  var isVertical = direction === 'vertical';
157
- var lineGen = (isVertical ? (0, _d3v.line)().y(function (_ref10) {
158
- var x = _ref10.data.x;
151
+ var lineGen = (isVertical ? (0, _d3v.line)().y(function (_ref9) {
152
+ var x = _ref9.data.x;
159
153
  return xScaler(x);
160
- }).x(function (_ref11) {
161
- var y = _ref11.data.y;
154
+ }).x(function (_ref10) {
155
+ var y = _ref10.data.y;
162
156
  return yScaler(y);
163
- }) : (0, _d3v.line)().x(function (_ref12) {
164
- var x = _ref12.data.x;
157
+ }) : (0, _d3v.line)().x(function (_ref11) {
158
+ var x = _ref11.data.x;
165
159
  return xScaler(x);
166
- }).y(function (_ref13) {
167
- var y = _ref13.data.y;
160
+ }).y(function (_ref12) {
161
+ var y = _ref12.data.y;
168
162
  return yScaler(y);
169
163
  })).defined(defined);
170
164
  curve && lineGen.curve(_d3v.curveCatmullRom.alpha(tension));
@@ -125,6 +125,7 @@ var _default = function _default(_ref) {
125
125
  type = item.type,
126
126
  orientation = item.orientation,
127
127
  ticks = item.ticks,
128
+ reverse = item.reverse,
128
129
  _item$tickCount = item.tickCount,
129
130
  count = _item$tickCount === void 0 ? 1 : _item$tickCount,
130
131
  _item$step = item.step,
@@ -331,6 +332,7 @@ var _default = function _default(_ref) {
331
332
  _length = _getChartsConfig2.length;
332
333
 
333
334
  var range = _direction === "horizontal" ? [_start, _end] : _direction === "vertical" ? [_end, _start] : [0, 0];
335
+ if (reverse) range = [range[1], range[0]];
334
336
  var newDomain = domain;
335
337
  var fixedDomain = extent && extent.min != "" && extent.max != ""; //判断配置项中是否强制了最大最小值,如果已经被强制了,就不计算newDomain
336
338
 
@@ -55,31 +55,34 @@ var setStackData = function setStackData(data, series, stacks) {
55
55
  var d = value[i];
56
56
  var currentSeries = series.get(d.s);
57
57
 
58
- if (d && d.y !== undefined && !isNaN(d.y)) {
58
+ if (currentSeries) {
59
+ var type = currentSeries.type;
59
60
  var currentStack = (0, _utils.getCurrentStack)(currentSeries, stacks);
60
61
 
61
- if (currentSeries && currentStack) {
62
- if (d.y >= 0) {
63
- currentSeries.data.push({
64
- data: d,
65
- index: currentStack.index,
66
- bound: [currentStack.positive, currentStack.positive + d.y]
67
- });
68
- currentStack.positive += d.y;
62
+ if (d && d.y !== undefined && (type != "band" || type == "band" && !isNaN(d.y))) {
63
+ if (currentStack) {
64
+ if (d.y >= 0) {
65
+ currentSeries.data.push({
66
+ data: d,
67
+ index: currentStack.index,
68
+ bound: [currentStack.positive, currentStack.positive + d.y]
69
+ });
70
+ currentStack.positive += d.y;
71
+ } else {
72
+ currentSeries.data.push({
73
+ data: d,
74
+ index: currentStack.index,
75
+ bound: [currentStack.negative, currentStack.negative + d.y]
76
+ });
77
+ currentStack.negative += d.y;
78
+ }
69
79
  } else {
70
80
  currentSeries.data.push({
71
81
  data: d,
72
- index: currentStack.index,
73
- bound: [currentStack.negative, currentStack.negative + d.y]
82
+ bound: [0, d.y],
83
+ index: 0
74
84
  });
75
- currentStack.negative += d.y;
76
85
  }
77
- } else {
78
- currentSeries.data.push({
79
- data: d,
80
- bound: [0, d.y],
81
- index: 0
82
- });
83
86
  }
84
87
  }
85
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -184,6 +184,7 @@ type LabelType = {
184
184
  show: boolean;
185
185
  translate: Translate;
186
186
  font: Font;
187
+ textAlign: TextAlign;
187
188
  style: CSSProperties | Function;
188
189
  appearance?: appearance;
189
190
  };
@@ -206,6 +207,7 @@ const Label: (
206
207
  style,
207
208
  translate: { x: translateX, y: translateY },
208
209
  font,
210
+ textAlign = "center",
209
211
  appearance: { width, speed, textOverflow } = defaultAppearance,
210
212
  },
211
213
  }) => {
@@ -245,8 +247,8 @@ const Label: (
245
247
  style={{
246
248
  width,
247
249
  transform,
248
- textAlign: "center",
249
- justifyContent: "center",
250
+ textAlign,
251
+ justifyContent: textAlign=="left"?"flex-start":textAlign=="right"?"flex-end":"center",
250
252
  }}
251
253
  ></TextOverflow>
252
254
  </div>
@@ -88,7 +88,7 @@ export default memo(
88
88
  bandLength = 0,
89
89
  data,
90
90
  xAxis: { scaler: normalScaler, step:normalStep, controlStep, direction, controlDragScaler },
91
- yAxis: { scaler: yScaler, isClipAxis, clipValue },
91
+ yAxis: { scaler: yScaler, isClipAxis, clipValue, reverse },
92
92
  }: any) => {
93
93
  if (!data.length) return null;
94
94
  const step = isControlChart?controlStep:normalStep;
@@ -99,7 +99,6 @@ export default memo(
99
99
  paddingInner,
100
100
  paddingOuter,
101
101
  });
102
-
103
102
  const _data = showHighlight ? getHighlightData(data, extent) : data;
104
103
  const isVertical = direction === "vertical";
105
104
  const borderStr = `${border.borderColor} solid ${border.borderWidth}px`;
@@ -155,7 +154,9 @@ export default memo(
155
154
  }
156
155
  };
157
156
  if (isNaN(positionX)) return null;
158
- const positionY = y < 0 ? y1 : y2;
157
+ const positionY = reverse?
158
+ y > 0 ? y1 : y2:
159
+ y < 0 ? y1 : y2;
159
160
  const attr = getAttr({
160
161
  isVertical,
161
162
  x: positionX,
@@ -90,8 +90,6 @@ const Chart = memo(
90
90
  [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
91
91
  );
92
92
 
93
-
94
-
95
93
  useEffect(()=>{
96
94
  const activeHandler=(e)=>{
97
95
  const { dynamicData = true } = e;
@@ -104,7 +102,6 @@ const Chart = memo(
104
102
  }
105
103
  },[]);
106
104
 
107
-
108
105
  //对轴类图表进行
109
106
  let data = originData;
110
107
  if(axes){
@@ -7,13 +7,17 @@ import { getColorList } from '../utils';
7
7
  import { Lighter, LinearGradient } from '.';
8
8
 
9
9
  const defined = (d) => d.data.y != null;
10
- const getLineData = (data, connectNulls) =>
11
- connectNulls
12
- ? data.map(({ data, ...item }) => ({
13
- ...item,
14
- data: { ...data, y: +data.y },
15
- }))
16
- : data;
10
+ const getLineData = (data, connectNulls) =>{
11
+ return data.flatMap(d=>{
12
+ const y = d.data.y;
13
+ return isNaN(y)?
14
+ connectNulls?
15
+ []:
16
+ {...d,data:{...d.data,y:null}}:
17
+ d
18
+ });
19
+ }
20
+
17
21
 
18
22
  const Area = ({
19
23
  data,
@@ -38,7 +42,6 @@ const Area = ({
38
42
  const areaGen = d3Area()
39
43
  .x(({ data: { x } }) => xScaler(x))
40
44
  .y1(({ data: { y } }) => yScaler(y))
41
- // .y0(height)
42
45
  .y0(({})=>yScaler(0))
43
46
  .defined(defined);
44
47
  curve && areaGen.curve(curveCatmullRom.alpha(tension));
@@ -86,7 +89,7 @@ export default memo(
86
89
  }) => {
87
90
  if (!data.length) return null;
88
91
  const ticks = xScaler.domain();
89
-
92
+
90
93
  const sortData = useMemo(() => {
91
94
  const usefulData = data.filter(
92
95
  ({ data: { x } }) => ticks.indexOf(x) > -1
@@ -96,12 +99,11 @@ export default memo(
96
99
  ticks.indexOf(a) - ticks.indexOf(b)
97
100
  );
98
101
  }, [data, ticks]);
99
-
102
+
100
103
  const _data = useMemo(
101
104
  () => getLineData(sortData, connectNulls),
102
105
  [sortData, connectNulls]
103
106
  );
104
-
105
107
  const lineGen = useMemo(() => {
106
108
  const isVertical = direction === 'vertical';
107
109
 
@@ -10,7 +10,7 @@ interface flowText{
10
10
  value:string,
11
11
  speed:number,
12
12
  style:CSSProperties,
13
- config:any
13
+ config?:any
14
14
  }
15
15
 
16
16
  export default memo(forwardRef((props:flowText, ref:any) => {
@@ -87,6 +87,7 @@ export default ({
87
87
  type,
88
88
  orientation,
89
89
  ticks,
90
+ reverse,
90
91
  tickCount: count = 1,
91
92
  step = 1,
92
93
  domain,
@@ -332,13 +333,13 @@ export default ({
332
333
  //计算真正需要的tickCount,如果domain区间太小,不能完全按照count来,需要减少count数
333
334
  const tickCount = type == "ordinal" ? _count : getTickCount(domain, _count, decimal);
334
335
  const { start, end, direction, _paddingOuter, length } = getChartsConfig(orientation, width, height, paddingOuter);
335
-
336
336
  let range =
337
337
  direction === "horizontal"
338
338
  ? [start, end]
339
339
  : direction === "vertical"
340
340
  ? [end, start]
341
341
  : [0, 0];
342
+ if(reverse)range = [range[1],range[0]];
342
343
  let newDomain = domain;
343
344
  const fixedDomain = extent && extent.min!="" && extent.max!=""; //判断配置项中是否强制了最大最小值,如果已经被强制了,就不计算newDomain
344
345
  if (type !== "ordinal" && !isNaN(domain[1]) && !auto && !fixedDomain) {
@@ -27,38 +27,41 @@ const resetStackData = (series) => {
27
27
 
28
28
  const setStackData = (data, series, stacks) => {
29
29
  const dataMap = group(data, (d) => d.x);
30
-
31
30
  dataMap.forEach((value) => {
32
31
  resetStacks(stacks);
33
32
  for (let i = 0, j = value.length; i < j; i++) {
34
33
  const d = value[i];
35
34
  const currentSeries = series.get(d.s);
36
- if (d && d.y !== undefined && !isNaN(d.y)) {
35
+ if(currentSeries){
36
+ const type = currentSeries.type;
37
37
  const currentStack = getCurrentStack(currentSeries, stacks);
38
- if (currentSeries && currentStack) {
39
- if (d.y >= 0) {
40
- currentSeries.data.push({
41
- data: d,
42
- index: currentStack.index,
43
- bound: [currentStack.positive, currentStack.positive + d.y],
44
- });
45
- currentStack.positive += d.y;
38
+ if (d && d.y !== undefined && (type!="band" || type=="band" && !isNaN(d.y))) {
39
+ if (currentStack) {
40
+ if (d.y >= 0) {
41
+ currentSeries.data.push({
42
+ data: d,
43
+ index: currentStack.index,
44
+ bound: [currentStack.positive, currentStack.positive + d.y],
45
+ });
46
+ currentStack.positive += d.y;
47
+ } else {
48
+ currentSeries.data.push({
49
+ data: d,
50
+ index: currentStack.index,
51
+ bound: [currentStack.negative, currentStack.negative + d.y],
52
+ });
53
+ currentStack.negative += d.y;
54
+ }
46
55
  } else {
47
56
  currentSeries.data.push({
48
57
  data: d,
49
- index: currentStack.index,
50
- bound: [currentStack.negative, currentStack.negative + d.y],
58
+ bound: [0, d.y],
59
+ index: 0,
51
60
  });
52
- currentStack.negative += d.y;
53
61
  }
54
- } else {
55
- currentSeries.data.push({
56
- data: d,
57
- bound: [0, d.y],
58
- index: 0,
59
- });
60
62
  }
61
63
  }
64
+
62
65
  }
63
66
  });
64
67
  dataMap.clear();
@@ -80,7 +83,6 @@ export default ({ data, series }) => {
80
83
  }, [series]);
81
84
 
82
85
  const _data = useMemo(() => dataYOrZ(data, _series.series), [data, _series]);
83
-
84
86
  const tmp = useMemo(() => {
85
87
  const { y: dataY, z: dataZ } = _data;
86
88
  const {
@@ -91,7 +93,6 @@ export default ({ data, series }) => {
91
93
  resetStackData(seriesZ);
92
94
  setStackData(dataY, seriesY, stacks);
93
95
  setStackData(dataZ, seriesZ, stacks);
94
-
95
96
  return {
96
97
  bandLength: stacks.filter((item) => item.type == 'band').length,
97
98
  series: [...seriesY.values(), ...seriesZ.values()],
@@ -36,6 +36,7 @@ type ChartLine = {
36
36
  };
37
37
 
38
38
  type Orientation = 'top' | 'bottom' | 'left' | 'right';
39
+ type TextAlign = "left" | "center" | "right" | "justify";
39
40
 
40
41
  type Translate = {
41
42
  x: number;