@easyv/charts 1.0.70 → 1.0.74

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.
@@ -184,6 +184,9 @@ var Label = function Label(_ref5) {
184
184
  var translateText = 'translate(' + x + ', ' + y + ')';
185
185
  return /*#__PURE__*/_react["default"].createElement("text", {
186
186
  className: className,
187
+ style: {
188
+ whiteSpace: "pre"
189
+ },
187
190
  dominantBaseline: dominantBaseline,
188
191
  textAnchor: textAnchor,
189
192
  fontFamily: fontFamily,
@@ -89,7 +89,11 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
89
89
  _ref3$config$paddingI = _ref3$config.paddingInner,
90
90
  paddingOuter = _ref3$config$paddingI === void 0 ? 0 : _ref3$config$paddingI,
91
91
  style = _ref3$config.style,
92
+ fillType = _ref3$config.fillType,
93
+ url = _ref3$config.url,
94
+ size = _ref3$config.size,
92
95
  fill = _ref3$config.fill,
96
+ opacity = _ref3$config.opacity,
93
97
  _ref3$config$highligh = _ref3$config.highlight,
94
98
  showHighlight = _ref3$config$highligh.show,
95
99
  extent = _ref3$config$highligh.extent,
@@ -152,7 +156,8 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
152
156
  style: {
153
157
  width: '100%',
154
158
  height: '100%',
155
- background: (0, _utils.getBandBackground)(pattern, extent === flag ? highlightFill : fill),
159
+ opacity: opacity,
160
+ background: fillType == 'pattern' ? "50% 50% / ".concat(size.width, "px ").concat(size.height, "px repeat ") + 'url(' + url + ')' : (0, _utils.getBandBackground)(pattern, extent === flag ? highlightFill : fill),
156
161
  borderRadius: style == 'square' ? '0 0 0 0' : getBorderRadius({
157
162
  isVertical: isVertical,
158
163
  positive: y > 0,
@@ -157,19 +157,29 @@ var Icon = function Icon(_ref4) {
157
157
  inner = _ref4$config.inner,
158
158
  outer = _ref4$config.outer,
159
159
  color = _ref4$config.color,
160
- radius = _ref4$config.radius;
160
+ radius = _ref4$config.radius,
161
+ image = _ref4$config.image,
162
+ _ref4$config$size = _ref4$config.size,
163
+ width = _ref4$config$size.width,
164
+ height = _ref4$config$size.height;
161
165
  return mode == 'single' ? /*#__PURE__*/React.createElement(Circle, {
162
166
  cx: cx,
163
167
  cy: cy,
164
168
  color: color,
165
169
  radius: radius
166
- }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Circle, (0, _extends2["default"])({
170
+ }) : mode == 'double' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Circle, (0, _extends2["default"])({
167
171
  cx: cx,
168
172
  cy: cy
169
173
  }, inner)), /*#__PURE__*/React.createElement(Circle, (0, _extends2["default"])({
170
174
  cx: cx,
171
175
  cy: cy
172
- }, outer)));
176
+ }, outer))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("image", {
177
+ width: width,
178
+ height: height,
179
+ x: cx - width / 2,
180
+ y: cy - height / 2,
181
+ xlinkHref: window.appConfig.ASSETS_URL + image
182
+ }));
173
183
  };
174
184
 
175
185
  var Circle = function Circle(_ref5) {
@@ -45,9 +45,16 @@ var getLineData = function getLineData(data, connectNulls) {
45
45
 
46
46
  var Area = function Area(_ref2) {
47
47
  var data = _ref2.data,
48
+ config = _ref2.config,
48
49
  _ref2$config = _ref2.config,
49
50
  id = _ref2$config.id,
50
51
  fill = _ref2$config.fill,
52
+ type = _ref2$config.type,
53
+ url = _ref2$config.url,
54
+ opacity = _ref2$config.opacity,
55
+ _ref2$config$size = _ref2$config.size,
56
+ patternW = _ref2$config$size.width,
57
+ patternH = _ref2$config$size.height,
51
58
  curve = _ref2$config.curve,
52
59
  tension = _ref2$config.tension,
53
60
  xScaler = _ref2.xScaler,
@@ -76,7 +83,17 @@ var Area = function Area(_ref2) {
76
83
  d: areaGen(data),
77
84
  stroke: "none",
78
85
  fill: 'url(#' + id + ')'
79
- }), /*#__PURE__*/_react["default"].createElement("defs", null, /*#__PURE__*/_react["default"].createElement(_.LinearGradient, {
86
+ }), /*#__PURE__*/_react["default"].createElement("defs", null, type && type == 'pattern' ? /*#__PURE__*/_react["default"].createElement("pattern", {
87
+ id: id,
88
+ patternUnits: "userSpaceOnUse",
89
+ width: patternW,
90
+ height: patternH
91
+ }, url && /*#__PURE__*/_react["default"].createElement("image", {
92
+ opacity: opacity,
93
+ width: patternW,
94
+ height: patternH,
95
+ xlinkHref: window.appConfig.ASSETS_URL + url
96
+ })) : /*#__PURE__*/_react["default"].createElement(_.LinearGradient, {
80
97
  id: id,
81
98
  colors: area,
82
99
  rotate: 0
@@ -45,7 +45,9 @@ var _default = function _default(_ref) {
45
45
  var tmp = new Map();
46
46
  var xAxisPositions = [];
47
47
  axes.forEach(function (item) {
48
- var type = item.type,
48
+ var _item$config$label$sh = item.config.label.showLast,
49
+ showLast = _item$config$label$sh === void 0 ? false : _item$config$label$sh,
50
+ type = item.type,
49
51
  orientation = item.orientation,
50
52
  ticks = item.ticks,
51
53
  _item$tickCount = item.tickCount,
@@ -76,7 +78,7 @@ var _default = function _default(_ref) {
76
78
 
77
79
  if (type === 'ordinal') {
78
80
  if (carousel === false) {
79
- _ticks = (0, _utils2.getTicksOfAxis)(_ticks, +tickCount);
81
+ _ticks = (0, _utils.getTicksOfAxis)(_ticks, +tickCount, showLast);
80
82
  }
81
83
  } else {
82
84
  if (auto === false) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.band = band;
9
- exports.getDataWithPercent = exports.sortPie = exports.getDomPath = exports.filterChildren = exports.getChildren = exports.isValidHttpUrl = exports.getBandSeriesStepAndWidth = exports.getBandwidth = exports.getBandBackground = exports.getCurrentStack = exports.resetStacks = exports.seriesYOrZ = exports.dataYOrZ = exports.getStacks = exports.getColorList = exports.getIcon = exports.getTranslate2d = exports.getTranslate3d = exports.getMargin = exports.getFontStyle = exports.getMousePos = exports.identity = exports.getGridCoord = exports.getTickCoord = exports.getBreakWord = exports.dateFormat = void 0;
9
+ exports.getDataWithPercent = exports.sortPie = exports.getDomPath = exports.filterChildren = exports.getChildren = exports.isValidHttpUrl = exports.getBandSeriesStepAndWidth = exports.getBandwidth = exports.getBandBackground = exports.getCurrentStack = exports.resetStacks = exports.seriesYOrZ = exports.dataYOrZ = exports.getStacks = exports.getColorList = exports.getIcon = exports.getTranslate2d = exports.getTranslate3d = exports.getMargin = exports.getFontStyle = exports.getMousePos = exports.identity = exports.getGridCoord = exports.getTickCoord = exports.getTicksOfAxis = exports.getBreakWord = exports.dateFormat = void 0;
10
10
 
11
11
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
12
 
@@ -169,10 +169,33 @@ exports.dateFormat = dateFormat;
169
169
  var getBreakWord = function getBreakWord(str, breakNumber) {
170
170
  var re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
171
171
  return str.match(re);
172
- };
172
+ }; //x轴标签逻辑
173
+
173
174
 
174
175
  exports.getBreakWord = getBreakWord;
175
176
 
177
+ var getTicksOfAxis = function getTicksOfAxis(domain, ticksCount, showLast) {
178
+ var len = domain.length;
179
+ if (ticksCount < 2 || ticksCount > len) return domain;
180
+ var step = Math.floor((len - ticksCount) / (ticksCount - 1));
181
+ var ticksArr = domain.filter(function (d, i) {
182
+ return i % (step + 1) === 0;
183
+ });
184
+ var Tlen = ticksArr.length;
185
+ var lastIndex = domain.findIndex(function (d) {
186
+ return d == ticksArr[Tlen - 1];
187
+ });
188
+
189
+ if (showLast) {
190
+ len % ticksCount == 0 || len - 1 - lastIndex >= Math.round(len / Tlen / 2) ? null : ticksArr.pop();
191
+ ticksArr.push(domain[len - 1]);
192
+ }
193
+
194
+ return ticksArr;
195
+ };
196
+
197
+ exports.getTicksOfAxis = getTicksOfAxis;
198
+
176
199
  var getTickCoord = function getTickCoord(_ref5) {
177
200
  var orientation = _ref5.orientation,
178
201
  coordinate = _ref5.coordinate,
@@ -768,8 +791,8 @@ exports.sortPie = sortPie;
768
791
  var getDataWithPercent = function getDataWithPercent() {
769
792
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
770
793
  var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
771
- var digits = Math.pow(10, precision); //const targetSeats = digits * 100;
772
-
794
+ var digits = Math.pow(10, precision);
795
+ var targetSeats = digits * 100;
773
796
  var total = (0, _d3v.sum)(data, function (d) {
774
797
  return d.value;
775
798
  });
@@ -782,7 +805,7 @@ var getDataWithPercent = function getDataWithPercent() {
782
805
  var currentSum = (0, _d3v.sum)(votesPerQuota, function (d) {
783
806
  return d.vote;
784
807
  });
785
- var remainder = 100 - currentSum;
808
+ var remainder = targetSeats - currentSum;
786
809
  votesPerQuota.sort(function (_ref26, _ref27) {
787
810
  var a = _ref26.value;
788
811
  var b = _ref27.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.0.70",
3
+ "version": "1.0.74",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -184,6 +184,9 @@ const Label: (props: LabelType) => ReactComponentElement<ComponentType> | null =
184
184
  return (
185
185
  <text
186
186
  className={className}
187
+ style={{
188
+ whiteSpace:"pre"
189
+ }}
187
190
  dominantBaseline={dominantBaseline}
188
191
  textAnchor={textAnchor}
189
192
  fontFamily={fontFamily}
@@ -76,7 +76,11 @@ export default memo(
76
76
  seriesIntervalWidth: paddingInner = 0,
77
77
  paddingInner: paddingOuter = 0,
78
78
  style,
79
+ fillType,
80
+ url,
81
+ size,
79
82
  fill,
83
+ opacity,
80
84
  highlight: { show: showHighlight, extent, fill: highlightFill },
81
85
  },
82
86
  bandLength = 0,
@@ -136,10 +140,17 @@ export default memo(
136
140
  style={{
137
141
  width: '100%',
138
142
  height: '100%',
139
- background: getBandBackground(
140
- pattern,
141
- extent === flag ? highlightFill : fill
142
- ),
143
+ opacity:opacity,
144
+ background:
145
+ fillType == 'pattern'
146
+ ? `50% 50% / ${size.width}px ${size.height}px repeat ` +
147
+ 'url(' +
148
+ url +
149
+ ')'
150
+ : getBandBackground(
151
+ pattern,
152
+ extent === flag ? highlightFill : fill
153
+ ),
143
154
  borderRadius:
144
155
  style == 'square'
145
156
  ? '0 0 0 0'
@@ -123,15 +123,25 @@ const Label = ({
123
123
  </text>
124
124
  );
125
125
  };
126
- const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius } }) =>
126
+ const Icon = ({ cx, cy, config: { mode, inner, outer, color, radius, image, size: { width, height } } }) =>
127
127
  mode == 'single' ? (
128
128
  <Circle cx={cx} cy={cy} color={color} radius={radius} />
129
- ) : (
129
+ ) : mode == 'double' ? (
130
130
  <>
131
131
  <Circle cx={cx} cy={cy} {...inner} />
132
132
  <Circle cx={cx} cy={cy} {...outer} />
133
133
  </>
134
+ ) : (
135
+ <>
136
+ <image
137
+ width={width}
138
+ height={height}
139
+ x={cx - width / 2}
140
+ y={cy - height / 2}
141
+ xlinkHref={window.appConfig.ASSETS_URL + image} />
142
+ </>
134
143
  );
144
+
135
145
  const Circle = ({ cx, cy, color, radius }) => (
136
146
  <circle cx={cx} cy={cy} fill={color} r={radius} stroke='none' />
137
147
  );
@@ -17,7 +17,17 @@ const getLineData = (data, connectNulls) =>
17
17
 
18
18
  const Area = ({
19
19
  data,
20
- config: { id, fill, curve, tension },
20
+ config,
21
+ config: {
22
+ id,
23
+ fill,
24
+ type,
25
+ url,
26
+ opacity,
27
+ size: { width: patternW, height: patternH },
28
+ curve,
29
+ tension
30
+ },
21
31
  xScaler,
22
32
  yScaler,
23
33
  }) => {
@@ -39,7 +49,13 @@ const Area = ({
39
49
  <>
40
50
  <path d={areaGen(data)} stroke='none' fill={'url(#' + id + ')'} />
41
51
  <defs>
42
- <LinearGradient id={id} colors={area} rotate={0} />
52
+ {type && type == 'pattern' ? (
53
+ <pattern id={id} patternUnits="userSpaceOnUse" width={patternW} height={patternH}>
54
+ {url && <image opacity={opacity} width={patternW} height={patternH} xlinkHref={window.appConfig.ASSETS_URL + url} />}
55
+ </pattern>
56
+ ) : (
57
+ <LinearGradient id={id} colors={area} rotate={0} />
58
+ )}
43
59
  </defs>
44
60
  </>
45
61
  );
@@ -1,10 +1,9 @@
1
1
  import { useMemo } from 'react';
2
2
  import { scaleLinear, scaleLog, scaleTime, scaleUtc } from 'd3-scale';
3
- import { band } from '../utils';
3
+ import { band, getTicksOfAxis } from '../utils';
4
4
  import {
5
5
  getYTicksByStep,
6
6
  getYTicks,
7
- getTicksOfAxis,
8
7
  } from '@easyv/utils/lib/common/utils';
9
8
 
10
9
  const scales = {
@@ -28,6 +27,7 @@ export default ({ axes, context: { width, height } }) => {
28
27
  const xAxisPositions = [];
29
28
  axes.forEach((item) => {
30
29
  const {
30
+ config: { label: { showLast = false } },
31
31
  type,
32
32
  orientation,
33
33
  ticks,
@@ -41,19 +41,20 @@ export default ({ axes, context: { width, height } }) => {
41
41
  carousel,
42
42
  config,
43
43
  } = item;
44
+
44
45
  const direction =
45
46
  orientation === 'top' || orientation === 'bottom'
46
47
  ? 'horizontal'
47
48
  : orientation === 'left' || orientation === 'right'
48
- ? 'vertical'
49
- : '';
49
+ ? 'vertical'
50
+ : '';
50
51
 
51
52
  const length =
52
53
  direction === 'horizontal'
53
54
  ? width
54
55
  : direction === 'vertical'
55
- ? height
56
- : 0;
56
+ ? height
57
+ : 0;
57
58
 
58
59
  const _paddingOuter = paddingOuter * length;
59
60
  const start = _paddingOuter / 2;
@@ -63,8 +64,8 @@ export default ({ axes, context: { width, height } }) => {
63
64
  direction === 'horizontal'
64
65
  ? [start, end]
65
66
  : direction === 'vertical'
66
- ? [end, start]
67
- : [0, 0];
67
+ ? [end, start]
68
+ : [0, 0];
68
69
 
69
70
  const scaler = scales[type]().domain(domain).range(range);
70
71
  scaler.type = type;
@@ -74,13 +75,13 @@ export default ({ axes, context: { width, height } }) => {
74
75
  const allTicks = ticks
75
76
  ? ticks
76
77
  : scaler.ticks
77
- ? scaler.ticks(tickCount)
78
- : scaler.domain();
78
+ ? scaler.ticks(tickCount)
79
+ : scaler.domain();
79
80
 
80
81
  let _ticks = allTicks;
81
82
  if (type === 'ordinal') {
82
83
  if (carousel === false) {
83
- _ticks = getTicksOfAxis(_ticks, +tickCount);
84
+ _ticks = getTicksOfAxis(_ticks, +tickCount, showLast);
84
85
  }
85
86
  } else {
86
87
  if (auto === false) {
@@ -86,16 +86,16 @@ const getIcon = (type, icon) => {
86
86
  case 'line':
87
87
  return icon
88
88
  ? {
89
- ...defaultLineIcon,
90
- ...icon,
91
- }
89
+ ...defaultLineIcon,
90
+ ...icon,
91
+ }
92
92
  : defaultLineIcon;
93
93
  default:
94
94
  return icon
95
95
  ? {
96
- ...defaultIcon,
97
- ...icon,
98
- }
96
+ ...defaultIcon,
97
+ ...icon,
98
+ }
99
99
  : defaultIcon;
100
100
  }
101
101
  };
@@ -141,6 +141,26 @@ const getBreakWord = (str, breakNumber) => {
141
141
  const re = new RegExp('([^]){1,' + breakNumber + '}', 'g');
142
142
  return str.match(re);
143
143
  };
144
+
145
+ //x轴标签逻辑
146
+
147
+ const getTicksOfAxis = (domain, ticksCount, showLast) => {
148
+
149
+ let len = domain.length;
150
+ if (ticksCount < 2 || ticksCount > len) return domain;
151
+ let step = Math.floor((len - ticksCount) / (ticksCount - 1));
152
+ const ticksArr = domain.filter(function (d, i) {
153
+ return i % (step + 1) === 0;
154
+ });
155
+ let Tlen = ticksArr.length;
156
+ let lastIndex = domain.findIndex(d => d == ticksArr[Tlen - 1])
157
+ if (showLast) {
158
+ len % ticksCount == 0 || (len-1) - lastIndex >= Math.round(len / Tlen / 2) ? null : ticksArr.pop()
159
+ ticksArr.push(domain[len - 1])
160
+ }
161
+ return ticksArr
162
+ }
163
+
144
164
  const getTickCoord = ({
145
165
  orientation,
146
166
  coordinate,
@@ -612,7 +632,7 @@ const sortPie = (data, order) => {
612
632
 
613
633
  const getDataWithPercent = (data = [], precision = 0) => {
614
634
  const digits = Math.pow(10, precision);
615
- //const targetSeats = digits * 100;
635
+ const targetSeats = digits * 100;
616
636
 
617
637
  const total = sum(data, (d) => d.value);
618
638
 
@@ -623,16 +643,16 @@ const getDataWithPercent = (data = [], precision = 0) => {
623
643
  }));
624
644
  const currentSum = sum(votesPerQuota, (d) => d.vote);
625
645
 
626
- let remainder = 100 - currentSum;
646
+ let remainder = targetSeats - currentSum;
627
647
  votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
628
648
 
629
649
  const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {
630
- let obj={
650
+ let obj = {
631
651
  ...data,
632
652
  value,
633
653
  percent: toFixed((vote + ((value && value != 0) ? remainder : 0)) / digits, precision),
634
654
  };
635
- if(value && value!=0){
655
+ if (value && value != 0) {
636
656
  remainder = 0
637
657
  }
638
658
  return obj
@@ -643,6 +663,7 @@ const getDataWithPercent = (data = [], precision = 0) => {
643
663
  export {
644
664
  dateFormat,
645
665
  getBreakWord,
666
+ getTicksOfAxis,
646
667
  getTickCoord,
647
668
  getGridCoord,
648
669
  identity,