awing-library 2.1.39 → 2.1.40

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.
@@ -15,6 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var jsx_runtime_1 = require("react/jsx-runtime");
18
+ var material_1 = require("@mui/material");
18
19
  var Helpers_1 = require("../../Utils/Helpers");
19
20
  require("chartjs-adapter-moment");
20
21
  var moment_1 = __importDefault(require("moment"));
@@ -73,6 +74,10 @@ var BarLineComponent = function (props) {
73
74
  lineHeight: 1.5,
74
75
  },
75
76
  },
77
+ htmlLegend: {
78
+ // ID of the container to put the legend in
79
+ containerID: 'legend-container',
80
+ },
76
81
  legend: {
77
82
  position: 'bottom',
78
83
  labels: {
@@ -88,7 +93,7 @@ var BarLineComponent = function (props) {
88
93
  lineHeight: 1.5,
89
94
  },
90
95
  },
91
- display: true,
96
+ display: false,
92
97
  },
93
98
  },
94
99
  scales: {
@@ -182,10 +187,83 @@ var BarLineComponent = function (props) {
182
187
  }),
183
188
  };
184
189
  var Chart = chart;
185
- return ((0, jsx_runtime_1.jsx)("div", { style: {
190
+ var getOrCreateLegendList = function (chart, id) {
191
+ var legendContainer = document.getElementById(id);
192
+ var listContainer = legendContainer === null || legendContainer === void 0 ? void 0 : legendContainer.querySelector('ul');
193
+ if (!listContainer) {
194
+ listContainer = document.createElement('ul');
195
+ listContainer.style.display = 'flex';
196
+ listContainer.style.flexDirection = 'row';
197
+ listContainer.style.margin = '0';
198
+ listContainer.style.padding = '0';
199
+ legendContainer === null || legendContainer === void 0 ? void 0 : legendContainer.appendChild(listContainer);
200
+ }
201
+ return listContainer;
202
+ };
203
+ var htmlLegendPlugin = {
204
+ id: 'htmlLegend',
205
+ afterUpdate: function (chart, args, options) {
206
+ var ul = getOrCreateLegendList(chart, options.containerID);
207
+ // Remove old legend items
208
+ while (ul.firstChild) {
209
+ ul.firstChild.remove();
210
+ }
211
+ // Reuse the built-in legendItems generator
212
+ var items = chart.options.plugins.legend.labels.generateLabels(chart);
213
+ items.forEach(function (item) {
214
+ var li = document.createElement('li');
215
+ li.style.alignItems = 'center';
216
+ li.style.cursor = 'pointer';
217
+ li.style.display = 'flex';
218
+ li.style.flexDirection = 'row';
219
+ li.style.marginLeft = '10px';
220
+ li.onclick = function () {
221
+ var type = chart.config.type;
222
+ if (type === 'pie' || type === 'doughnut') {
223
+ // Pie and doughnut charts only have a single dataset and visibility is per item
224
+ chart.toggleDataVisibility(item.index);
225
+ }
226
+ else {
227
+ chart.setDatasetVisibility(item.datasetIndex, !chart.isDatasetVisible(item.datasetIndex));
228
+ }
229
+ chart.update();
230
+ };
231
+ // Color box
232
+ var boxSpan = document.createElement('span');
233
+ boxSpan.style.background = item.fillStyle;
234
+ boxSpan.style.borderColor = item.strokeStyle;
235
+ boxSpan.style.borderWidth = item.lineWidth + 'px';
236
+ boxSpan.style.display = 'inline-block';
237
+ boxSpan.style.flexShrink = '0';
238
+ boxSpan.style.height = '20px';
239
+ boxSpan.style.marginRight = '10px';
240
+ boxSpan.style.width = '20px';
241
+ boxSpan.style.borderRadius = '20px';
242
+ // Text
243
+ var textContainer = document.createElement('p');
244
+ textContainer.style.color = item.fontColor;
245
+ textContainer.style.margin = '0';
246
+ textContainer.style.padding = '0';
247
+ textContainer.style.textDecoration = item.hidden
248
+ ? 'line-through'
249
+ : '';
250
+ var text = document.createTextNode(item.text);
251
+ textContainer.appendChild(text);
252
+ li.appendChild(boxSpan);
253
+ li.appendChild(textContainer);
254
+ ul.appendChild(li);
255
+ });
256
+ },
257
+ };
258
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
186
259
  width: width,
187
260
  height: height,
188
261
  position: 'relative',
189
- }, children: (0, jsx_runtime_1.jsx)(Chart, { data: chartData, type: type, options: (0, Helpers_1.updateObjectFields)(options, optionCustom) }) }));
262
+ marginBottom: '80px',
263
+ }, children: [(0, jsx_runtime_1.jsx)(Chart, { data: chartData, type: type, options: (0, Helpers_1.updateObjectFields)(options, optionCustom), plugins: [htmlLegendPlugin] }), (0, jsx_runtime_1.jsx)(material_1.Box, { id: "legend-container", sx: {
264
+ marginTop: '35px',
265
+ display: 'flex',
266
+ justifyContent: 'center',
267
+ } })] }));
190
268
  };
191
269
  exports.default = BarLineComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.39",
3
+ "version": "2.1.40",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",