dp-widgets-framework 1.3.4 → 1.3.6

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/index.esm.js CHANGED
@@ -17,6 +17,7 @@ import { v4 } from 'uuid';
17
17
  import { CopilotKit, useCopilotContext, useCoAgent, useCopilotChat } from '@copilotkit/react-core';
18
18
  import { CopilotChat } from '@copilotkit/react-ui';
19
19
  import ChartDataLabels from 'chartjs-plugin-datalabels';
20
+ import ChartPieChartOutlabels from '@energiency/chartjs-plugin-piechart-outlabels';
20
21
  import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
21
22
  import * as DialogPrimitive from '@radix-ui/react-dialog';
22
23
 
@@ -15038,7 +15039,7 @@ const Line = /* #__PURE__ */ createTypedChart('line', LineController);
15038
15039
  const Bar = /* #__PURE__ */ createTypedChart('bar', BarController);
15039
15040
  const Pie = /* #__PURE__ */ createTypedChart('pie', PieController);
15040
15041
 
15041
- Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15042
+ Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
15042
15043
  function BarChart({ orientation, title, data, options, className, units, content }) {
15043
15044
  const formatValue = (value) => {
15044
15045
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15047,6 +15048,26 @@ function BarChart({ orientation, title, data, options, className, units, content
15047
15048
  }
15048
15049
  return value;
15049
15050
  };
15051
+ const barValuePlugin = {
15052
+ id: "barValuePlugin",
15053
+ afterDatasetsDraw(chart) {
15054
+ if (!(content === null || content === void 0 ? void 0 : content.showLabels))
15055
+ return;
15056
+ const { ctx } = chart;
15057
+ chart.data.datasets.forEach((dataset, i) => {
15058
+ const meta = chart.getDatasetMeta(i);
15059
+ meta.data.forEach((bar, index) => {
15060
+ const value = dataset.data[index];
15061
+ ctx.save();
15062
+ ctx.font = "12px sans-serif";
15063
+ ctx.textAlign = "center";
15064
+ ctx.fillStyle = "black";
15065
+ ctx.fillText(value, bar.x, bar.y - 5);
15066
+ ctx.restore();
15067
+ });
15068
+ });
15069
+ },
15070
+ };
15050
15071
  const defaultOptions = {
15051
15072
  responsive: true,
15052
15073
  maintainAspectRatio: false,
@@ -15069,13 +15090,7 @@ function BarChart({ orientation, title, data, options, className, units, content
15069
15090
  position: "bottom"
15070
15091
  },
15071
15092
  datalabels: {
15072
- display: (context) => { var _a; return context.dataset.data[context.dataIndex] !== null && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false); },
15073
- color: "white",
15074
- anchor: "center",
15075
- align: "center",
15076
- offset: 0,
15077
- font: { size: 12 },
15078
- formatter: (value) => value,
15093
+ display: false,
15079
15094
  },
15080
15095
  title: {
15081
15096
  display: true,
@@ -15116,18 +15131,47 @@ function BarChart({ orientation, title, data, options, className, units, content
15116
15131
  },
15117
15132
  },
15118
15133
  };
15119
- return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15134
+ return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [barValuePlugin] }));
15120
15135
  }
15121
15136
 
15122
- Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15137
+ Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
15123
15138
  function SeriesChart({ orientation, title, data, options, className, units, content }) {
15139
+ var _a, _b;
15124
15140
  const formatValue = (value) => {
15125
15141
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
15126
- if (units === '$' && !isNaN(numValue)) {
15142
+ if (!isNaN(numValue)) {
15127
15143
  return numValue.toLocaleString();
15128
15144
  }
15129
15145
  return value;
15130
15146
  };
15147
+ const barValuePlugin = {
15148
+ id: "barValuePlugin",
15149
+ afterDatasetsDraw(chart) {
15150
+ if (!(content === null || content === void 0 ? void 0 : content.showLabels))
15151
+ return;
15152
+ const { ctx } = chart;
15153
+ chart.data.datasets.forEach((dataset, i) => {
15154
+ const meta = chart.getDatasetMeta(i);
15155
+ meta.data.forEach((bar, index) => {
15156
+ const value = dataset.data[index];
15157
+ ctx.save();
15158
+ ctx.font = "12px sans-serif";
15159
+ ctx.textAlign = "center";
15160
+ ctx.fillStyle = "black";
15161
+ ctx.fillText(value, bar.x, bar.y - 5);
15162
+ ctx.restore();
15163
+ });
15164
+ });
15165
+ },
15166
+ };
15167
+ const getAxisLabel = (symbol) => {
15168
+ const labelMap = {
15169
+ "%": "Percentage",
15170
+ "$": "Cost",
15171
+ "#": "Count",
15172
+ };
15173
+ return labelMap[symbol] || symbol; // fallback if not found
15174
+ };
15131
15175
  const defaultOptions = {
15132
15176
  responsive: true,
15133
15177
  maintainAspectRatio: false,
@@ -15142,7 +15186,13 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15142
15186
  },
15143
15187
  plugins: {
15144
15188
  legend: {
15145
- display: true,
15189
+ display: (ctx) => {
15190
+ const chart = ctx.chart;
15191
+ const datasets = chart.data.datasets;
15192
+ if (datasets.length > 1)
15193
+ return true;
15194
+ return false;
15195
+ },
15146
15196
  labels: {
15147
15197
  boxWidth: 12,
15148
15198
  boxHeight: 12,
@@ -15150,13 +15200,7 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15150
15200
  position: "bottom"
15151
15201
  },
15152
15202
  datalabels: {
15153
- display: (context) => { var _a; return context.dataset.data[context.dataIndex] !== null && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false); },
15154
- color: "white",
15155
- anchor: "center",
15156
- align: "center",
15157
- offset: 0,
15158
- font: { size: 12 },
15159
- formatter: (value) => value,
15203
+ display: false,
15160
15204
  },
15161
15205
  title: {
15162
15206
  display: true,
@@ -15181,30 +15225,43 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15181
15225
  ticks: { autoSkip: false, maxRotation: 45, minRotation: 0 },
15182
15226
  },
15183
15227
  y: {
15228
+ title: {
15229
+ display: true,
15230
+ text: (data === null || data === void 0 ? void 0 : data.datasets) && ((_a = data === null || data === void 0 ? void 0 : data.datasets) === null || _a === void 0 ? void 0 : _a.length) === 1 ? (_b = data === null || data === void 0 ? void 0 : data.datasets) === null || _b === void 0 ? void 0 : _b[0].label : getAxisLabel(units !== null && units !== void 0 ? units : ""),
15231
+ },
15184
15232
  beginAtZero: true,
15185
15233
  ticks: {
15186
15234
  callback: function (value) {
15187
15235
  if (units === '$') {
15188
15236
  return `${units}${formatValue(value)}`;
15189
15237
  }
15190
- return units ? `${formatValue(value)} ${units}` : value;
15238
+ return units ? `${formatValue(value)} ${(units === null || units === void 0 ? void 0 : units.length) < 3 ? units : ""}` : value;
15191
15239
  }
15192
15240
  }
15193
15241
  },
15194
15242
  },
15195
15243
  };
15196
- return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15244
+ return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [barValuePlugin] }));
15197
15245
  }
15198
15246
 
15199
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15247
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15200
15248
  function SeriesLineChart({ orientation, title, data, options, className, units, content }) {
15249
+ var _a, _b;
15201
15250
  const formatValue = (value) => {
15202
15251
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
15203
- if (units === '$' && !isNaN(numValue)) {
15252
+ if (!isNaN(numValue)) {
15204
15253
  return numValue.toLocaleString();
15205
15254
  }
15206
15255
  return value;
15207
15256
  };
15257
+ const getAxisLabel = (symbol) => {
15258
+ const labelMap = {
15259
+ "%": "Percentage",
15260
+ "$": "Cost",
15261
+ "#": "Count",
15262
+ };
15263
+ return labelMap[symbol] || symbol; // fallback if not found
15264
+ };
15208
15265
  const defaultOptions = {
15209
15266
  responsive: true,
15210
15267
  maintainAspectRatio: false,
@@ -15218,7 +15275,13 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15218
15275
  },
15219
15276
  plugins: {
15220
15277
  legend: {
15221
- display: true,
15278
+ display: (ctx) => {
15279
+ const chart = ctx.chart;
15280
+ const datasets = chart.data.datasets;
15281
+ if (datasets.length > 1)
15282
+ return true;
15283
+ return false;
15284
+ },
15222
15285
  labels: {
15223
15286
  boxWidth: 12,
15224
15287
  boxHeight: 12,
@@ -15261,6 +15324,10 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15261
15324
  ticks: { autoSkip: true, maxTicksLimit: 8, maxRotation: 45, minRotation: 0 },
15262
15325
  },
15263
15326
  y: {
15327
+ title: {
15328
+ display: true,
15329
+ text: (data === null || data === void 0 ? void 0 : data.datasets) && ((_a = data === null || data === void 0 ? void 0 : data.datasets) === null || _a === void 0 ? void 0 : _a.length) === 1 ? (_b = data === null || data === void 0 ? void 0 : data.datasets) === null || _b === void 0 ? void 0 : _b[0].label : getAxisLabel(units !== null && units !== void 0 ? units : ""),
15330
+ },
15264
15331
  beginAtZero: true,
15265
15332
  ticks: {
15266
15333
  callback: function (value) {
@@ -15278,10 +15345,10 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15278
15345
  },
15279
15346
  },
15280
15347
  };
15281
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15348
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15282
15349
  }
15283
15350
 
15284
- Chart$1.register(ArcElement, plugin_tooltip, plugin_legend, ChartDataLabels);
15351
+ Chart$1.register(ArcElement, plugin_tooltip, plugin_legend);
15285
15352
  const PieChart = (props) => {
15286
15353
  const { data, title, options, units, content } = props;
15287
15354
  const formatValue = (value) => {
@@ -15291,8 +15358,6 @@ const PieChart = (props) => {
15291
15358
  }
15292
15359
  return value;
15293
15360
  };
15294
- // Sanitize data to prevent null/undefined values
15295
- const sanitizedData = Object.assign(Object.assign({}, data), { datasets: data.datasets.map(dataset => (Object.assign(Object.assign({}, dataset), { data: dataset.data.map(d => d === null || d === undefined || isNaN(Number(d)) ? 0 : d) }))) });
15296
15361
  const defaultOptions = {
15297
15362
  responsive: true,
15298
15363
  maintainAspectRatio: false,
@@ -15304,20 +15369,35 @@ const PieChart = (props) => {
15304
15369
  },
15305
15370
  position: "bottom",
15306
15371
  },
15307
- datalabels: {
15308
- display: (context) => {
15372
+ outlabels: {
15373
+ display: (context) => { var _a; return context.dataset.data[context.dataIndex] !== null && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false); },
15374
+ text: (ctx) => {
15309
15375
  var _a;
15310
- const value = context.dataset.data[context.dataIndex];
15311
- return value !== null && value !== undefined && !isNaN(Number(value)) && value !== 0 && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false);
15376
+ const dataset = ctx.dataset.data;
15377
+ const total = dataset.reduce((a, b) => a + b, 0);
15378
+ const value = dataset[ctx.dataIndex];
15379
+ const percent = (value / total) * 100;
15380
+ // Only show if >= 5%
15381
+ return percent >= 5 ? `${(_a = ctx.chart.data.labels) === null || _a === void 0 ? void 0 : _a[ctx.dataIndex]} ${value}` : "";
15312
15382
  },
15313
- color: "white",
15314
- font: { size: 12 },
15315
- formatter: (value) => {
15316
- if (value === null || value === undefined || isNaN(Number(value)))
15317
- return '';
15318
- return formatValue(value);
15383
+ color: "black",
15384
+ stretch: 15,
15385
+ font: {
15386
+ resizable: true,
15387
+ minSize: 12,
15388
+ maxSize: 18,
15389
+ },
15390
+ backgroundColor: (ctx) => {
15391
+ const dataset = ctx.dataset.data;
15392
+ const total = dataset.reduce((a, b) => a + b, 0);
15393
+ const value = dataset[ctx.dataIndex];
15394
+ const percent = (value / total) * 100;
15395
+ return percent >= 5 ? "rgba(255,255,255,0.7)" : "transparent";
15319
15396
  },
15320
15397
  },
15398
+ datalabels: {
15399
+ display: false
15400
+ },
15321
15401
  title: {
15322
15402
  display: true,
15323
15403
  text: title,
@@ -15345,10 +15425,10 @@ const PieChart = (props) => {
15345
15425
  },
15346
15426
  },
15347
15427
  };
15348
- return jsxRuntimeExports.jsx(Pie, { data: sanitizedData, options: options !== null && options !== void 0 ? options : defaultOptions });
15428
+ return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartPieChartOutlabels] });
15349
15429
  };
15350
15430
 
15351
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15431
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15352
15432
  function LineChart({ title, data, options, className, units, content }) {
15353
15433
  const formatValue = (value) => {
15354
15434
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15422,7 +15502,7 @@ function LineChart({ title, data, options, className, units, content }) {
15422
15502
  },
15423
15503
  },
15424
15504
  };
15425
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15505
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15426
15506
  }
15427
15507
 
15428
15508
  function DataGrid({ title, data, className }) {
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var uuid = require('uuid');
18
18
  var reactCore = require('@copilotkit/react-core');
19
19
  var reactUi = require('@copilotkit/react-ui');
20
20
  var ChartDataLabels = require('chartjs-plugin-datalabels');
21
+ var ChartPieChartOutlabels = require('@energiency/chartjs-plugin-piechart-outlabels');
21
22
  var CheckboxPrimitive = require('@radix-ui/react-checkbox');
22
23
  var DialogPrimitive = require('@radix-ui/react-dialog');
23
24
 
@@ -15065,7 +15066,7 @@ const Line = /* #__PURE__ */ createTypedChart('line', LineController);
15065
15066
  const Bar = /* #__PURE__ */ createTypedChart('bar', BarController);
15066
15067
  const Pie = /* #__PURE__ */ createTypedChart('pie', PieController);
15067
15068
 
15068
- Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15069
+ Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
15069
15070
  function BarChart({ orientation, title, data, options, className, units, content }) {
15070
15071
  const formatValue = (value) => {
15071
15072
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15074,6 +15075,26 @@ function BarChart({ orientation, title, data, options, className, units, content
15074
15075
  }
15075
15076
  return value;
15076
15077
  };
15078
+ const barValuePlugin = {
15079
+ id: "barValuePlugin",
15080
+ afterDatasetsDraw(chart) {
15081
+ if (!(content === null || content === void 0 ? void 0 : content.showLabels))
15082
+ return;
15083
+ const { ctx } = chart;
15084
+ chart.data.datasets.forEach((dataset, i) => {
15085
+ const meta = chart.getDatasetMeta(i);
15086
+ meta.data.forEach((bar, index) => {
15087
+ const value = dataset.data[index];
15088
+ ctx.save();
15089
+ ctx.font = "12px sans-serif";
15090
+ ctx.textAlign = "center";
15091
+ ctx.fillStyle = "black";
15092
+ ctx.fillText(value, bar.x, bar.y - 5);
15093
+ ctx.restore();
15094
+ });
15095
+ });
15096
+ },
15097
+ };
15077
15098
  const defaultOptions = {
15078
15099
  responsive: true,
15079
15100
  maintainAspectRatio: false,
@@ -15096,13 +15117,7 @@ function BarChart({ orientation, title, data, options, className, units, content
15096
15117
  position: "bottom"
15097
15118
  },
15098
15119
  datalabels: {
15099
- display: (context) => { var _a; return context.dataset.data[context.dataIndex] !== null && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false); },
15100
- color: "white",
15101
- anchor: "center",
15102
- align: "center",
15103
- offset: 0,
15104
- font: { size: 12 },
15105
- formatter: (value) => value,
15120
+ display: false,
15106
15121
  },
15107
15122
  title: {
15108
15123
  display: true,
@@ -15143,18 +15158,47 @@ function BarChart({ orientation, title, data, options, className, units, content
15143
15158
  },
15144
15159
  },
15145
15160
  };
15146
- return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15161
+ return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [barValuePlugin] }));
15147
15162
  }
15148
15163
 
15149
- Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15164
+ Chart$1.register(CategoryScale, LinearScale, BarElement, plugin_title, plugin_tooltip, plugin_legend);
15150
15165
  function SeriesChart({ orientation, title, data, options, className, units, content }) {
15166
+ var _a, _b;
15151
15167
  const formatValue = (value) => {
15152
15168
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
15153
- if (units === '$' && !isNaN(numValue)) {
15169
+ if (!isNaN(numValue)) {
15154
15170
  return numValue.toLocaleString();
15155
15171
  }
15156
15172
  return value;
15157
15173
  };
15174
+ const barValuePlugin = {
15175
+ id: "barValuePlugin",
15176
+ afterDatasetsDraw(chart) {
15177
+ if (!(content === null || content === void 0 ? void 0 : content.showLabels))
15178
+ return;
15179
+ const { ctx } = chart;
15180
+ chart.data.datasets.forEach((dataset, i) => {
15181
+ const meta = chart.getDatasetMeta(i);
15182
+ meta.data.forEach((bar, index) => {
15183
+ const value = dataset.data[index];
15184
+ ctx.save();
15185
+ ctx.font = "12px sans-serif";
15186
+ ctx.textAlign = "center";
15187
+ ctx.fillStyle = "black";
15188
+ ctx.fillText(value, bar.x, bar.y - 5);
15189
+ ctx.restore();
15190
+ });
15191
+ });
15192
+ },
15193
+ };
15194
+ const getAxisLabel = (symbol) => {
15195
+ const labelMap = {
15196
+ "%": "Percentage",
15197
+ "$": "Cost",
15198
+ "#": "Count",
15199
+ };
15200
+ return labelMap[symbol] || symbol; // fallback if not found
15201
+ };
15158
15202
  const defaultOptions = {
15159
15203
  responsive: true,
15160
15204
  maintainAspectRatio: false,
@@ -15169,7 +15213,13 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15169
15213
  },
15170
15214
  plugins: {
15171
15215
  legend: {
15172
- display: true,
15216
+ display: (ctx) => {
15217
+ const chart = ctx.chart;
15218
+ const datasets = chart.data.datasets;
15219
+ if (datasets.length > 1)
15220
+ return true;
15221
+ return false;
15222
+ },
15173
15223
  labels: {
15174
15224
  boxWidth: 12,
15175
15225
  boxHeight: 12,
@@ -15177,13 +15227,7 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15177
15227
  position: "bottom"
15178
15228
  },
15179
15229
  datalabels: {
15180
- display: (context) => { var _a; return context.dataset.data[context.dataIndex] !== null && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false); },
15181
- color: "white",
15182
- anchor: "center",
15183
- align: "center",
15184
- offset: 0,
15185
- font: { size: 12 },
15186
- formatter: (value) => value,
15230
+ display: false,
15187
15231
  },
15188
15232
  title: {
15189
15233
  display: true,
@@ -15208,30 +15252,43 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15208
15252
  ticks: { autoSkip: false, maxRotation: 45, minRotation: 0 },
15209
15253
  },
15210
15254
  y: {
15255
+ title: {
15256
+ display: true,
15257
+ text: (data === null || data === void 0 ? void 0 : data.datasets) && ((_a = data === null || data === void 0 ? void 0 : data.datasets) === null || _a === void 0 ? void 0 : _a.length) === 1 ? (_b = data === null || data === void 0 ? void 0 : data.datasets) === null || _b === void 0 ? void 0 : _b[0].label : getAxisLabel(units !== null && units !== void 0 ? units : ""),
15258
+ },
15211
15259
  beginAtZero: true,
15212
15260
  ticks: {
15213
15261
  callback: function (value) {
15214
15262
  if (units === '$') {
15215
15263
  return `${units}${formatValue(value)}`;
15216
15264
  }
15217
- return units ? `${formatValue(value)} ${units}` : value;
15265
+ return units ? `${formatValue(value)} ${(units === null || units === void 0 ? void 0 : units.length) < 3 ? units : ""}` : value;
15218
15266
  }
15219
15267
  }
15220
15268
  },
15221
15269
  },
15222
15270
  };
15223
- return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15271
+ return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [barValuePlugin] }));
15224
15272
  }
15225
15273
 
15226
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15274
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15227
15275
  function SeriesLineChart({ orientation, title, data, options, className, units, content }) {
15276
+ var _a, _b;
15228
15277
  const formatValue = (value) => {
15229
15278
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
15230
- if (units === '$' && !isNaN(numValue)) {
15279
+ if (!isNaN(numValue)) {
15231
15280
  return numValue.toLocaleString();
15232
15281
  }
15233
15282
  return value;
15234
15283
  };
15284
+ const getAxisLabel = (symbol) => {
15285
+ const labelMap = {
15286
+ "%": "Percentage",
15287
+ "$": "Cost",
15288
+ "#": "Count",
15289
+ };
15290
+ return labelMap[symbol] || symbol; // fallback if not found
15291
+ };
15235
15292
  const defaultOptions = {
15236
15293
  responsive: true,
15237
15294
  maintainAspectRatio: false,
@@ -15245,7 +15302,13 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15245
15302
  },
15246
15303
  plugins: {
15247
15304
  legend: {
15248
- display: true,
15305
+ display: (ctx) => {
15306
+ const chart = ctx.chart;
15307
+ const datasets = chart.data.datasets;
15308
+ if (datasets.length > 1)
15309
+ return true;
15310
+ return false;
15311
+ },
15249
15312
  labels: {
15250
15313
  boxWidth: 12,
15251
15314
  boxHeight: 12,
@@ -15288,6 +15351,10 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15288
15351
  ticks: { autoSkip: true, maxTicksLimit: 8, maxRotation: 45, minRotation: 0 },
15289
15352
  },
15290
15353
  y: {
15354
+ title: {
15355
+ display: true,
15356
+ text: (data === null || data === void 0 ? void 0 : data.datasets) && ((_a = data === null || data === void 0 ? void 0 : data.datasets) === null || _a === void 0 ? void 0 : _a.length) === 1 ? (_b = data === null || data === void 0 ? void 0 : data.datasets) === null || _b === void 0 ? void 0 : _b[0].label : getAxisLabel(units !== null && units !== void 0 ? units : ""),
15357
+ },
15291
15358
  beginAtZero: true,
15292
15359
  ticks: {
15293
15360
  callback: function (value) {
@@ -15305,10 +15372,10 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15305
15372
  },
15306
15373
  },
15307
15374
  };
15308
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15375
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15309
15376
  }
15310
15377
 
15311
- Chart$1.register(ArcElement, plugin_tooltip, plugin_legend, ChartDataLabels);
15378
+ Chart$1.register(ArcElement, plugin_tooltip, plugin_legend);
15312
15379
  const PieChart = (props) => {
15313
15380
  const { data, title, options, units, content } = props;
15314
15381
  const formatValue = (value) => {
@@ -15318,8 +15385,6 @@ const PieChart = (props) => {
15318
15385
  }
15319
15386
  return value;
15320
15387
  };
15321
- // Sanitize data to prevent null/undefined values
15322
- const sanitizedData = Object.assign(Object.assign({}, data), { datasets: data.datasets.map(dataset => (Object.assign(Object.assign({}, dataset), { data: dataset.data.map(d => d === null || d === undefined || isNaN(Number(d)) ? 0 : d) }))) });
15323
15388
  const defaultOptions = {
15324
15389
  responsive: true,
15325
15390
  maintainAspectRatio: false,
@@ -15331,20 +15396,35 @@ const PieChart = (props) => {
15331
15396
  },
15332
15397
  position: "bottom",
15333
15398
  },
15334
- datalabels: {
15335
- display: (context) => {
15399
+ outlabels: {
15400
+ display: (context) => { var _a; return context.dataset.data[context.dataIndex] !== null && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false); },
15401
+ text: (ctx) => {
15336
15402
  var _a;
15337
- const value = context.dataset.data[context.dataIndex];
15338
- return value !== null && value !== undefined && !isNaN(Number(value)) && value !== 0 && ((_a = content === null || content === void 0 ? void 0 : content.showLabels) !== null && _a !== void 0 ? _a : false);
15403
+ const dataset = ctx.dataset.data;
15404
+ const total = dataset.reduce((a, b) => a + b, 0);
15405
+ const value = dataset[ctx.dataIndex];
15406
+ const percent = (value / total) * 100;
15407
+ // Only show if >= 5%
15408
+ return percent >= 5 ? `${(_a = ctx.chart.data.labels) === null || _a === void 0 ? void 0 : _a[ctx.dataIndex]} ${value}` : "";
15339
15409
  },
15340
- color: "white",
15341
- font: { size: 12 },
15342
- formatter: (value) => {
15343
- if (value === null || value === undefined || isNaN(Number(value)))
15344
- return '';
15345
- return formatValue(value);
15410
+ color: "black",
15411
+ stretch: 15,
15412
+ font: {
15413
+ resizable: true,
15414
+ minSize: 12,
15415
+ maxSize: 18,
15416
+ },
15417
+ backgroundColor: (ctx) => {
15418
+ const dataset = ctx.dataset.data;
15419
+ const total = dataset.reduce((a, b) => a + b, 0);
15420
+ const value = dataset[ctx.dataIndex];
15421
+ const percent = (value / total) * 100;
15422
+ return percent >= 5 ? "rgba(255,255,255,0.7)" : "transparent";
15346
15423
  },
15347
15424
  },
15425
+ datalabels: {
15426
+ display: false
15427
+ },
15348
15428
  title: {
15349
15429
  display: true,
15350
15430
  text: title,
@@ -15372,10 +15452,10 @@ const PieChart = (props) => {
15372
15452
  },
15373
15453
  },
15374
15454
  };
15375
- return jsxRuntimeExports.jsx(Pie, { data: sanitizedData, options: options !== null && options !== void 0 ? options : defaultOptions });
15455
+ return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartPieChartOutlabels] });
15376
15456
  };
15377
15457
 
15378
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15458
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15379
15459
  function LineChart({ title, data, options, className, units, content }) {
15380
15460
  const formatValue = (value) => {
15381
15461
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15449,7 +15529,7 @@ function LineChart({ title, data, options, className, units, content }) {
15449
15529
  },
15450
15530
  },
15451
15531
  };
15452
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15532
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15453
15533
  }
15454
15534
 
15455
15535
  function DataGrid({ title, data, className }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dp-widgets-framework",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
@@ -56,6 +56,7 @@
56
56
  "@copilotkit/react-core": "^1.9.3",
57
57
  "@copilotkit/react-ui": "^1.9.3",
58
58
  "@copilotkit/runtime": "^1.9.3",
59
+ "@energiency/chartjs-plugin-piechart-outlabels": "^1.3.5",
59
60
  "@hello-pangea/dnd": "^17.0.0",
60
61
  "@monaco-editor/react": "^4.6.0",
61
62
  "@radix-ui/react-accordion": "^1.2.2",
@@ -135,4 +136,4 @@
135
136
  "tailwindcss": "^3.3.0",
136
137
  "typescript": "^5"
137
138
  }
138
- }
139
+ }