@easyv/charts 1.0.73 → 1.1.0

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.
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * 提示框
3
3
  */
4
- import { memo } from 'react';
4
+ import { memo, useMemo } from 'react';
5
5
  import { getFontStyle, getMargin, getTranslate3d } from '../utils';
6
6
  import { getIcon } from '../utils';
7
-
8
7
  export default memo(
9
8
  ({
10
9
  x: position,
11
10
  tickName: x,
11
+ marginLeft,
12
+ marginTop,
12
13
  data,
13
14
  series,
14
- config,
15
15
  config: {
16
16
  tip: {
17
17
  data: {
@@ -22,39 +22,61 @@ export default memo(
22
22
  },
23
23
  image,
24
24
  margin,
25
- size: { width, height },
25
+ size: { width: tipWidth, height: tipHeight },
26
26
  translate: translateTip,
27
27
  },
28
28
  },
29
29
  formatter,
30
30
  isVertical,
31
+ width,
32
+ height,
31
33
  }) => {
32
- const translate3d = isVertical
33
- ? {
34
- ...translateTip,
35
- y: translateTip.y + position,
34
+ const tipPosition = useMemo(() => {
35
+ const translate3d = isVertical
36
+ ? {
37
+ ...translateTip,
38
+ y: translateTip.y + position + marginTop,
39
+ }
40
+ : {
41
+ ...translateTip,
42
+ x: translateTip.x + position + marginLeft,
43
+ };
44
+ if (translate3d.x + tipWidth > width) {
45
+ const newPositon = position + marginLeft - tipWidth - translateTip.x;
46
+ translate3d.x = newPositon >= 0 ? newPositon : 0;
47
+ }
48
+ if (translate3d.y + tipHeight > height) {
49
+ const newPositon = position + marginTop - tipHeight - translateTip.y;
50
+ translate3d.y = newPositon >= 0 ? newPositon : height - tipHeight;
36
51
  }
37
- : {
38
- ...translateTip,
39
- x: translateTip.x + position,
40
- };
52
+ return getTranslate3d(translate3d);
53
+ }, [
54
+ width,
55
+ height,
56
+ marginLeft,
57
+ marginTop,
58
+ position,
59
+ tipWidth,
60
+ tipHeight,
61
+ translateTip,
62
+ ]);
41
63
 
42
64
  return (
43
65
  <div
44
66
  className='__easyv-tooltip'
45
67
  style={{
46
68
  pointerEvents: 'none',
47
- transform: getTranslate3d(translate3d),
48
- width,
49
- height,
69
+ transform: tipPosition,
70
+ width: tipWidth,
71
+ height: tipHeight,
50
72
  padding: getMargin(margin),
51
73
  background: image
52
74
  ? '50% 50% / 100% 100% no-repeat url(' +
53
- window.appConfig.ASSETS_URL +
54
- image +
55
- ')'
75
+ window.appConfig.ASSETS_URL +
76
+ image +
77
+ ')'
56
78
  : 'rgba(48, 55, 66, 0.85)',
57
- ...getFontStyle(font)
79
+ ...getFontStyle(font),
58
80
  }}
59
81
  >
60
82
  {formatter ? (
@@ -80,21 +102,21 @@ export default memo(
80
102
  }}
81
103
  >
82
104
  {x}
83
-
84
105
  </dt>
85
106
  {data.map(({ showY, s }, index) => {
86
107
  const { type, icon, displayName } = series.find(
87
108
  (series) => series.name == s
88
109
  );
89
- const { show: showSuffix, content, font: suffiixFont, translate: suffixTranslate } = suffix
110
+ const {
111
+ show: showSuffix,
112
+ content,
113
+ font: suffiixFont,
114
+ translate: suffixTranslate,
115
+ } = suffix;
90
116
  const tmp = new Map();
91
- Object.values(content).forEach(
92
- (item) => {
93
- tmp.set(item['suffix'].name,
94
- item['suffix'].suffix
95
- );
96
- }
97
- );
117
+ Object.values(content).forEach((item) => {
118
+ tmp.set(item['suffix'].name, item['suffix'].suffix);
119
+ });
98
120
  const _icon = getIcon(type, icon);
99
121
  return (
100
122
  <dd
@@ -113,14 +135,27 @@ export default memo(
113
135
  gap: icon.iconGap,
114
136
  }}
115
137
  >
116
- <span style={{ ..._icon, width: iconSize + 'px', height: iconSize + 'px' }} />
138
+ <span
139
+ style={{
140
+ ..._icon,
141
+ width: iconSize + 'px',
142
+ height: iconSize + 'px',
143
+ }}
144
+ />
117
145
  <span style={getFontStyle(name)}>{displayName || s}</span>
118
146
  </span>
119
- <span style={getFontStyle(value)}>{showY}
120
- {showSuffix && <span style={{ ...getFontStyle(suffiixFont), transform: getTranslate3d(suffixTranslate) }}>
121
- {tmp.get(s)}
122
- </span>
123
- }
147
+ <span style={getFontStyle(value)}>
148
+ {showY}
149
+ {showSuffix && (
150
+ <span
151
+ style={{
152
+ ...getFontStyle(suffiixFont),
153
+ transform: getTranslate3d(suffixTranslate),
154
+ }}
155
+ >
156
+ {tmp.get(s)}
157
+ </span>
158
+ )}
124
159
  </span>
125
160
  </dd>
126
161
  );
@@ -9,6 +9,7 @@ import Axis from './Axis';
9
9
  import Tooltip from './Tooltip';
10
10
  import Indicator from './Indicator';
11
11
  import Band from './Band';
12
+ import Lighter from './Lighter';
12
13
  import Line from './Line';
13
14
  import Background from './Background';
14
15
  import LinearGradient from './LinearGradient';
@@ -34,6 +35,7 @@ export {
34
35
  Axis,
35
36
  Indicator,
36
37
  Band,
38
+ Lighter,
37
39
  Line,
38
40
  Area,
39
41
  Background,
@@ -36,7 +36,10 @@ type Translate = {
36
36
  x: number;
37
37
  y: number;
38
38
  };
39
-
39
+ type Size = {
40
+ width: number;
41
+ height: number;
42
+ };
40
43
  type Font = {
41
44
  bold: boolean;
42
45
  color: string;
@@ -632,7 +632,7 @@ const sortPie = (data, order) => {
632
632
 
633
633
  const getDataWithPercent = (data = [], precision = 0) => {
634
634
  const digits = Math.pow(10, precision);
635
- //const targetSeats = digits * 100;
635
+ const targetSeats = digits * 100;
636
636
 
637
637
  const total = sum(data, (d) => d.value);
638
638
 
@@ -643,7 +643,7 @@ const getDataWithPercent = (data = [], precision = 0) => {
643
643
  }));
644
644
  const currentSum = sum(votesPerQuota, (d) => d.vote);
645
645
 
646
- let remainder = 100 - currentSum;
646
+ let remainder = targetSeats - currentSum;
647
647
  votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
648
648
 
649
649
  const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {