@easyv/charts 1.0.67 → 1.0.71

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.
@@ -194,7 +194,7 @@ var Label = function Label(_ref5) {
194
194
  letterSpacing: letterSpacing,
195
195
  dx: "0",
196
196
  dy: "0",
197
- transform: Array.isArray(_label) ? rotate !== 0 ? isVertical ? translateText + 'rotate(' + rotate + ')' : 'rotate(' + rotate + ', ' + x + ', ' + y + ')' : isVertical ? translateText : translateText : translateText + 'rotate(' + rotate + ')'
197
+ transform: Array.isArray(_label) ? rotate !== 0 ? isVertical ? translateText + 'rotate(' + rotate + ')' : 'rotate(' + rotate + ', ' + x + ', ' + y + ')' : isVertical ? translateText : 'translate(' + translateX + ', ' + translateY + ')' : translateText + 'rotate(' + rotate + ')'
198
198
  }, !!Array.isArray(_label) ? _label.map(function (item, index) {
199
199
  return /*#__PURE__*/_react["default"].createElement("tspan", {
200
200
  key: index,
@@ -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) {
@@ -887,7 +887,7 @@ var Label = function Label(_ref10) {
887
887
 
888
888
  var _showValue = showValue && (value || showSuffix);
889
889
 
890
- return show && (_showName || showPercent || _showValue) && /*#__PURE__*/_react["default"].createElement("g", {
890
+ return show && (_showName || showPercent || showValue) && /*#__PURE__*/_react["default"].createElement("g", {
891
891
  key: index
892
892
  }, /*#__PURE__*/_react["default"].createElement("path", {
893
893
  className: animation ? _piechartModule["default"]['label-line'] : "",
@@ -908,7 +908,7 @@ var Label = function Label(_ref10) {
908
908
  textAnchor: x3 >= 0 ? 'start' : 'end'
909
909
  }, _showName && /*#__PURE__*/_react["default"].createElement("tspan", {
910
910
  style: (0, _utils.getFontStyle)(nameFont, 'svg')
911
- }, displayName + (showValue || showPercent ? ':' : '')), _showValue && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("tspan", {
911
+ }, displayName + (showValue || showPercent ? ':' : '')), showValue && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("tspan", {
912
912
  x: !!(_showName && mode == 'vertical') ? _x : '',
913
913
  dx: valueDx(_showName, mode),
914
914
  dy: !!(_showName && mode == 'vertical') ? '1.5em' : '',
@@ -73,7 +73,7 @@ var pieLegendFormatter = function pieLegendFormatter(_ref, _ref2) {
73
73
  alignItems: 'center',
74
74
  justifyContent: 'flex-start'
75
75
  })
76
- }, showValue && /*#__PURE__*/React.createElement("span", null, data.y), showSuffix && /*#__PURE__*/React.createElement("span", {
76
+ }, /*#__PURE__*/React.createElement("span", null, data.y), showSuffix && /*#__PURE__*/React.createElement("span", {
77
77
  style: {
78
78
  whiteSpace: "nowrap",
79
79
  fontSize: fontSize,
@@ -742,15 +742,34 @@ var sortPie = function sortPie(data, order) {
742
742
  }
743
743
 
744
744
  return _data;
745
- };
745
+ }; // const getDataWithPercent = (data = [], precision = 0, type) => {
746
+ // const digits = Math.pow(10, precision);
747
+ // const targetSeats = digits * 100;
748
+ // const total = sum(data, (d) => d.value);
749
+ // const votesPerQuota = data.map((d, index) => ({
750
+ // ...d,
751
+ // vote: Math.round((d.value / total) * digits * 100),
752
+ // index,
753
+ // }));
754
+ // const currentSum = sum(votesPerQuota, (d) => d.vote);
755
+ // const remainder = targetSeats - currentSum;
756
+ // console.log(type+":",votesPerQuota, toFixed);
757
+ // votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
758
+ // const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
759
+ // ...data,
760
+ // percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
761
+ // }));
762
+ // return tmp;
763
+ // };
764
+
746
765
 
747
766
  exports.sortPie = sortPie;
748
767
 
749
768
  var getDataWithPercent = function getDataWithPercent() {
750
769
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
751
770
  var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
752
- var digits = Math.pow(10, precision);
753
- var targetSeats = digits * 100;
771
+ var digits = Math.pow(10, precision); //const targetSeats = digits * 100;
772
+
754
773
  var total = (0, _d3v.sum)(data, function (d) {
755
774
  return d.value;
756
775
  });
@@ -763,7 +782,7 @@ var getDataWithPercent = function getDataWithPercent() {
763
782
  var currentSum = (0, _d3v.sum)(votesPerQuota, function (d) {
764
783
  return d.vote;
765
784
  });
766
- var remainder = targetSeats - currentSum;
785
+ var remainder = 100 - currentSum;
767
786
  votesPerQuota.sort(function (_ref26, _ref27) {
768
787
  var a = _ref26.value;
769
788
  var b = _ref27.value;
@@ -771,10 +790,19 @@ var getDataWithPercent = function getDataWithPercent() {
771
790
  });
772
791
  var tmp = votesPerQuota.map(function (_ref28, index) {
773
792
  var vote = _ref28.vote,
774
- data = (0, _objectWithoutProperties2["default"])(_ref28, ["vote"]);
775
- return _objectSpread(_objectSpread({}, data), {}, {
776
- percent: (0, _utils2.toFixed)((vote + (index < remainder ? 1 : 0)) / digits, precision)
793
+ value = _ref28.value,
794
+ data = (0, _objectWithoutProperties2["default"])(_ref28, ["vote", "value"]);
795
+
796
+ var obj = _objectSpread(_objectSpread({}, data), {}, {
797
+ value: value,
798
+ percent: (0, _utils2.toFixed)((vote + (value && value != 0 ? remainder : 0)) / digits, precision)
777
799
  });
800
+
801
+ if (value && value != 0) {
802
+ remainder = 0;
803
+ }
804
+
805
+ return obj;
778
806
  });
779
807
  return tmp;
780
808
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.0.67",
3
+ "version": "1.0.71",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -180,7 +180,7 @@ const Label: (props: LabelType) => ReactComponentElement<ComponentType> | null =
180
180
  translateY * directionY;
181
181
 
182
182
  const translateText = 'translate(' + x + ', ' + y + ')';
183
-
183
+
184
184
  return (
185
185
  <text
186
186
  className={className}
@@ -202,7 +202,7 @@ const Label: (props: LabelType) => ReactComponentElement<ComponentType> | null =
202
202
  : 'rotate(' + rotate + ', ' + x + ', ' + y + ')'
203
203
  : isVertical
204
204
  ? translateText
205
- : translateText
205
+ : 'translate(' + translateX + ', ' + translateY + ')'
206
206
  : translateText + 'rotate(' + rotate + ')'
207
207
  }
208
208
  >
@@ -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
  );
@@ -861,7 +861,7 @@ const Label = ({
861
861
 
862
862
  return (
863
863
  show &&
864
- (_showName || showPercent || _showValue) && (
864
+ (_showName || showPercent || showValue) && (
865
865
  <g key={index}>
866
866
  <path
867
867
  className={animation? ringCss['label-line']:""}
@@ -887,7 +887,7 @@ const Label = ({
887
887
  {displayName + (showValue || showPercent ? ':' : '')}
888
888
  </tspan>
889
889
  )}
890
- {_showValue && (
890
+ {showValue && (
891
891
  <>
892
892
  <tspan
893
893
  x={!!(_showName && mode == 'vertical') ? _x : ''}
@@ -58,7 +58,7 @@ export const pieLegendFormatter = (
58
58
  justifyContent: 'flex-start',
59
59
  }}
60
60
  >
61
- {showValue && <span>{data.y}</span>}
61
+ <span>{data.y}</span>
62
62
  {showSuffix && (
63
63
  <span
64
64
  style={{
@@ -586,9 +586,33 @@ const sortPie = (data, order) => {
586
586
  return _data;
587
587
  };
588
588
 
589
+ // const getDataWithPercent = (data = [], precision = 0, type) => {
590
+ // const digits = Math.pow(10, precision);
591
+ // const targetSeats = digits * 100;
592
+
593
+ // const total = sum(data, (d) => d.value);
594
+
595
+ // const votesPerQuota = data.map((d, index) => ({
596
+ // ...d,
597
+ // vote: Math.round((d.value / total) * digits * 100),
598
+ // index,
599
+ // }));
600
+ // const currentSum = sum(votesPerQuota, (d) => d.vote);
601
+ // const remainder = targetSeats - currentSum;
602
+ // console.log(type+":",votesPerQuota, toFixed);
603
+ // votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
604
+
605
+ // const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
606
+ // ...data,
607
+ // percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
608
+ // }));
609
+
610
+ // return tmp;
611
+ // };
612
+
589
613
  const getDataWithPercent = (data = [], precision = 0) => {
590
614
  const digits = Math.pow(10, precision);
591
- const targetSeats = digits * 100;
615
+ //const targetSeats = digits * 100;
592
616
 
593
617
  const total = sum(data, (d) => d.value);
594
618
 
@@ -598,17 +622,24 @@ const getDataWithPercent = (data = [], precision = 0) => {
598
622
  index,
599
623
  }));
600
624
  const currentSum = sum(votesPerQuota, (d) => d.vote);
601
- const remainder = targetSeats - currentSum;
602
625
 
626
+ let remainder = 100 - currentSum;
603
627
  votesPerQuota.sort(({ value: a }, { value: b }) => (a % total) - (b % total));
604
628
 
605
- const tmp = votesPerQuota.map(({ vote, ...data }, index) => ({
606
- ...data,
607
- percent: toFixed((vote + (index < remainder ? 1 : 0)) / digits, precision),
608
- }));
609
-
629
+ const tmp = votesPerQuota.map(({ vote, value, ...data }, index) => {
630
+ let obj={
631
+ ...data,
632
+ value,
633
+ percent: toFixed((vote + ((value && value != 0) ? remainder : 0)) / digits, precision),
634
+ };
635
+ if(value && value!=0){
636
+ remainder = 0
637
+ }
638
+ return obj
639
+ });
610
640
  return tmp;
611
641
  };
642
+
612
643
  export {
613
644
  dateFormat,
614
645
  getBreakWord,