cx 21.12.4 → 22.1.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.
package/dist/charts.js CHANGED
@@ -1037,6 +1037,174 @@ 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.init = function init() {
1050
+ this.lineStyle = parseStyle(this.lineStyle);
1051
+
1052
+ _BoundedObject.prototype.init.call(this);
1053
+ };
1054
+
1055
+ _proto.declareData = function declareData() {
1056
+ var _BoundedObject$protot;
1057
+
1058
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1059
+ args[_key] = arguments[_key];
1060
+ }
1061
+
1062
+ (_BoundedObject$protot = _BoundedObject.prototype.declareData).call.apply(
1063
+ _BoundedObject$protot,
1064
+ [this].concat(args, [
1065
+ {
1066
+ distance: undefined,
1067
+ lineStyle: {
1068
+ structured: true
1069
+ },
1070
+ lineStroke: undefined,
1071
+ lineClass: {
1072
+ structured: true
1073
+ },
1074
+ lineColorIndex: undefined
1075
+ }
1076
+ ])
1077
+ );
1078
+ };
1079
+
1080
+ _proto.calculateBounds = function calculateBounds(context, instance) {
1081
+ var data = instance.data;
1082
+ var bounds = Rect.add(Rect.add(Rect.multiply(instance.parentRect, data.anchors), data.offset), data.margin);
1083
+ instance.originalBounds = bounds;
1084
+ instance.actualBounds = context.placePieLabel(bounds, data.distance);
1085
+ return new Rect({
1086
+ t: 0,
1087
+ r: bounds.width(),
1088
+ b: bounds.height(),
1089
+ l: 0
1090
+ });
1091
+ };
1092
+
1093
+ _proto.prepare = function prepare(context, instance) {
1094
+ _BoundedObject.prototype.prepare.call(this, context, instance);
1095
+
1096
+ if (!context.registerPieLabel)
1097
+ throw new Error("PieLabel components are allowed only within PieLabelsContainer components.");
1098
+ context.registerPieLabel(instance);
1099
+ };
1100
+
1101
+ _proto.render = function render(context, instance, key) {
1102
+ var originalBounds = instance.originalBounds,
1103
+ actualBounds = instance.actualBounds,
1104
+ data = instance.data;
1105
+ return /*#__PURE__*/ jsxs(
1106
+ "g",
1107
+ {
1108
+ className: data.classNames,
1109
+ children: [
1110
+ /*#__PURE__*/ jsx("line", {
1111
+ className: this.CSS.element(
1112
+ this.baseClass,
1113
+ "line",
1114
+ data.lineColorIndex != null && "color-" + data.lineColorIndex
1115
+ ),
1116
+ x1: actualBounds.l < originalBounds.l ? actualBounds.r : actualBounds.l,
1117
+ y1: (actualBounds.t + actualBounds.b) / 2,
1118
+ x2: (originalBounds.l + originalBounds.r) / 2,
1119
+ y2: (originalBounds.t + originalBounds.b) / 2,
1120
+ stroke: data.lineStroke,
1121
+ style: data.lineStyle
1122
+ }),
1123
+ /*#__PURE__*/ jsx("g", {
1124
+ transform: "translate(" + instance.actualBounds.l + " " + instance.actualBounds.t + ")",
1125
+ children: this.renderChildren(context, instance)
1126
+ })
1127
+ ]
1128
+ },
1129
+ key
1130
+ );
1131
+ };
1132
+
1133
+ return PieLabel;
1134
+ })(BoundedObject);
1135
+ PieLabel.prototype.distance = 100;
1136
+ PieLabel.prototype.baseClass = "pielabel";
1137
+ PieLabel.prototype.styled = true;
1138
+
1139
+ var PieLabelsContainer = /*#__PURE__*/ (function(_BoundedObject) {
1140
+ _inheritsLoose(PieLabelsContainer, _BoundedObject);
1141
+
1142
+ function PieLabelsContainer() {
1143
+ return _BoundedObject.apply(this, arguments) || this;
1144
+ }
1145
+
1146
+ var _proto = PieLabelsContainer.prototype;
1147
+
1148
+ _proto.prepare = function prepare(context, instance) {
1149
+ _BoundedObject.prototype.prepare.call(this, context, instance);
1150
+
1151
+ var bounds = instance.data.bounds;
1152
+ var cx2 = bounds.l + bounds.r;
1153
+ context.push("placePieLabel", function(labelBounds, distance) {
1154
+ var clone = new Rect(labelBounds);
1155
+ var w = clone.r - clone.l;
1156
+
1157
+ if (clone.l + clone.r > cx2) {
1158
+ clone.r = Math.min(clone.r + distance, bounds.r);
1159
+ clone.l = clone.r - w;
1160
+ } else {
1161
+ clone.l = Math.max(bounds.l, clone.l - distance);
1162
+ clone.r = clone.l + w;
1163
+ }
1164
+
1165
+ return clone;
1166
+ });
1167
+ instance.leftLabels = [];
1168
+ instance.rightLabels = [];
1169
+ context.push("registerPieLabel", function(label) {
1170
+ if (label.actualBounds.l + label.actualBounds.r < cx2) instance.leftLabels.push(label);
1171
+ else instance.rightLabels.push(label);
1172
+ });
1173
+ };
1174
+
1175
+ _proto.prepareCleanup = function prepareCleanup(context, instance) {
1176
+ context.pop("placePieLabel");
1177
+ context.pop("registerPieLabel");
1178
+
1179
+ _BoundedObject.prototype.prepareCleanup.call(this, context, instance);
1180
+
1181
+ this.distributeLabels(instance.leftLabels, instance);
1182
+ this.distributeLabels(instance.rightLabels, instance);
1183
+ };
1184
+
1185
+ _proto.distributeLabels = function distributeLabels(labels, instance) {
1186
+ labels.sort(function(a, b) {
1187
+ return a.actualBounds.t + a.actualBounds.b - (b.actualBounds.t + b.actualBounds.b);
1188
+ });
1189
+ var totalHeight = labels.reduce(function(h, l) {
1190
+ return h + l.actualBounds.height();
1191
+ }, 0);
1192
+ var bounds = instance.data.bounds;
1193
+ var avgHeight = Math.min(totalHeight, bounds.height()) / labels.length;
1194
+ var at = bounds.t;
1195
+
1196
+ for (var i = 0; i < labels.length; i++) {
1197
+ var ab = labels[i].actualBounds;
1198
+ ab.t = Math.max(at, Math.min(ab.t, bounds.b - (labels.length - i) * avgHeight));
1199
+ ab.b = ab.t + avgHeight;
1200
+ at = ab.b;
1201
+ }
1202
+ };
1203
+
1204
+ return PieLabelsContainer;
1205
+ })(BoundedObject);
1206
+ PieLabelsContainer.prototype.anchors = "0 1 1 0";
1207
+
1040
1208
  var ColumnBarBase = /*#__PURE__*/ (function(_PureContainer) {
1041
1209
  _inheritsLoose(ColumnBarBase, _PureContainer);
1042
1210
 
@@ -5412,6 +5580,8 @@ export {
5412
5580
  NumericAxis,
5413
5581
  Pie,
5414
5582
  PieChart,
5583
+ PieLabel,
5584
+ PieLabelsContainer,
5415
5585
  PieSlice,
5416
5586
  PointReducer,
5417
5587
  Range,