@easyv/charts 1.2.14 → 1.3.2

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.
@@ -24,7 +24,7 @@ import {
24
24
  Brush,
25
25
  Label,
26
26
  Mapping,
27
- BaseLine
27
+ BaseLine,
28
28
  } from '.';
29
29
 
30
30
  const Chart = memo(
@@ -41,11 +41,12 @@ const Chart = memo(
41
41
  legend,
42
42
  },
43
43
  series,
44
+ bandLength,
44
45
  tooltip,
45
46
  baseLine: {
46
- orientation:baseLineOri='',
47
+ orientation: baseLineOri = '',
47
48
  config: baseLineConfig = {},
48
- data: baseLineData = []
49
+ data: baseLineData = [],
49
50
  },
50
51
  tooltip: {
51
52
  config: tooltipConfig = {},
@@ -55,7 +56,7 @@ const Chart = memo(
55
56
  },
56
57
  style,
57
58
  data,
58
- filterData
59
+ filterData,
59
60
  }) => {
60
61
  const context = useContext(chartContext);
61
62
  const {
@@ -101,10 +102,10 @@ const Chart = memo(
101
102
  const indicatorAttr = isVertical
102
103
  ? { width: chartWidth, height: indicatorWidth, y: position }
103
104
  : {
104
- height: chartHeight,
105
- width: indicatorWidth,
106
- x: position,
107
- };
105
+ height: chartHeight,
106
+ width: indicatorWidth,
107
+ x: position,
108
+ };
108
109
 
109
110
  const onInteraction = useCallback(
110
111
  (e) => {
@@ -134,6 +135,7 @@ const Chart = memo(
134
135
  length={isVertical ? chartWidth : chartHeight}
135
136
  axis={axisX}
136
137
  config={background}
138
+ bandLength={bandLength}
137
139
  />
138
140
  )}
139
141
  {[...axes.values()].map((item, index) => {
@@ -152,6 +154,7 @@ const Chart = memo(
152
154
  <Component
153
155
  key={index}
154
156
  {...config}
157
+ bandLength={bandLength}
155
158
  xAxis={axisX}
156
159
  yAxis={yAxis}
157
160
  triggerClick={onInteraction}
@@ -166,6 +169,7 @@ const Chart = memo(
166
169
  <Label
167
170
  key={index}
168
171
  {...config}
172
+ bandLength={bandLength}
169
173
  xAxis={axisX}
170
174
  yAxis={yAxis}
171
175
  triggerClick={onInteraction}
@@ -173,20 +177,27 @@ const Chart = memo(
173
177
  )
174
178
  );
175
179
  })}
176
- {baseLineData && baseLineData.length > 0 && baseLineData.map((item, index) => {
177
- const { line: { yOrZ } } = baseLineConfig[index];
178
- const yAxis = axes.get(yOrZ);
179
- return (
180
- yAxis && (<BaseLine
181
- height={height}
182
- width={width}
183
- key={index}
184
- config={baseLineConfig[index]}
185
- baseLineOri={baseLineOri}
186
- yAxis={yAxis}
187
- data={item} />)
188
- )
189
- })}
180
+ {baseLineData &&
181
+ baseLineData.length > 0 &&
182
+ baseLineData.map((item, index) => {
183
+ const {
184
+ line: { yOrZ },
185
+ } = baseLineConfig[index];
186
+ const yAxis = axes.get(yOrZ);
187
+ return (
188
+ yAxis && (
189
+ <BaseLine
190
+ height={height}
191
+ width={width}
192
+ key={index}
193
+ config={baseLineConfig[index]}
194
+ baseLineOri={baseLineOri}
195
+ yAxis={yAxis}
196
+ data={item}
197
+ />
198
+ )
199
+ );
200
+ })}
190
201
  </ChartContainer>
191
202
  <Legend {...legend} filterData={filterData} series={series} />
192
203
  {showTooltip && (
@@ -65,7 +65,7 @@ const Chart = memo(
65
65
  });
66
66
  }
67
67
  },
68
- [onRelative, emitEvent, JSON.stringify(interaction)]
68
+ [ JSON.stringify(interaction)]
69
69
  );
70
70
 
71
71
  const onEmit = useCallback(
@@ -2,11 +2,7 @@
2
2
  * 轴类图表标签
3
3
  */
4
4
  import { memo, useContext } from 'react';
5
- import {
6
- getTranslate2d,
7
- getBandwidth,
8
- getBandSeriesStepAndWidth,
9
- } from '../utils';
5
+ import { getTranslate2d, getSeriesInfo } from '../utils';
10
6
  import { chartContext } from '../context';
11
7
 
12
8
  export default memo(
@@ -24,68 +20,78 @@ export default memo(
24
20
  yAxis: { scaler: yScaler },
25
21
  triggerClick,
26
22
  }) => {
27
- const lineType = config.hasOwnProperty('line') //堆叠处理
23
+ const lineType = config.hasOwnProperty('line'); // 堆叠处理
28
24
  const showIcon = icon && icon.show;
29
25
  const showLabel = label && label.show;
30
26
 
31
27
  if (!(data.length && (showIcon || showLabel))) return null;
32
28
  const { width, height } = useContext(chartContext);
33
- const bandwidth = getBandwidth(step, paddingOuter);
34
- const { seriesStep, seriesWidth } = getBandSeriesStepAndWidth({
35
- width: bandwidth,
36
- paddingInner,
29
+ const { seriesStep, seriesWidth, seriesStart } = getSeriesInfo({
30
+ step,
37
31
  bandLength,
32
+ paddingInner,
33
+ paddingOuter,
38
34
  });
39
35
 
40
- const offset =
41
- (seriesWidth + paddingInner * seriesStep) * bandLength -
42
- paddingInner * seriesStep;
43
36
  const isVertical = direction === 'vertical';
44
37
  const _position = label.position;
45
38
  return (
46
39
  <g className='__easyv-label'>
47
40
  {data.map(
48
- ({ index, bound: [start, end], data, data: { x, y, showY, s } }, i) => {
41
+ (
42
+ { index, bound: [start, end], data, data: { x, y, showY, s } },
43
+ i
44
+ ) => {
49
45
  const y1 = yScaler(isVertical ? end : start);
50
- //处理z型折线图和堆叠柱图的逻辑冲突
51
- const y2 = lineType ? start ? yScaler(isVertical ? start : end - start) : yScaler(isVertical ? start : end) : yScaler(isVertical ? start : end);
46
+
47
+ // 处理z型折线图和堆叠柱图的逻辑冲突
48
+ const y2 = lineType
49
+ ? start
50
+ ? yScaler(isVertical ? start : end - start)
51
+ : yScaler(isVertical ? start : end)
52
+ : yScaler(isVertical ? start : end);
53
+
52
54
  // const y2 = yScaler(isVertical ? start : end);
53
- const positionX = xScaler(x) + seriesStep * index - offset / 2;
55
+ const positionX =
56
+ xScaler(x) - step / 2 + seriesStart + index * seriesStep;
57
+
54
58
  if (isNaN(positionX)) return null;
55
59
  const position = positionX + seriesWidth / 2;
56
60
  const labelPosition = isVertical
57
61
  ? getVerticalLabel({
58
- position: _position,
59
- y,
60
- y1,
61
- y2,
62
- width,
63
- })
62
+ position: _position,
63
+ y,
64
+ y1,
65
+ y2,
66
+ width,
67
+ })
64
68
  : getHorizontalLabel({
65
- position: _position,
66
- y,
67
- y1,
68
- y2,
69
- height,
70
- });
69
+ position: _position,
70
+ y,
71
+ y1,
72
+ y2,
73
+ height,
74
+ });
71
75
  const attr = isVertical
72
76
  ? {
73
- ...labelPosition,
74
- y: position,
75
- dominantBaseline: 'middle',
76
- }
77
+ ...labelPosition,
78
+ y: position,
79
+ dominantBaseline: 'middle',
80
+ }
77
81
  : {
78
- ...labelPosition,
79
- x: position,
80
- textAnchor: 'middle',
81
- };
82
+ ...labelPosition,
83
+ x: position,
84
+ textAnchor: 'middle',
85
+ };
82
86
  return (
83
87
  <g
84
88
  key={i}
85
89
  onClick={triggerClick}
86
90
  data-data={JSON.stringify(data)}
87
91
  >
88
- {showIcon && <Icon cx={attr.x} cy={attr.y} config={icon} />}
92
+ {showIcon && !isNaN(attr.y) && (
93
+ <Icon cx={attr.x} cy={attr.y} config={icon} />
94
+ )}
89
95
  {showLabel && <Label value={showY} config={label} {...attr} />}
90
96
  </g>
91
97
  );
@@ -123,7 +129,19 @@ const Label = ({
123
129
  </text>
124
130
  );
125
131
  };
126
- const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius, image, size: { width, height } } }) =>
132
+ const Icon = ({
133
+ cx,
134
+ cy,
135
+ config: {
136
+ mode,
137
+ inner,
138
+ outer,
139
+ color,
140
+ radius,
141
+ image,
142
+ size: { width, height },
143
+ },
144
+ }) =>
127
145
  mode == 'single' ? (
128
146
  <Circle cx={cx} cy={cy} color={color} radius={radius} />
129
147
  ) : mode == 'double' ? (
@@ -138,7 +156,8 @@ const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius, image, size
138
156
  height={height}
139
157
  x={cx - width / 2}
140
158
  y={cy - height / 2}
141
- xlinkHref={window.appConfig.ASSETS_URL + image} />
159
+ xlinkHref={window.appConfig.ASSETS_URL + image}
160
+ />
142
161
  </>
143
162
  );
144
163
 
@@ -5,16 +5,12 @@ import { memo } from 'react';
5
5
  import { useStackData } from '../hooks';
6
6
  export default (Component) => {
7
7
  return memo(({ config: { series, ...config }, data, ...props }) => {
8
- const _series = useStackData({
8
+ const _config = useStackData({
9
9
  series,
10
10
  data,
11
11
  });
12
12
  return (
13
- <Component
14
- {...props}
15
- config={{ ...config, series: _series }}
16
- data={data}
17
- />
13
+ <Component {...props} config={{ ...config, ..._config }} data={data} />
18
14
  );
19
15
  });
20
16
  };