@powerportalspro/react-charts 5.0.0-beta.1

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.
@@ -0,0 +1,352 @@
1
+ import { DataPoint, ChartDataset as ChartDataset$1, PowerPortalsProClient, ChartData, ChartDataRequest, ChartDateGrouping, ChartLinkedEntity, AggregateType } from '@powerportalspro/core';
2
+ export { AggregateChartConfig, AggregateType, BaseDataPoint, ChartData, ChartDataRequest, ChartDataResponse, ChartDateGrouping, ChartLinkedEntity, DataPoint, DataverseDataPoint, JoinOperator } from '@powerportalspro/core';
3
+ import { RefAttributes, ReactElement } from 'react';
4
+
5
+ /**
6
+ * Display-only type / enum definitions for the React Charts wrapper.
7
+ * Wire-shape types (ChartData, ChartDataset, DataPoint, DataverseDataPoint,
8
+ * ChartLinkedEntity, ChartDateGrouping, AggregateType, JoinOperator) are
9
+ * generated from OpenAPI and re-exported from `@powerportalspro/core` —
10
+ * this file holds only the Chart.js-presentation enums that don't cross
11
+ * the wire.
12
+ */
13
+
14
+ /**
15
+ * Dataset of chart data points. Generic over `TPoint` so consumers can
16
+ * carry a custom DataPoint subtype through to the click handler.
17
+ *
18
+ * Defaults to the built-in {@link DataPoint} union — when the consumer
19
+ * doesn't specialize the generic, calls look exactly like before
20
+ * (no `<…>` required). When they DO want richer click context, they
21
+ * extend {@link BaseDataPoint} and parameterize:
22
+ *
23
+ * ```ts
24
+ * interface SalesDataPoint extends BaseDataPoint {
25
+ * region: string;
26
+ * orderCount: number;
27
+ * }
28
+ *
29
+ * const datasets: ChartDataset<SalesDataPoint>[] = [{
30
+ * label: 'Sales',
31
+ * data: [{ value: 65, region: 'North', orderCount: 12 }],
32
+ * }];
33
+ *
34
+ * <FluentUIChart<SalesDataPoint>
35
+ * datasets={datasets}
36
+ * onElementClick={(a) => a.dataPoint?.region}
37
+ * />
38
+ * ```
39
+ *
40
+ * Mirrors Blazor's `List<DataPoint>` polymorphism — the underlying
41
+ * Chart.js layer accepts arbitrary object fields on each data point and
42
+ * passes them straight through to the click handler.
43
+ */
44
+ type ChartDataset<TPoint = DataPoint> = Omit<ChartDataset$1, 'data'> & {
45
+ data?: TPoint[];
46
+ };
47
+ /** Chart types supported by the underlying Chart.js library. */
48
+ declare const ChartType: {
49
+ /** Bar chart (`'bar'`). */
50
+ readonly Bar: "bar";
51
+ /** Line chart (`'line'`). */
52
+ readonly Line: "line";
53
+ /** Pie chart (`'pie'`). */
54
+ readonly Pie: "pie";
55
+ /** Doughnut chart (`'doughnut'`). */
56
+ readonly Doughnut: "doughnut";
57
+ /** Polar area chart (`'polarArea'`). */
58
+ readonly PolarArea: "polarArea";
59
+ /** Radar chart (`'radar'`). */
60
+ readonly Radar: "radar";
61
+ /** Bubble chart (`'bubble'`). */
62
+ readonly Bubble: "bubble";
63
+ /** Scatter chart (`'scatter'`). */
64
+ readonly Scatter: "scatter";
65
+ /** Funnel chart (via the `chartjs-chart-funnel` plugin, type `'funnel'`). */
66
+ readonly Funnel: "funnel";
67
+ };
68
+ type ChartType = (typeof ChartType)[keyof typeof ChartType];
69
+ /**
70
+ * Placement of the chart legend, or `Hidden` to suppress it entirely. Maps
71
+ * directly to Chart.js's lowercase legend position string.
72
+ */
73
+ declare const ChartLegendPosition: {
74
+ readonly Top: "top";
75
+ readonly Bottom: "bottom";
76
+ readonly Left: "left";
77
+ readonly Right: "right";
78
+ /** Legend is not rendered. */
79
+ readonly Hidden: "hidden";
80
+ };
81
+ type ChartLegendPosition = (typeof ChartLegendPosition)[keyof typeof ChartLegendPosition];
82
+ /**
83
+ * Chart.js `indexAxis` value — `'x'` for vertical bar / line charts and
84
+ * `'y'` for horizontal bars / funnels. Most consumers should set
85
+ * {@link ChartOrientation} on a component instead of touching this directly.
86
+ */
87
+ declare const ChartIndexAxis: {
88
+ readonly X: "x";
89
+ readonly Y: "y";
90
+ };
91
+ type ChartIndexAxis = (typeof ChartIndexAxis)[keyof typeof ChartIndexAxis];
92
+ /**
93
+ * Caller-facing chart orientation. Maps to the underlying Chart.js
94
+ * `indexAxis` via {@link toIndexAxis}: `Vertical` → `'x'`, `Horizontal` →
95
+ * `'y'`. Funnel charts default to `Horizontal` for a top-down funnel.
96
+ */
97
+ declare const ChartOrientation: {
98
+ readonly Vertical: "vertical";
99
+ readonly Horizontal: "horizontal";
100
+ };
101
+ type ChartOrientation = (typeof ChartOrientation)[keyof typeof ChartOrientation];
102
+ /** Maps a {@link ChartOrientation} to the Chart.js {@link ChartIndexAxis}. */
103
+ declare function toIndexAxis(orientation: ChartOrientation): ChartIndexAxis;
104
+ /**
105
+ * Theme and formatting overrides forwarded to Chart.js. Fields left
106
+ * `undefined` are not applied — the underlying Chart.js defaults stand.
107
+ */
108
+ interface ChartTheme {
109
+ /** Color for legend labels, axis ticks, and the title. */
110
+ textColor?: string;
111
+ /** Color for axis gridlines and borders. */
112
+ gridColor?: string;
113
+ /** Prefix prepended to every Y-axis tick label and tooltip value (e.g. `"$"`). */
114
+ yAxisPrefix?: string;
115
+ /** Suffix appended to every Y-axis tick label and tooltip value (e.g. `"%"`). */
116
+ yAxisSuffix?: string;
117
+ /** Prefix prepended to every X-axis tick label (e.g. `"Q"`). */
118
+ xAxisPrefix?: string;
119
+ /** Suffix appended to every X-axis tick label. */
120
+ xAxisSuffix?: string;
121
+ /** Chart title text displayed above the chart. */
122
+ title?: string;
123
+ /**
124
+ * Stack datasets on top of each other instead of side-by-side. Applies to
125
+ * bar and line charts.
126
+ */
127
+ stacked?: boolean;
128
+ /** Legend placement or `Hidden`. When omitted, Chart.js's default is used. */
129
+ legendPosition?: ChartLegendPosition;
130
+ /** Whether chart animations are enabled. Defaults to `true`. */
131
+ enableAnimation?: boolean;
132
+ /**
133
+ * Category-axis direction — usually set indirectly via the caller-facing
134
+ * {@link ChartOrientation}. Funnel charts default to `'y'`.
135
+ */
136
+ indexAxis?: ChartIndexAxis;
137
+ }
138
+ /**
139
+ * Payload describing a single click on a rendered chart element. Generic
140
+ * over `TPoint` so consumers using a custom DataPoint subtype see their
141
+ * extra fields on `dataPoint` without a cast.
142
+ */
143
+ interface ChartClickEventArgs<TPoint = DataPoint> {
144
+ /** Zero-based dataset index that contains the clicked element. */
145
+ datasetIndex: number;
146
+ /** Zero-based point index within its dataset. */
147
+ dataIndex: number;
148
+ /** Category label of the clicked element (e.g. `"January"`) or empty. */
149
+ label: string;
150
+ /** Numeric value of the clicked data point. */
151
+ value: number;
152
+ /** Label of the dataset the clicked element belongs to. */
153
+ datasetLabel: string;
154
+ /**
155
+ * The original data-point object backing the clicked element. Typed as
156
+ * the dataset's `TPoint` so a `ChartDataset<MyPoint>` flows through to
157
+ * `MyPoint` here. With the default {@link DataPoint} union, discriminate
158
+ * via the `$type` field or `'record' in dataPoint` to recover
159
+ * DataverseDataPoint context. `undefined` only when the indices from
160
+ * Chart.js no longer line up with the current datasets (rare race
161
+ * during a data swap).
162
+ */
163
+ dataPoint?: TPoint;
164
+ }
165
+
166
+ /**
167
+ * Base `<Chart>` React component — direct Chart.js wrapper, mirrors the
168
+ * Blazor `Chart.razor` API surface (Type, Labels, Datasets, Width, Height,
169
+ * Theme, OnElementClick + `exportAsImage`).
170
+ *
171
+ * Owns the Chart.js instance via a canvas ref; React's render is just the
172
+ * outer container + `<canvas>`. Chart lifecycle is driven by an effect that
173
+ * reads the props snapshot. The component pre-empts re-renders triggered
174
+ * by unrelated parent updates by reference-checking labels/datasets/theme
175
+ * before destroying the underlying Chart.js instance — the same
176
+ * "destroy + recreate is expensive" optimization the Blazor component
177
+ * uses (each re-create restarts the entry animation).
178
+ */
179
+
180
+ /** Imperative handle exposed to callers via `ref` on `<Chart>`. */
181
+ interface ChartHandle {
182
+ /**
183
+ * Exports the chart as a PNG data URI
184
+ * (`"data:image/png;base64,…"`). Returns `null` when the chart hasn't
185
+ * been rendered yet (typically the first paint).
186
+ */
187
+ exportAsImage(): string | null;
188
+ }
189
+ /**
190
+ * Props accepted by `<Chart>`. Generic over `TPoint` — the type carried
191
+ * through the dataset's `data` array and back out on `onElementClick`.
192
+ * Defaults to {@link DataPoint}, so callers that don't extend the built-in
193
+ * DataPoint shape never need to mention the generic.
194
+ */
195
+ interface ChartProps<TPoint = DataPoint> {
196
+ /** Chart type. Defaults to `ChartType.Bar`. */
197
+ type?: ChartType;
198
+ /** Category labels rendered along the primary axis. */
199
+ labels: string[];
200
+ /** Datasets to plot. */
201
+ datasets: ChartDataset<TPoint>[];
202
+ /** Optional CSS width applied to the outer container. */
203
+ width?: string;
204
+ /** Optional CSS height applied to the outer container. Defaults to `'400px'`. */
205
+ height?: string;
206
+ /** Theme overrides forwarded to Chart.js. */
207
+ theme?: ChartTheme;
208
+ /** Fires when the user clicks on a rendered chart element. */
209
+ onElementClick?: (args: ChartClickEventArgs<TPoint>) => void;
210
+ }
211
+ declare const Chart: <TPoint = DataPoint>(props: ChartProps<TPoint> & RefAttributes<ChartHandle>) => ReactElement | null;
212
+
213
+ /**
214
+ * Base chart data source. Builds a {@link ChartDataRequest} from the
215
+ * configured properties and dispatches it through the server-side
216
+ * `IChartService` via {@link PowerPortalsProClient.loadChartAsync}.
217
+ * The server owns FetchXML construction and record shaping — this class
218
+ * is a thin client over the typed request shape.
219
+ *
220
+ * Mirrors `PowerPortalsPro.Web.Blazor.Charts.Components.DataverseChartDataSource`
221
+ * on the Blazor side; both feed the same endpoint.
222
+ */
223
+
224
+ /**
225
+ * Configuration accepted by {@link DataverseChartDataSource}. Subclasses
226
+ * carry their own subset and forward what they need to the base constructor.
227
+ */
228
+ interface DataverseChartDataSourceOptions {
229
+ /**
230
+ * FetchXML to send to the server. Subclasses leave this blank and
231
+ * override `configureRequest` to set a different input mode.
232
+ */
233
+ fetchXml?: string;
234
+ /** Result column name to read chart labels from (X axis). */
235
+ labelColumn?: string;
236
+ /** Result column name to read numeric values from. */
237
+ valueColumn?: string;
238
+ /**
239
+ * Optional result column name used to split rows into multiple
240
+ * datasets. When set, rows sharing the same series value form one
241
+ * dataset.
242
+ */
243
+ seriesColumn?: string;
244
+ /**
245
+ * Optional label applied to the single emitted dataset when
246
+ * {@link seriesColumn} isn't set. Multi-series queries use the
247
+ * formatted series value as the dataset label and ignore this.
248
+ */
249
+ singleSeriesLabel?: string;
250
+ }
251
+ declare class DataverseChartDataSource {
252
+ fetchXml?: string;
253
+ labelColumn: string;
254
+ valueColumn: string;
255
+ seriesColumn?: string;
256
+ singleSeriesLabel: string;
257
+ constructor(options?: DataverseChartDataSourceOptions);
258
+ /**
259
+ * Builds a {@link ChartDataRequest} from this instance's properties
260
+ * and POSTs it via `client.loadChartAsync`. Subclasses inject the
261
+ * input mode via {@link configureRequest}.
262
+ */
263
+ loadAsync(client: PowerPortalsProClient, signal?: AbortSignal): Promise<ChartData>;
264
+ /**
265
+ * Sets the input mode (FetchXml / ViewId / Aggregate) on the request.
266
+ * Base implementation sets `fetchXml`; subclasses override to use
267
+ * ViewId or Aggregate config instead.
268
+ */
269
+ protected configureRequest(request: ChartDataRequest): void;
270
+ }
271
+
272
+ /**
273
+ * Loads chart data from a saved Dataverse view. Caller still picks which
274
+ * of the view's columns map to labels / values via `labelColumn` /
275
+ * `valueColumn`; this class just sets the request's `viewId` input mode.
276
+ *
277
+ * Mirrors `PowerPortalsPro.Web.Blazor.Charts.Components.ViewDataverseChartDataSource`.
278
+ */
279
+
280
+ interface ViewDataverseChartDataSourceOptions extends DataverseChartDataSourceOptions {
281
+ /** Dataverse saved-view id. Server fetches its FetchXML on every load. */
282
+ viewId?: string;
283
+ }
284
+ declare class ViewDataverseChartDataSource extends DataverseChartDataSource {
285
+ viewId?: string;
286
+ constructor(options?: ViewDataverseChartDataSourceOptions);
287
+ protected configureRequest(request: ChartDataRequest): void;
288
+ }
289
+
290
+ /**
291
+ * Aggregate chart data source. Builds an {@link AggregateChartConfig}
292
+ * from typed properties and sends it through the server-side endpoint.
293
+ * The server constructs the FetchXML (including link-entity trees,
294
+ * combined date groupings, and view-filter merging) and shapes the
295
+ * response.
296
+ *
297
+ * Mirrors `PowerPortalsPro.Web.Blazor.Charts.Components.AggregateDataverseChartDataSource`.
298
+ */
299
+
300
+ /** Caller-supplied configuration. Mirrors the Blazor property surface. */
301
+ interface AggregateDataverseChartDataSourceOptions extends Omit<DataverseChartDataSourceOptions, 'fetchXml' | 'labelColumn' | 'valueColumn'> {
302
+ /** Dataverse table to query (e.g. `"opportunity"`). */
303
+ tableName: string;
304
+ /** Column to group by — becomes the chart's X-axis labels. */
305
+ groupByColumn: string;
306
+ /** Date bucketing for `groupByColumn` when it's a datetime column. */
307
+ groupByDateGrouping?: ChartDateGrouping;
308
+ /** Linked entity chain when `groupByColumn` lives on a related table. */
309
+ groupByLinkedEntity?: ChartLinkedEntity;
310
+ /**
311
+ * Secondary date grouping applied to the same column as `groupByColumn`
312
+ * (year-over-year charts). When set, the server emits a second
313
+ * `groupby` on the same column and uses its result as the series
314
+ * discriminator.
315
+ */
316
+ seriesDateGrouping?: ChartDateGrouping;
317
+ /** Linked entity chain for `seriesColumn` when it lives on a related table. */
318
+ seriesLinkedEntity?: ChartLinkedEntity;
319
+ /** Column to aggregate (sum / count / etc.). */
320
+ aggregateColumn: string;
321
+ /** Aggregate function. Defaults to `AggregateType.Sum`. */
322
+ aggregate?: AggregateType;
323
+ /** Optional saved-view id whose filters are merged into the generated query. */
324
+ viewId?: string;
325
+ /** Optional raw `<filter>...</filter>` fragment injected into the query. */
326
+ filterXml?: string;
327
+ /** Optional row cap. */
328
+ top?: number;
329
+ }
330
+ declare class AggregateDataverseChartDataSource extends DataverseChartDataSource {
331
+ tableName: string;
332
+ groupByDateGrouping: ChartDateGrouping;
333
+ groupByLinkedEntity?: ChartLinkedEntity;
334
+ seriesDateGrouping: ChartDateGrouping;
335
+ seriesLinkedEntity?: ChartLinkedEntity;
336
+ aggregate: AggregateType;
337
+ viewId?: string;
338
+ filterXml?: string;
339
+ top?: number;
340
+ constructor(options: AggregateDataverseChartDataSourceOptions);
341
+ /** Caller-friendly alias for `labelColumn` (kept in sync via getter/setter). */
342
+ get groupByColumn(): string;
343
+ set groupByColumn(value: string);
344
+ /** Caller-friendly alias for `valueColumn`. */
345
+ get aggregateColumn(): string;
346
+ set aggregateColumn(value: string);
347
+ protected configureRequest(request: ChartDataRequest): void;
348
+ }
349
+
350
+ declare const VERSION = "0.1.0";
351
+
352
+ export { AggregateDataverseChartDataSource, type AggregateDataverseChartDataSourceOptions, Chart, type ChartClickEventArgs, type ChartDataset, type ChartHandle, ChartIndexAxis, ChartLegendPosition, ChartOrientation, type ChartProps, type ChartTheme, ChartType, DataverseChartDataSource, type DataverseChartDataSourceOptions, VERSION, ViewDataverseChartDataSource, type ViewDataverseChartDataSourceOptions, toIndexAxis };