dp-widgets-framework 1.3.3 → 1.3.5

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,10 +15131,10 @@ 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 }) {
15124
15139
  const formatValue = (value) => {
15125
15140
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15128,6 +15143,26 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15128
15143
  }
15129
15144
  return value;
15130
15145
  };
15146
+ const barValuePlugin = {
15147
+ id: "barValuePlugin",
15148
+ afterDatasetsDraw(chart) {
15149
+ if (!(content === null || content === void 0 ? void 0 : content.showLabels))
15150
+ return;
15151
+ const { ctx } = chart;
15152
+ chart.data.datasets.forEach((dataset, i) => {
15153
+ const meta = chart.getDatasetMeta(i);
15154
+ meta.data.forEach((bar, index) => {
15155
+ const value = dataset.data[index];
15156
+ ctx.save();
15157
+ ctx.font = "12px sans-serif";
15158
+ ctx.textAlign = "center";
15159
+ ctx.fillStyle = "black";
15160
+ ctx.fillText(value, bar.x, bar.y - 5);
15161
+ ctx.restore();
15162
+ });
15163
+ });
15164
+ },
15165
+ };
15131
15166
  const defaultOptions = {
15132
15167
  responsive: true,
15133
15168
  maintainAspectRatio: false,
@@ -15150,13 +15185,7 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15150
15185
  position: "bottom"
15151
15186
  },
15152
15187
  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,
15188
+ display: false,
15160
15189
  },
15161
15190
  title: {
15162
15191
  display: true,
@@ -15193,10 +15222,10 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15193
15222
  },
15194
15223
  },
15195
15224
  };
15196
- return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15225
+ return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [barValuePlugin] }));
15197
15226
  }
15198
15227
 
15199
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15228
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15200
15229
  function SeriesLineChart({ orientation, title, data, options, className, units, content }) {
15201
15230
  const formatValue = (value) => {
15202
15231
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15278,10 +15307,10 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15278
15307
  },
15279
15308
  },
15280
15309
  };
15281
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15310
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15282
15311
  }
15283
15312
 
15284
- Chart$1.register(ArcElement, plugin_tooltip, plugin_legend, ChartDataLabels);
15313
+ Chart$1.register(ArcElement, plugin_tooltip, plugin_legend);
15285
15314
  const PieChart = (props) => {
15286
15315
  const { data, title, options, units, content } = props;
15287
15316
  const formatValue = (value) => {
@@ -15302,11 +15331,34 @@ const PieChart = (props) => {
15302
15331
  },
15303
15332
  position: "bottom",
15304
15333
  },
15305
- datalabels: {
15334
+ outlabels: {
15306
15335
  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); },
15307
- color: "white",
15308
- font: { size: 12 },
15309
- formatter: (value) => formatValue(value),
15336
+ text: (ctx) => {
15337
+ var _a;
15338
+ const dataset = ctx.dataset.data;
15339
+ const total = dataset.reduce((a, b) => a + b, 0);
15340
+ const value = dataset[ctx.dataIndex];
15341
+ const percent = (value / total) * 100;
15342
+ // Only show if >= 5%
15343
+ return percent >= 5 ? `${(_a = ctx.chart.data.labels) === null || _a === void 0 ? void 0 : _a[ctx.dataIndex]} ${value}` : "";
15344
+ },
15345
+ color: "black",
15346
+ stretch: 15,
15347
+ font: {
15348
+ resizable: true,
15349
+ minSize: 12,
15350
+ maxSize: 18,
15351
+ },
15352
+ backgroundColor: (ctx) => {
15353
+ const dataset = ctx.dataset.data;
15354
+ const total = dataset.reduce((a, b) => a + b, 0);
15355
+ const value = dataset[ctx.dataIndex];
15356
+ const percent = (value / total) * 100;
15357
+ return percent >= 5 ? "rgba(255,255,255,0.7)" : "transparent";
15358
+ },
15359
+ },
15360
+ datalabels: {
15361
+ display: false
15310
15362
  },
15311
15363
  title: {
15312
15364
  display: true,
@@ -15335,10 +15387,10 @@ const PieChart = (props) => {
15335
15387
  },
15336
15388
  },
15337
15389
  };
15338
- return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions });
15390
+ return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartPieChartOutlabels] });
15339
15391
  };
15340
15392
 
15341
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15393
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15342
15394
  function LineChart({ title, data, options, className, units, content }) {
15343
15395
  const formatValue = (value) => {
15344
15396
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15412,7 +15464,7 @@ function LineChart({ title, data, options, className, units, content }) {
15412
15464
  },
15413
15465
  },
15414
15466
  };
15415
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15467
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15416
15468
  }
15417
15469
 
15418
15470
  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,10 +15158,10 @@ 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 }) {
15151
15166
  const formatValue = (value) => {
15152
15167
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15155,6 +15170,26 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15155
15170
  }
15156
15171
  return value;
15157
15172
  };
15173
+ const barValuePlugin = {
15174
+ id: "barValuePlugin",
15175
+ afterDatasetsDraw(chart) {
15176
+ if (!(content === null || content === void 0 ? void 0 : content.showLabels))
15177
+ return;
15178
+ const { ctx } = chart;
15179
+ chart.data.datasets.forEach((dataset, i) => {
15180
+ const meta = chart.getDatasetMeta(i);
15181
+ meta.data.forEach((bar, index) => {
15182
+ const value = dataset.data[index];
15183
+ ctx.save();
15184
+ ctx.font = "12px sans-serif";
15185
+ ctx.textAlign = "center";
15186
+ ctx.fillStyle = "black";
15187
+ ctx.fillText(value, bar.x, bar.y - 5);
15188
+ ctx.restore();
15189
+ });
15190
+ });
15191
+ },
15192
+ };
15158
15193
  const defaultOptions = {
15159
15194
  responsive: true,
15160
15195
  maintainAspectRatio: false,
@@ -15177,13 +15212,7 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15177
15212
  position: "bottom"
15178
15213
  },
15179
15214
  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,
15215
+ display: false,
15187
15216
  },
15188
15217
  title: {
15189
15218
  display: true,
@@ -15220,10 +15249,10 @@ function SeriesChart({ orientation, title, data, options, className, units, cont
15220
15249
  },
15221
15250
  },
15222
15251
  };
15223
- return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15252
+ return (jsxRuntimeExports.jsx(Bar, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [barValuePlugin] }));
15224
15253
  }
15225
15254
 
15226
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15255
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15227
15256
  function SeriesLineChart({ orientation, title, data, options, className, units, content }) {
15228
15257
  const formatValue = (value) => {
15229
15258
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15305,10 +15334,10 @@ function SeriesLineChart({ orientation, title, data, options, className, units,
15305
15334
  },
15306
15335
  },
15307
15336
  };
15308
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15337
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15309
15338
  }
15310
15339
 
15311
- Chart$1.register(ArcElement, plugin_tooltip, plugin_legend, ChartDataLabels);
15340
+ Chart$1.register(ArcElement, plugin_tooltip, plugin_legend);
15312
15341
  const PieChart = (props) => {
15313
15342
  const { data, title, options, units, content } = props;
15314
15343
  const formatValue = (value) => {
@@ -15329,11 +15358,34 @@ const PieChart = (props) => {
15329
15358
  },
15330
15359
  position: "bottom",
15331
15360
  },
15332
- datalabels: {
15361
+ outlabels: {
15333
15362
  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); },
15334
- color: "white",
15335
- font: { size: 12 },
15336
- formatter: (value) => formatValue(value),
15363
+ text: (ctx) => {
15364
+ var _a;
15365
+ const dataset = ctx.dataset.data;
15366
+ const total = dataset.reduce((a, b) => a + b, 0);
15367
+ const value = dataset[ctx.dataIndex];
15368
+ const percent = (value / total) * 100;
15369
+ // Only show if >= 5%
15370
+ return percent >= 5 ? `${(_a = ctx.chart.data.labels) === null || _a === void 0 ? void 0 : _a[ctx.dataIndex]} ${value}` : "";
15371
+ },
15372
+ color: "black",
15373
+ stretch: 15,
15374
+ font: {
15375
+ resizable: true,
15376
+ minSize: 12,
15377
+ maxSize: 18,
15378
+ },
15379
+ backgroundColor: (ctx) => {
15380
+ const dataset = ctx.dataset.data;
15381
+ const total = dataset.reduce((a, b) => a + b, 0);
15382
+ const value = dataset[ctx.dataIndex];
15383
+ const percent = (value / total) * 100;
15384
+ return percent >= 5 ? "rgba(255,255,255,0.7)" : "transparent";
15385
+ },
15386
+ },
15387
+ datalabels: {
15388
+ display: false
15337
15389
  },
15338
15390
  title: {
15339
15391
  display: true,
@@ -15362,10 +15414,10 @@ const PieChart = (props) => {
15362
15414
  },
15363
15415
  },
15364
15416
  };
15365
- return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions });
15417
+ return jsxRuntimeExports.jsx(Pie, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartPieChartOutlabels] });
15366
15418
  };
15367
15419
 
15368
- Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend, ChartDataLabels);
15420
+ Chart$1.register(CategoryScale, LinearScale, PointElement, LineElement, plugin_title, plugin_tooltip, plugin_legend);
15369
15421
  function LineChart({ title, data, options, className, units, content }) {
15370
15422
  const formatValue = (value) => {
15371
15423
  const numValue = typeof value === 'string' ? parseFloat(value) : value;
@@ -15439,7 +15491,7 @@ function LineChart({ title, data, options, className, units, content }) {
15439
15491
  },
15440
15492
  },
15441
15493
  };
15442
- return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions }));
15494
+ return (jsxRuntimeExports.jsx(Line, { data: data, options: options !== null && options !== void 0 ? options : defaultOptions, plugins: [ChartDataLabels] }));
15443
15495
  }
15444
15496
 
15445
15497
  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.3",
3
+ "version": "1.3.5",
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
+ }