cx 21.12.2 → 22.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.
package/dist/charts.js CHANGED
@@ -1037,6 +1037,150 @@ debug("The Pie class is deprecated. Please use PieChart instead.");
1037
1037
  var Pie = PieChart;
1038
1038
  Pie.Slice = PieSlice;
1039
1039
 
1040
+ var PieLabel = /*#__PURE__*/ (function(_BoundedObject) {
1041
+ _inheritsLoose(PieLabel, _BoundedObject);
1042
+
1043
+ function PieLabel() {
1044
+ return _BoundedObject.apply(this, arguments) || this;
1045
+ }
1046
+
1047
+ var _proto = PieLabel.prototype;
1048
+
1049
+ _proto.declareData = function declareData() {
1050
+ var _BoundedObject$protot;
1051
+
1052
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1053
+ args[_key] = arguments[_key];
1054
+ }
1055
+
1056
+ (_BoundedObject$protot = _BoundedObject.prototype.declareData).call.apply(
1057
+ _BoundedObject$protot,
1058
+ [this].concat(args, [
1059
+ {
1060
+ distance: undefined
1061
+ }
1062
+ ])
1063
+ );
1064
+ };
1065
+
1066
+ _proto.calculateBounds = function calculateBounds(context, instance) {
1067
+ var data = instance.data;
1068
+ var bounds = Rect.add(Rect.add(Rect.multiply(instance.parentRect, data.anchors), data.offset), data.margin);
1069
+ instance.originalBounds = bounds;
1070
+ instance.actualBounds = context.placePieLabel(bounds, data.distance);
1071
+ return new Rect({
1072
+ t: 0,
1073
+ r: bounds.width(),
1074
+ b: bounds.height(),
1075
+ l: 0
1076
+ });
1077
+ };
1078
+
1079
+ _proto.prepare = function prepare(context, instance) {
1080
+ _BoundedObject.prototype.prepare.call(this, context, instance);
1081
+
1082
+ if (!context.registerPieLabel)
1083
+ throw new Error("PieLabel components are allowed only within PieLabelsContainer components.");
1084
+ context.registerPieLabel(instance);
1085
+ };
1086
+
1087
+ _proto.render = function render(context, instance, key) {
1088
+ var originalBounds = instance.originalBounds,
1089
+ actualBounds = instance.actualBounds;
1090
+ return /*#__PURE__*/ jsxs(
1091
+ "g",
1092
+ {
1093
+ children: [
1094
+ /*#__PURE__*/ jsx("line", {
1095
+ x1: actualBounds.l < originalBounds.l ? actualBounds.r : actualBounds.l,
1096
+ y1: (actualBounds.t + actualBounds.b) / 2,
1097
+ x2: (originalBounds.l + originalBounds.r) / 2,
1098
+ y2: (originalBounds.t + originalBounds.b) / 2,
1099
+ stroke: "gray"
1100
+ }),
1101
+ /*#__PURE__*/ jsx("g", {
1102
+ transform: "translate(" + instance.actualBounds.l + " " + instance.actualBounds.t + ")",
1103
+ children: this.renderChildren(context, instance)
1104
+ })
1105
+ ]
1106
+ },
1107
+ key
1108
+ );
1109
+ };
1110
+
1111
+ return PieLabel;
1112
+ })(BoundedObject);
1113
+ PieLabel.prototype.distance = 100;
1114
+
1115
+ var PieLabelsContainer = /*#__PURE__*/ (function(_BoundedObject) {
1116
+ _inheritsLoose(PieLabelsContainer, _BoundedObject);
1117
+
1118
+ function PieLabelsContainer() {
1119
+ return _BoundedObject.apply(this, arguments) || this;
1120
+ }
1121
+
1122
+ var _proto = PieLabelsContainer.prototype;
1123
+
1124
+ _proto.prepare = function prepare(context, instance) {
1125
+ _BoundedObject.prototype.prepare.call(this, context, instance);
1126
+
1127
+ var bounds = instance.data.bounds;
1128
+ var cx2 = bounds.l + bounds.r;
1129
+ context.push("placePieLabel", function(labelBounds, distance) {
1130
+ var clone = new Rect(labelBounds);
1131
+ var w = clone.r - clone.l;
1132
+
1133
+ if (clone.l + clone.r > cx2) {
1134
+ clone.r = Math.min(clone.r + distance, bounds.r);
1135
+ clone.l = clone.r - w;
1136
+ } else {
1137
+ clone.l = Math.max(bounds.l, clone.l - distance);
1138
+ clone.r = clone.l + w;
1139
+ }
1140
+
1141
+ return clone;
1142
+ });
1143
+ instance.leftLabels = [];
1144
+ instance.rightLabels = [];
1145
+ context.push("registerPieLabel", function(label) {
1146
+ if (label.actualBounds.l + label.actualBounds.r < cx2) instance.leftLabels.push(label);
1147
+ else instance.rightLabels.push(label);
1148
+ });
1149
+ };
1150
+
1151
+ _proto.prepareCleanup = function prepareCleanup(context, instance) {
1152
+ context.pop("placePieLabel");
1153
+ context.pop("registerPieLabel");
1154
+
1155
+ _BoundedObject.prototype.prepareCleanup.call(this, context, instance);
1156
+
1157
+ this.distributeLabels(instance.leftLabels, instance);
1158
+ this.distributeLabels(instance.rightLabels, instance);
1159
+ };
1160
+
1161
+ _proto.distributeLabels = function distributeLabels(labels, instance) {
1162
+ labels.sort(function(a, b) {
1163
+ return a.actualBounds.t + a.actualBounds.b - (b.actualBounds.t + b.actualBounds.b);
1164
+ });
1165
+ var totalHeight = labels.reduce(function(h, l) {
1166
+ return h + l.actualBounds.height();
1167
+ }, 0);
1168
+ var bounds = instance.data.bounds;
1169
+ var avgHeight = Math.min(totalHeight, bounds.height()) / labels.length;
1170
+ var at = bounds.t;
1171
+
1172
+ for (var i = 0; i < labels.length; i++) {
1173
+ var ab = labels[i].actualBounds;
1174
+ ab.t = Math.max(at, Math.min(ab.t, bounds.b - (labels.length - i) * avgHeight));
1175
+ ab.b = ab.t + avgHeight;
1176
+ at = ab.b;
1177
+ }
1178
+ };
1179
+
1180
+ return PieLabelsContainer;
1181
+ })(BoundedObject);
1182
+ PieLabelsContainer.prototype.anchors = "0 1 1 0";
1183
+
1040
1184
  var ColumnBarBase = /*#__PURE__*/ (function(_PureContainer) {
1041
1185
  _inheritsLoose(ColumnBarBase, _PureContainer);
1042
1186
 
@@ -5412,6 +5556,8 @@ export {
5412
5556
  NumericAxis,
5413
5557
  Pie,
5414
5558
  PieChart,
5559
+ PieLabel,
5560
+ PieLabelsContainer,
5415
5561
  PieSlice,
5416
5562
  PointReducer,
5417
5563
  Range,