chartjs-chart-treemap 5.0.0-next.9 → 5.0.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.
@@ -1,4 +1,4 @@
1
- import type { LayoutNode, LayoutOptions } from './layout';
1
+ import type { LayoutNode, LayoutOptions } from './layout.js';
2
2
  import { DatasetController } from 'chart.js';
3
3
  export default class TreemapController extends DatasetController {
4
4
  static readonly id: string;
@@ -16,6 +16,8 @@ export default class TreemapController extends DatasetController {
16
16
  _regionWarned: boolean;
17
17
  _layoutDirty: boolean;
18
18
  _fingerprint: string | undefined;
19
+ _layoutKey: string | undefined;
20
+ _resetFrom: number | undefined;
19
21
  constructor(chart: any, datasetIndex: number);
20
22
  initialize(): void;
21
23
  getMinMax(scale: any): {
@@ -49,7 +51,7 @@ export default class TreemapController extends DatasetController {
49
51
  * `dataset.data`, because a treemap with groups has more rectangles than the
50
52
  * user supplied rows.
51
53
  */
52
- buildOrUpdateElements(_resetNewElements?: boolean): void;
54
+ buildOrUpdateElements(resetNewElements?: boolean): void;
53
55
  parse(_start: number, _count: number): void;
54
56
  getContext(index: number, active?: boolean, mode?: string): any;
55
57
  getLabelAndValue(index: number): {
@@ -0,0 +1,65 @@
1
+ import type { TreemapConfig, TreemapDataPoint, TreemapLayoutOptions, TreemapOptions, TreemapScriptableContext } from './types.cjs';
2
+ import type { Element } from 'chart.js' with { 'resolution-mode': 'import' };
3
+ export default class TreemapElement extends Element<TreemapConfig, TreemapOptions> {
4
+ static readonly id = "treemap";
5
+ static readonly defaults: {
6
+ borderRadius: number;
7
+ borderWidth: number;
8
+ captions: {
9
+ align: undefined;
10
+ color: string;
11
+ display: boolean;
12
+ font: {};
13
+ formatter: (ctx: TreemapScriptableContext) => string;
14
+ overflow: string;
15
+ padding: number;
16
+ textAlign: undefined;
17
+ };
18
+ labels: {
19
+ align: string;
20
+ color: string;
21
+ display: boolean;
22
+ font: {};
23
+ formatter(ctx: TreemapScriptableContext): string | string[];
24
+ overflow: string;
25
+ padding: number;
26
+ position: string;
27
+ textAlign: undefined;
28
+ wrap: boolean;
29
+ };
30
+ };
31
+ static readonly descriptors: {
32
+ _indexable: boolean;
33
+ _scriptable: boolean;
34
+ captions: {
35
+ _fallback: boolean;
36
+ _scriptable: (name: string) => boolean;
37
+ };
38
+ labels: {
39
+ _fallback: boolean;
40
+ _scriptable: (name: string) => boolean;
41
+ };
42
+ };
43
+ static readonly defaultRoutes: {
44
+ backgroundColor: string;
45
+ borderColor: string;
46
+ };
47
+ $context?: TreemapScriptableContext;
48
+ width: number | undefined;
49
+ height: number | undefined;
50
+ constructor(cfg?: Partial<TreemapConfig> & {
51
+ options?: TreemapOptions;
52
+ });
53
+ draw(ctx: CanvasRenderingContext2D, data?: TreemapDataPoint, layout?: TreemapLayoutOptions): void;
54
+ inRange(mouseX: number, mouseY: number, useFinalPosition?: boolean): boolean;
55
+ inXRange(mouseX: number, useFinalPosition?: boolean): boolean;
56
+ inYRange(mouseY: number, useFinalPosition?: boolean): boolean;
57
+ getCenterPoint(useFinalPosition?: boolean): {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ tooltipPosition(): {
62
+ x: number;
63
+ y: number;
64
+ };
65
+ }
package/dist/element.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TreemapConfig, TreemapDataPoint, TreemapLayoutOptions, TreemapOptions, TreemapScriptableContext } from './types';
1
+ import type { TreemapConfig, TreemapDataPoint, TreemapLayoutOptions, TreemapOptions, TreemapScriptableContext } from './types.js';
2
2
  import { Element } from 'chart.js';
3
3
  export default class TreemapElement extends Element<TreemapConfig, TreemapOptions> {
4
4
  static readonly id = "treemap";
@@ -0,0 +1,38 @@
1
+ import type { BorderRadius, Element } from 'chart.js' with { 'resolution-mode': 'import' };
2
+ import type { TreemapBorderRadius, TreemapConfig, TreemapOptions } from './types.cjs';
3
+ export type DrawRect = {
4
+ active?: boolean;
5
+ h: number;
6
+ radius: TreemapBorderRadius;
7
+ w: number;
8
+ x: number;
9
+ y: number;
10
+ };
11
+ type TreemapElementBase = Element<TreemapConfig, TreemapOptions>;
12
+ export declare function boundingRects(rect: TreemapElementBase): {
13
+ inner: {
14
+ active: boolean;
15
+ h: number;
16
+ radius: {
17
+ bottomLeft: number;
18
+ bottomRight: number;
19
+ topLeft: number;
20
+ topRight: number;
21
+ };
22
+ w: number;
23
+ x: number;
24
+ y: number;
25
+ };
26
+ outer: {
27
+ active: boolean;
28
+ h: number;
29
+ radius: Required<BorderRadius>;
30
+ w: number;
31
+ x: number;
32
+ y: number;
33
+ };
34
+ };
35
+ export declare function inRange(rect: TreemapElementBase, x: number | null, y: number | null, useFinalPosition?: boolean): boolean;
36
+ export declare function hasRadius(radius: TreemapBorderRadius): number;
37
+ export declare function addNormalRectPath(ctx: CanvasRenderingContext2D, rect: DrawRect): void;
38
+ export {};
@@ -1,5 +1,5 @@
1
- import type { Element } from 'chart.js';
2
- import type { TreemapBorderRadius, TreemapConfig, TreemapOptions } from './types';
1
+ import type { BorderRadius, Element } from 'chart.js';
2
+ import type { TreemapBorderRadius, TreemapConfig, TreemapOptions } from './types.js';
3
3
  export type DrawRect = {
4
4
  active?: boolean;
5
5
  h: number;
@@ -26,7 +26,7 @@ export declare function boundingRects(rect: TreemapElementBase): {
26
26
  outer: {
27
27
  active: boolean;
28
28
  h: number;
29
- radius: Required<import("chart.js").BorderRadius>;
29
+ radius: Required<BorderRadius>;
30
30
  w: number;
31
31
  x: number;
32
32
  y: number;
@@ -0,0 +1,5 @@
1
+ import TreemapController from './controller.cjs';
2
+ import TreemapElement from './element.cjs';
3
+ export type { LabelAlign, LabelOverflow, LabelPosition, TreemapConfig, TreemapControllerDatasetOptions, TreemapDataPoint, TreemapElement as TreemapElementType, TreemapOptions, } from './types.cjs';
4
+ export * from './utils.cjs';
5
+ export { TreemapController, TreemapElement };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import TreemapController from './controller';
2
- import TreemapElement from './element';
3
- export type { LabelAlign, LabelOverflow, LabelPosition, TreemapConfig, TreemapControllerDatasetOptions, TreemapDataPoint, TreemapElement as TreemapElementType, TreemapOptions, } from './types';
4
- export * from './utils';
1
+ import TreemapController from './controller.js';
2
+ import TreemapElement from './element.js';
3
+ export type { LabelAlign, LabelOverflow, LabelPosition, TreemapConfig, TreemapControllerDatasetOptions, TreemapDataPoint, TreemapElement as TreemapElementType, TreemapOptions, } from './types.js';
4
+ export * from './utils.js';
5
5
  export { TreemapController, TreemapElement };
@@ -0,0 +1,4 @@
1
+ export type { LabelAlign, LabelOverflow, LabelPosition, TreemapConfig, TreemapControllerDatasetOptions, TreemapDataPoint, TreemapElement as TreemapElementType, TreemapOptions, } from './types.cjs';
2
+ export { default as TreemapController } from './controller.cjs';
3
+ export { default as TreemapElement } from './element.cjs';
4
+ export { flattenTree } from './utils.cjs';
@@ -1,4 +1,4 @@
1
- export type { LabelAlign, LabelOverflow, LabelPosition, TreemapConfig, TreemapControllerDatasetOptions, TreemapDataPoint, TreemapElement as TreemapElementType, TreemapOptions, } from './types';
2
- export { default as TreemapController } from './controller';
3
- export { default as TreemapElement } from './element';
4
- export { flattenTree } from './utils';
1
+ export type { LabelAlign, LabelOverflow, LabelPosition, TreemapConfig, TreemapControllerDatasetOptions, TreemapDataPoint, TreemapElement as TreemapElementType, TreemapOptions, } from './types.js';
2
+ export { default as TreemapController } from './controller.js';
3
+ export { default as TreemapElement } from './element.js';
4
+ export { flattenTree } from './utils.js';
@@ -0,0 +1,29 @@
1
+ import type { DrawRect } from './geometry.cjs';
2
+ import type { TreemapDataPoint, TreemapDisplayMode, TreemapOthers, TreemapValueScale } from './types.cjs';
3
+ export type LayoutOptions = {
4
+ borderWidth: any;
5
+ captions: any;
6
+ displayMode: TreemapDisplayMode;
7
+ groups: any[];
8
+ leafKey: string;
9
+ others: false | TreemapOthers;
10
+ spacing: number;
11
+ unsorted: boolean;
12
+ valueScale: TreemapValueScale;
13
+ };
14
+ /** A node while the layout is being built; `_children` is dropped before use. */
15
+ export type LayoutNode = TreemapDataPoint & {
16
+ _children?: LayoutNode[];
17
+ };
18
+ /** Draw order: a set of siblings, then the descendants of each in turn. */
19
+ export declare function flattenNodes(nodes: LayoutNode[]): LayoutNode[];
20
+ /** Writes the geometry for a whole tree of nodes, then applies headerBoxes. */
21
+ export declare function layoutNodes(nodes: LayoutNode[], rect: any, layout: LayoutOptions): void;
22
+ /**
23
+ * The hierarchy pass on its own: the nested nodes, in draw order, with no
24
+ * geometry. Takes no rectangle, which is the whole point - the controller needs
25
+ * the node count before the chart area is known.
26
+ */
27
+ export declare function buildNodes(tree: any, keys: string[], layout: LayoutOptions): LayoutNode[];
28
+ /** Turns the user's input into the flat list of rectangles the chart draws. */
29
+ export declare function buildData(tree: any, keys: string[], mainRect: DrawRect, layout: LayoutOptions): TreemapDataPoint[];
package/dist/layout.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { DrawRect } from './geometry';
2
- import type { TreemapDataPoint, TreemapDisplayMode, TreemapOthers, TreemapValueScale } from './types';
1
+ import type { DrawRect } from './geometry.js';
2
+ import type { TreemapDataPoint, TreemapDisplayMode, TreemapOthers, TreemapValueScale } from './types.js';
3
3
  export type LayoutOptions = {
4
4
  borderWidth: any;
5
5
  captions: any;
@@ -0,0 +1,15 @@
1
+ import type { TreemapBorderRadius, TreemapBorderWidth, TreemapLayoutOptions, TreemapOptions } from './types.cjs';
2
+ /**
3
+ * Options that shape the whole dataset's layout rather than a single element.
4
+ * They live in the controller's defaults; the element receives the resolved
5
+ * values as an argument to `draw`.
6
+ */
7
+ export declare const layoutDefaults: TreemapLayoutOptions;
8
+ export type ParsedBorderWidth = {
9
+ b: number;
10
+ l: number;
11
+ r: number;
12
+ t: number;
13
+ };
14
+ export declare function parseBorderWidth(value: TreemapBorderWidth, maxW: number, maxH: number): ParsedBorderWidth;
15
+ export declare function parseBorderRadius(value: TreemapOptions['borderRadius'], maxW: number, maxH: number): TreemapBorderRadius;
package/dist/options.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TreemapBorderRadius, TreemapBorderWidth, TreemapLayoutOptions, TreemapOptions } from './types';
1
+ import type { TreemapBorderRadius, TreemapBorderWidth, TreemapLayoutOptions, TreemapOptions } from './types.js';
2
2
  /**
3
3
  * Options that shape the whole dataset's layout rather than a single element.
4
4
  * They live in the controller's defaults; the element receives the resolved
@@ -0,0 +1,18 @@
1
+ export default class Rect {
2
+ [key: string]: any;
3
+ rtl: boolean;
4
+ unsorted: boolean;
5
+ x: number;
6
+ y: number;
7
+ _ix: number;
8
+ _iy: number;
9
+ w: number;
10
+ h: number;
11
+ constructor(r?: any);
12
+ get area(): number;
13
+ get iw(): number;
14
+ get ih(): number;
15
+ get dir(): "x" | "y";
16
+ get side(): number;
17
+ map(arr: any): void;
18
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Where the layout weight lives when `valueScale` is not linear. Non-enumerable
3
+ * on the node, so `ctx.raw` keeps the shape it has always had.
4
+ */
5
+ export declare const WEIGHT_KEY = "_weight";
6
+ /**
7
+ * Builds the nodes for one set of siblings, without any geometry.
8
+ *
9
+ * Everything here depends only on the data: which item a node came from, its
10
+ * value, its group and level. The rectangle is not involved, which is what lets
11
+ * the controller know how many elements it needs before the chart area is known.
12
+ */
13
+ export declare function toNodes(values: any[], keys: string[], grp?: string, lvl?: number): any[];
14
+ /** Orders a set of siblings the way the layout draws them: largest first. */
15
+ export declare function sortNodes(nodes: any[], weighted?: boolean): void;
16
+ /**
17
+ * Packs already-ordered nodes into the rectangle, writing `x`, `y`, `w`, `h`,
18
+ * the row sum `s` and the normalized area `a` onto them.
19
+ */
20
+ export declare function packInto(nodes: any[], rectangle: any, weighted?: boolean): void;
21
+ export default function squarify(values: any[], rectangle: any, keys?: string[], grp?: string, lvl?: number, gsum?: number): any[];
@@ -0,0 +1,18 @@
1
+ export default class StatArray {
2
+ key: string;
3
+ ratio: number;
4
+ _arr: any[];
5
+ _hist: any[];
6
+ sum: number;
7
+ nsum: number;
8
+ min: number;
9
+ max: number;
10
+ nmin: number;
11
+ nmax: number;
12
+ constructor(key: string, ratio: number);
13
+ get length(): number;
14
+ reset(): void;
15
+ push(o: any): void;
16
+ pushIf(o: any, fn: any, ...args: any[]): any;
17
+ get(): any[];
18
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Color } from 'chart.js';
2
- import type { DrawRect } from '../geometry';
3
- import type { TreemapLabelsOptions } from '../types';
4
- import type { Font, LabelSize } from './measure';
2
+ import type { DrawRect } from '../geometry.js';
3
+ import type { TreemapLabelsOptions } from '../types.js';
4
+ import type { Font, LabelSize } from './measure.js';
5
5
  /**
6
6
  * One block of text ready to draw: the lines, the styles they are drawn with,
7
7
  * and where the block's top edge sits. Captions and labels differ only in how
@@ -1,6 +1,6 @@
1
- import type { DrawRect } from '../geometry';
2
- import type { TreemapLabelsOptions } from '../types';
3
- import type { Font, LabelSize } from './measure';
1
+ import type { DrawRect } from '../geometry.js';
2
+ import type { TreemapLabelsOptions } from '../types.js';
3
+ import type { Font, LabelSize } from './measure.js';
4
4
  export declare function sliceTextToFitWidth(ctx: CanvasRenderingContext2D, text: string, width: number, fonts: Font[]): string;
5
5
  export declare function applyEllipsis(ctx: CanvasRenderingContext2D, lines: string[], styles: number[], fonts: Font[], maxWidth: number, maxHeight: number): {
6
6
  lines: string[];
@@ -1,6 +1,6 @@
1
1
  import type { Element } from 'chart.js';
2
- import type { DrawRect } from '../geometry';
3
- import type { TreemapCaptionsOptions, TreemapConfig, TreemapDataPoint, TreemapDisplayMode, TreemapLayoutOptions, TreemapOptions, TreemapScriptableContext } from '../types';
2
+ import type { DrawRect } from '../geometry.js';
3
+ import type { TreemapCaptionsOptions, TreemapConfig, TreemapDataPoint, TreemapDisplayMode, TreemapLayoutOptions, TreemapOptions, TreemapScriptableContext } from '../types.js';
4
4
  type RectSize = {
5
5
  h: number;
6
6
  w: number;
@@ -1,4 +1,4 @@
1
- import type { Font } from './measure';
1
+ import type { Font } from './measure.js';
2
2
  export declare function wrapToWidth(ctx: CanvasRenderingContext2D, text: string, font: Font, width: number): string[];
3
3
  export declare function toLines(ctx: CanvasRenderingContext2D, content: string | string[], fonts: Font[], width: number, wrap: boolean): {
4
4
  lines: string[];
@@ -0,0 +1,167 @@
1
+ import type {} from './types.js' with { 'resolution-mode': 'import' };
2
+ import type { BorderRadius, Chart, ChartComponent, Color, CoreChartOptions, DatasetController, Element, FontSpec, Scriptable, ScriptableContext, VisualElement } from 'chart.js' with { 'resolution-mode': 'import' };
3
+ export type AnyObject = Record<string, unknown>;
4
+ export type LabelPosition = 'top' | 'middle' | 'bottom';
5
+ export type LabelAlign = 'left' | 'center' | 'right';
6
+ export type LabelOverflow = 'cut' | 'ellipsis' | 'fit' | 'hidden';
7
+ /**
8
+ * How a value becomes an area. `linear` keeps area proportional to value;
9
+ * the others compress a wide range so small items stay visible.
10
+ */
11
+ /**
12
+ * The part of the chart area a dataset lays out into, as fractions of it.
13
+ * Two datasets can then sit side by side instead of painting over each other.
14
+ */
15
+ export type TreemapRegion = {
16
+ left?: number;
17
+ top?: number;
18
+ width?: number;
19
+ height?: number;
20
+ };
21
+ export type TreemapOthers = {
22
+ /** Bucket a leaf below this share of its siblings' total layout weight. */
23
+ threshold: number;
24
+ label?: string;
25
+ /** Only bucket when at least this many leaves fall below the threshold. */
26
+ minCount?: number;
27
+ };
28
+ export type TreemapValueScale<DType = AnyObject> = 'linear' | 'log' | 'sqrt' | ((value: number, item: DType) => number);
29
+ export type TreemapDisplayMode = 'containerBoxes' | 'headerBoxes';
30
+ export type TreemapBorderWidth = number | Partial<Record<'bottom' | 'left' | 'right' | 'top', number>>;
31
+ export type TreemapBorderRadius = Required<BorderRadius>;
32
+ export type TreemapFontSpec = Partial<FontSpec>;
33
+ export type TreemapScriptableContext = ScriptableContext<'treemap'> & {
34
+ raw: TreemapDataPoint;
35
+ };
36
+ export type TreemapFormatter<T> = T | ((context: TreemapScriptableContext) => T);
37
+ export type TreemapControllerDatasetCaptionsOptions = {
38
+ align?: Scriptable<LabelAlign, TreemapScriptableContext>;
39
+ overflow?: Scriptable<LabelOverflow, TreemapScriptableContext>;
40
+ textAlign?: Scriptable<LabelAlign, TreemapScriptableContext>;
41
+ color?: Scriptable<Color, TreemapScriptableContext>;
42
+ display?: boolean;
43
+ formatter?: TreemapFormatter<string>;
44
+ font?: TreemapFontSpec;
45
+ hoverColor?: Scriptable<Color, TreemapScriptableContext>;
46
+ hoverFont?: TreemapFontSpec;
47
+ padding?: number;
48
+ };
49
+ export type TreemapControllerDatasetLabelsOptions = {
50
+ align?: Scriptable<LabelAlign, TreemapScriptableContext>;
51
+ textAlign?: Scriptable<LabelAlign, TreemapScriptableContext>;
52
+ wrap?: boolean;
53
+ color?: Scriptable<Color | Color[], TreemapScriptableContext>;
54
+ display?: boolean;
55
+ formatter?: TreemapFormatter<string | string[]>;
56
+ font?: Scriptable<TreemapFontSpec | TreemapFontSpec[], TreemapScriptableContext>;
57
+ hoverColor?: Scriptable<Color | Color[], TreemapScriptableContext>;
58
+ hoverFont?: Scriptable<TreemapFontSpec | TreemapFontSpec[], TreemapScriptableContext>;
59
+ overflow?: Scriptable<LabelOverflow, TreemapScriptableContext>;
60
+ padding?: number;
61
+ position?: Scriptable<LabelPosition, TreemapScriptableContext>;
62
+ };
63
+ export type TreemapCaptionsOptions = {
64
+ align?: LabelAlign;
65
+ overflow?: LabelOverflow;
66
+ textAlign?: LabelAlign;
67
+ color: Color;
68
+ display?: boolean;
69
+ font: TreemapFontSpec;
70
+ formatter?: TreemapFormatter<string>;
71
+ hoverColor?: Color;
72
+ hoverFont?: TreemapFontSpec;
73
+ padding: number;
74
+ };
75
+ export type TreemapLabelsOptions = {
76
+ align: LabelAlign;
77
+ textAlign?: LabelAlign;
78
+ wrap?: boolean;
79
+ color: Color | Color[];
80
+ display?: boolean;
81
+ font: TreemapFontSpec | TreemapFontSpec[];
82
+ formatter?: TreemapFormatter<string | string[]>;
83
+ hoverColor?: Color | Color[];
84
+ hoverFont?: TreemapFontSpec | TreemapFontSpec[];
85
+ overflow: LabelOverflow;
86
+ padding: number;
87
+ position: LabelPosition;
88
+ };
89
+ export interface TreemapControllerDatasetOptions<DType> {
90
+ displayMode?: TreemapDisplayMode;
91
+ rtl?: boolean;
92
+ spacing?: number;
93
+ others?: false | TreemapOthers;
94
+ region?: TreemapRegion;
95
+ unsorted?: boolean;
96
+ valueScale?: TreemapValueScale<DType>;
97
+ backgroundColor?: Scriptable<Color, TreemapScriptableContext>;
98
+ borderColor?: Scriptable<Color, TreemapScriptableContext>;
99
+ borderRadius?: Scriptable<number | Partial<BorderRadius>, TreemapScriptableContext>;
100
+ borderWidth?: number;
101
+ hoverBackgroundColor?: Scriptable<Color, TreemapScriptableContext>;
102
+ hoverBorderColor?: Scriptable<Color, TreemapScriptableContext>;
103
+ hoverBorderWidth?: number;
104
+ captions?: TreemapControllerDatasetCaptionsOptions;
105
+ labels?: TreemapControllerDatasetLabelsOptions;
106
+ label?: string;
107
+ /**
108
+ * Numbers, objects, or a nested object addressed through `leafKey`.
109
+ * The array is read, never written: the layout nodes live in the parsed data.
110
+ */
111
+ data: number[] | DType[] | AnyObject;
112
+ groups?: Array<keyof DType>;
113
+ sumKeys?: Array<keyof DType>;
114
+ leafKey?: keyof DType;
115
+ key?: keyof DType;
116
+ }
117
+ export interface TreemapDataPoint {
118
+ x: number;
119
+ y: number;
120
+ w: number;
121
+ h: number;
122
+ v: number;
123
+ s: number;
124
+ l?: number;
125
+ g?: string;
126
+ gs?: number;
127
+ vs?: AnyObject;
128
+ _data?: AnyObject;
129
+ isLeaf?: boolean;
130
+ /** Set on the synthetic node that absorbed the items below `others.threshold`. */
131
+ isOthers?: boolean;
132
+ /** headerBoxes: the group's caption does not fit, so nothing is drawn. */
133
+ hidden?: boolean;
134
+ }
135
+
136
+ /** Element scope: everything that can differ from one rectangle to the next. */
137
+ export interface TreemapOptions {
138
+ backgroundColor: Color;
139
+ borderColor: Color;
140
+ borderRadius: number | Partial<BorderRadius>;
141
+ borderWidth: TreemapBorderWidth;
142
+ captions: TreemapCaptionsOptions;
143
+ labels: TreemapLabelsOptions;
144
+ }
145
+ /** Dataset scope: resolved once per dataset and passed into layout and draw. */
146
+ export interface TreemapLayoutOptions {
147
+ displayMode: TreemapDisplayMode;
148
+ rtl: boolean;
149
+ spacing: number;
150
+ }
151
+ export interface TreemapConfig {
152
+ x: number;
153
+ y: number;
154
+ width: number;
155
+ height: number;
156
+ }
157
+ export type TreemapController = DatasetController;
158
+ export type TreemapControllerComponent = ChartComponent & {
159
+ prototype: TreemapController;
160
+ new (chart: Chart, datasetIndex: number): TreemapController;
161
+ };
162
+ export interface TreemapElement<T extends TreemapConfig = TreemapConfig, O extends TreemapOptions = TreemapOptions> extends Element<T, O>, VisualElement {
163
+ }
164
+ export type TreemapElementComponent = ChartComponent & {
165
+ prototype: TreemapElement;
166
+ new (cfg: TreemapConfig): TreemapElement;
167
+ };
@@ -0,0 +1,17 @@
1
+ import type { AnyObject } from './types.cjs';
2
+ export declare const getGroupKey: (lvl: unknown) => string;
3
+ /**
4
+ * Flattens a nested object into the array form of `data`.
5
+ *
6
+ * The controller does this at runtime, so JavaScript configurations never need
7
+ * it. TypeScript users who would rather pass an array than a generic can call
8
+ * it up front.
9
+ */
10
+ export declare function flattenTree<T = AnyObject>(tree: AnyObject, keys: string[], leafKey: string): T[];
11
+ export declare function normalizeTreeToArray(keys: string[], leafKey: string, obj: Record<string, any>): Record<string, any>[];
12
+ export declare function flatten(input: any[]): any[];
13
+ export declare function group(values: Record<string, any>[], grp: string, keys: string[], leafKey: string, mainGrp?: string, mainValue?: any, groups?: string[], allGroups?: string[], groupIndex?: number): Record<string, any>[];
14
+ export declare function index(values: any[], key: string): string;
15
+ export declare function sort(values: any[], key?: string): void;
16
+ export declare function sum(values: any[], key?: string): number;
17
+ export declare function requireVersion(pkg: string, min: string, ver: string, strict?: boolean): boolean;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyObject } from './types';
1
+ import type { AnyObject } from './types.js';
2
2
  export declare const getGroupKey: (lvl: unknown) => string;
3
3
  /**
4
4
  * Flattens a nested object into the array form of `data`.
package/package.json CHANGED
@@ -7,11 +7,11 @@
7
7
  "devDependencies": {
8
8
  "@astrojs/check": "^0.9.9",
9
9
  "@astrojs/mdx": "^8.0.0",
10
- "@astrojs/starlight": "^0.42.0",
10
+ "@astrojs/starlight": "^0.43.1",
11
11
  "@biomejs/biome": "^2.4.14",
12
12
  "@emnapi/core": "^1.11.2",
13
13
  "@emnapi/runtime": "^1.11.2",
14
- "@kurkle/astro-chartjs-editor": "^1.0.0",
14
+ "@kurkle/astro-chartjs-editor": "^1.3.1",
15
15
  "@kurkle/configs": "^1.5.1",
16
16
  "@napi-rs/canvas": "^1.0.0",
17
17
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -29,10 +29,10 @@
29
29
  "chart.js": "^4.0.1",
30
30
  "chartjs-plugin-datalabels": "^2.2.0",
31
31
  "chartjs-plugin-zoom": "^2.0.0",
32
+ "chartjs-test-utils": "^1.1.0",
32
33
  "concurrently": "^10.0.3",
33
34
  "conventional-changelog-conventionalcommits": "^9.3.1",
34
35
  "globals": "^17.0.0",
35
- "pixelmatch": "^7.1.0",
36
36
  "playwright": "^1.63.0",
37
37
  "png-to-ico": "^3.0.2",
38
38
  "rollup": "^4.21.2",
@@ -46,10 +46,15 @@
46
46
  },
47
47
  "exports": {
48
48
  ".": {
49
- "import": "./dist/chartjs-chart-treemap.esm.js",
50
- "require": "./dist/chartjs-chart-treemap.cjs",
51
- "script": "./dist/chartjs-chart-treemap.min.js",
52
- "types": "./dist/index.esm.d.ts"
49
+ "import": {
50
+ "types": "./dist/index.esm.d.ts",
51
+ "default": "./dist/chartjs-chart-treemap.esm.js"
52
+ },
53
+ "require": {
54
+ "types": "./dist/index.d.cts",
55
+ "default": "./dist/chartjs-chart-treemap.cjs"
56
+ },
57
+ "script": "./dist/chartjs-chart-treemap.min.js"
53
58
  },
54
59
  "./package.json": "./package.json"
55
60
  },
@@ -78,7 +83,7 @@
78
83
  "scripts": {
79
84
  "autobuild": "rollup -c -w",
80
85
  "bench": "node bench/update.mjs",
81
- "build": "rollup -c && tsc -p tsconfig.json --emitDeclarationOnly",
86
+ "build": "rollup -c && tsc -p tsconfig.json --emitDeclarationOnly && kurkle-build-cjs-types",
82
87
  "dev": "vitest --config vitest.browser.config.ts",
83
88
  "docs": "npm run build && astro build",
84
89
  "docs:dev": "npm run build && astro dev",
@@ -87,16 +92,21 @@
87
92
  "format": "biome check --write",
88
93
  "icons": "kurkle-generate-icons",
89
94
  "lint": "biome check",
95
+ "predev": "playwright install chromium firefox",
90
96
  "predocs": "npm run docs:version",
91
97
  "predocs:dev": "npm run docs:version",
98
+ "prefixtures:update": "playwright install chromium",
92
99
  "prepack": "npm run build",
93
100
  "prepare": "git config core.hooksPath .githooks || true",
94
- "test": "npm run test:unit && npm run test:fixture && npm run test:integration:browser-module && npm run test:integration:node-commonjs && npm run test:integration:node-module && npm run test:integration:webpack",
101
+ "pretest:fixture": "playwright install chromium firefox",
102
+ "pretest:integration:browser-module": "playwright install chromium",
103
+ "test": "npm run test:unit && npm run test:fixture && npm run test:integration:browser-module && npm run test:integration:node-commonjs && npm run test:integration:node-module && npm run test:integration:webpack && npm run test:pack",
95
104
  "test:fixture": "vitest run --config vitest.browser.config.ts --coverage",
96
105
  "test:integration:browser-module": "vitest run --config vitest.integration.config.ts",
97
106
  "test:integration:node-commonjs": "node test/integration/node-commonjs/test.cjs",
98
107
  "test:integration:node-module": "node test/integration/node-module/test.mjs",
99
108
  "test:integration:webpack": "node test/integration/webpack/test.mjs",
109
+ "test:pack": "kurkle-check-package",
100
110
  "test:unit": "vitest run --config vitest.config.ts --coverage",
101
111
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json && tsc -p tsconfig.json --emitDeclarationOnly && tsc --noEmit -p test/types/ && tsc --noEmit -p tsconfig.tooling.json",
102
112
  "typecheck:docs": "astro check"
@@ -108,5 +118,5 @@
108
118
  "type": "module",
109
119
  "types": "dist/index.esm.d.ts",
110
120
  "unpkg": "dist/chartjs-chart-treemap.min.js",
111
- "version": "5.0.0-next.9"
121
+ "version": "5.0.1"
112
122
  }