chartjs-chart-treemap 4.2.2 → 5.0.0-next.10
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/README.md +41 -1
- package/dist/chartjs-chart-treemap.cjs +777 -382
- package/dist/chartjs-chart-treemap.esm.js +781 -404
- package/dist/chartjs-chart-treemap.min.js +2 -2
- package/dist/chartjs-chart-treemap.min.js.map +1 -1
- package/dist/controller.d.cts +62 -0
- package/dist/controller.d.ts +39 -4
- package/dist/element.d.cts +65 -0
- package/dist/element.d.ts +6 -15
- package/dist/geometry.d.cts +38 -0
- package/dist/geometry.d.ts +3 -3
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.esm.d.cts +4 -0
- package/dist/index.esm.d.ts +4 -3
- package/dist/layout.d.cts +29 -0
- package/dist/layout.d.ts +29 -0
- package/dist/options.d.cts +15 -0
- package/dist/options.d.ts +7 -1
- package/dist/rect.d.cts +18 -0
- package/dist/rect.d.ts +1 -1
- package/dist/squarify.d.cts +21 -0
- package/dist/squarify.d.ts +20 -0
- package/dist/statArray.d.cts +18 -0
- package/dist/text/draw.d.ts +30 -0
- package/dist/text/fit.d.ts +9 -0
- package/dist/{text.d.ts → text/index.d.ts} +3 -4
- package/dist/text/measure.d.ts +26 -0
- package/dist/text/wrap.d.ts +6 -0
- package/dist/types.d.cts +167 -0
- package/dist/types.d.ts +54 -28
- package/dist/utils.d.cts +17 -0
- package/dist/utils.d.ts +11 -2
- package/package.json +46 -35
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { LayoutNode, LayoutOptions } from './layout.cjs';
|
|
2
|
+
import type { DatasetController } from 'chart.js' with { 'resolution-mode': 'import' };
|
|
3
|
+
export default class TreemapController extends DatasetController {
|
|
4
|
+
static readonly id: string;
|
|
5
|
+
static readonly defaults: Record<string, unknown>;
|
|
6
|
+
static readonly descriptors: Record<string, unknown>;
|
|
7
|
+
static readonly overrides: Record<string, unknown>;
|
|
8
|
+
static readonly beforeRegister: () => void;
|
|
9
|
+
static readonly afterRegister: () => void;
|
|
10
|
+
static readonly afterUnregister: () => void;
|
|
11
|
+
dataElementType: new () => any;
|
|
12
|
+
options: any;
|
|
13
|
+
_rect: any;
|
|
14
|
+
_rectChanged: boolean;
|
|
15
|
+
_nodes: LayoutNode[];
|
|
16
|
+
_regionWarned: boolean;
|
|
17
|
+
_layoutDirty: boolean;
|
|
18
|
+
_fingerprint: string | undefined;
|
|
19
|
+
constructor(chart: any, datasetIndex: number);
|
|
20
|
+
initialize(): void;
|
|
21
|
+
getMinMax(scale: any): {
|
|
22
|
+
max: number;
|
|
23
|
+
min: number;
|
|
24
|
+
};
|
|
25
|
+
configure(): void;
|
|
26
|
+
/**
|
|
27
|
+
* The part of the chart area this dataset lays out into.
|
|
28
|
+
*
|
|
29
|
+
* Every dataset shares the chart's single pair of linear scales, whose max is
|
|
30
|
+
* the full chart area in pixels, so a region is just a rectangle in that
|
|
31
|
+
* space and no scale has to change.
|
|
32
|
+
*/
|
|
33
|
+
_regionBounds(w: number, h: number): {
|
|
34
|
+
h: number;
|
|
35
|
+
w: number;
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Options that shape the layout rather than a single rectangle, resolved once
|
|
41
|
+
* per dataset. Reading them from `this.options` rather than from the raw
|
|
42
|
+
* dataset is what makes `options.datasets.treemap` work for all of them.
|
|
43
|
+
*/
|
|
44
|
+
_layoutOptions(): LayoutOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Chart.js calls this before `configure()`, so the chart area is not
|
|
47
|
+
* available here - see the hierarchy pass in `./layout`, which does not need
|
|
48
|
+
* one. Elements are created from the parsed nodes rather than from
|
|
49
|
+
* `dataset.data`, because a treemap with groups has more rectangles than the
|
|
50
|
+
* user supplied rows.
|
|
51
|
+
*/
|
|
52
|
+
buildOrUpdateElements(_resetNewElements?: boolean): void;
|
|
53
|
+
parse(_start: number, _count: number): void;
|
|
54
|
+
getContext(index: number, active?: boolean, mode?: string): any;
|
|
55
|
+
getLabelAndValue(index: number): {
|
|
56
|
+
label: string;
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
59
|
+
update(mode: any): void;
|
|
60
|
+
updateElements(rects: any[], start: number, count: number, mode: any): void;
|
|
61
|
+
draw(): void;
|
|
62
|
+
}
|
package/dist/controller.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LayoutNode, LayoutOptions } from './layout.js';
|
|
1
2
|
import { DatasetController } from 'chart.js';
|
|
2
3
|
export default class TreemapController extends DatasetController {
|
|
3
4
|
static readonly id: string;
|
|
@@ -7,13 +8,14 @@ export default class TreemapController extends DatasetController {
|
|
|
7
8
|
static readonly beforeRegister: () => void;
|
|
8
9
|
static readonly afterRegister: () => void;
|
|
9
10
|
static readonly afterUnregister: () => void;
|
|
11
|
+
dataElementType: new () => any;
|
|
10
12
|
options: any;
|
|
11
|
-
_groups: any[] | undefined;
|
|
12
|
-
_keys: any[] | undefined;
|
|
13
13
|
_rect: any;
|
|
14
14
|
_rectChanged: boolean;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
_nodes: LayoutNode[];
|
|
16
|
+
_regionWarned: boolean;
|
|
17
|
+
_layoutDirty: boolean;
|
|
18
|
+
_fingerprint: string | undefined;
|
|
17
19
|
constructor(chart: any, datasetIndex: number);
|
|
18
20
|
initialize(): void;
|
|
19
21
|
getMinMax(scale: any): {
|
|
@@ -21,6 +23,39 @@ export default class TreemapController extends DatasetController {
|
|
|
21
23
|
min: number;
|
|
22
24
|
};
|
|
23
25
|
configure(): void;
|
|
26
|
+
/**
|
|
27
|
+
* The part of the chart area this dataset lays out into.
|
|
28
|
+
*
|
|
29
|
+
* Every dataset shares the chart's single pair of linear scales, whose max is
|
|
30
|
+
* the full chart area in pixels, so a region is just a rectangle in that
|
|
31
|
+
* space and no scale has to change.
|
|
32
|
+
*/
|
|
33
|
+
_regionBounds(w: number, h: number): {
|
|
34
|
+
h: number;
|
|
35
|
+
w: number;
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Options that shape the layout rather than a single rectangle, resolved once
|
|
41
|
+
* per dataset. Reading them from `this.options` rather than from the raw
|
|
42
|
+
* dataset is what makes `options.datasets.treemap` work for all of them.
|
|
43
|
+
*/
|
|
44
|
+
_layoutOptions(): LayoutOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Chart.js calls this before `configure()`, so the chart area is not
|
|
47
|
+
* available here - see the hierarchy pass in `./layout`, which does not need
|
|
48
|
+
* one. Elements are created from the parsed nodes rather than from
|
|
49
|
+
* `dataset.data`, because a treemap with groups has more rectangles than the
|
|
50
|
+
* user supplied rows.
|
|
51
|
+
*/
|
|
52
|
+
buildOrUpdateElements(_resetNewElements?: boolean): void;
|
|
53
|
+
parse(_start: number, _count: number): void;
|
|
54
|
+
getContext(index: number, active?: boolean, mode?: string): any;
|
|
55
|
+
getLabelAndValue(index: number): {
|
|
56
|
+
label: string;
|
|
57
|
+
value: string;
|
|
58
|
+
};
|
|
24
59
|
update(mode: any): void;
|
|
25
60
|
updateElements(rects: any[], start: number, count: number, mode: any): void;
|
|
26
61
|
draw(): void;
|
|
@@ -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, 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";
|
|
@@ -11,18 +11,10 @@ export default class TreemapElement extends Element<TreemapConfig, TreemapOption
|
|
|
11
11
|
display: boolean;
|
|
12
12
|
font: {};
|
|
13
13
|
formatter: (ctx: TreemapScriptableContext) => string;
|
|
14
|
+
overflow: string;
|
|
14
15
|
padding: number;
|
|
16
|
+
textAlign: undefined;
|
|
15
17
|
};
|
|
16
|
-
displayMode: string;
|
|
17
|
-
dividers: {
|
|
18
|
-
display: boolean;
|
|
19
|
-
lineCapStyle: string;
|
|
20
|
-
lineColor: string;
|
|
21
|
-
lineDash: never[];
|
|
22
|
-
lineDashOffset: number;
|
|
23
|
-
lineWidth: number;
|
|
24
|
-
};
|
|
25
|
-
label: undefined;
|
|
26
18
|
labels: {
|
|
27
19
|
align: string;
|
|
28
20
|
color: string;
|
|
@@ -32,10 +24,9 @@ export default class TreemapElement extends Element<TreemapConfig, TreemapOption
|
|
|
32
24
|
overflow: string;
|
|
33
25
|
padding: number;
|
|
34
26
|
position: string;
|
|
27
|
+
textAlign: undefined;
|
|
28
|
+
wrap: boolean;
|
|
35
29
|
};
|
|
36
|
-
rtl: boolean;
|
|
37
|
-
spacing: number;
|
|
38
|
-
unsorted: boolean;
|
|
39
30
|
};
|
|
40
31
|
static readonly descriptors: {
|
|
41
32
|
_indexable: boolean;
|
|
@@ -59,7 +50,7 @@ export default class TreemapElement extends Element<TreemapConfig, TreemapOption
|
|
|
59
50
|
constructor(cfg?: Partial<TreemapConfig> & {
|
|
60
51
|
options?: TreemapOptions;
|
|
61
52
|
});
|
|
62
|
-
draw(ctx: CanvasRenderingContext2D, data?: TreemapDataPoint): void;
|
|
53
|
+
draw(ctx: CanvasRenderingContext2D, data?: TreemapDataPoint, layout?: TreemapLayoutOptions): void;
|
|
63
54
|
inRange(mouseX: number, mouseY: number, useFinalPosition?: boolean): boolean;
|
|
64
55
|
inXRange(mouseX: number, useFinalPosition?: boolean): boolean;
|
|
65
56
|
inYRange(mouseY: number, useFinalPosition?: boolean): boolean;
|
|
@@ -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 {};
|
package/dist/geometry.d.ts
CHANGED
|
@@ -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<
|
|
29
|
+
radius: Required<BorderRadius>;
|
|
30
30
|
w: number;
|
|
31
31
|
x: number;
|
|
32
32
|
y: number;
|
package/dist/index.d.cts
ADDED
|
@@ -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';
|
package/dist/index.esm.d.ts
CHANGED
|
@@ -1,3 +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';
|
|
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
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DrawRect } from './geometry.js';
|
|
2
|
+
import type { TreemapDataPoint, TreemapDisplayMode, TreemapOthers, TreemapValueScale } from './types.js';
|
|
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[];
|
|
@@ -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,10 @@
|
|
|
1
|
-
import type { TreemapBorderRadius, TreemapBorderWidth, TreemapOptions } from './types';
|
|
1
|
+
import type { TreemapBorderRadius, TreemapBorderWidth, TreemapLayoutOptions, TreemapOptions } from './types.js';
|
|
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;
|
|
2
8
|
export type ParsedBorderWidth = {
|
|
3
9
|
b: number;
|
|
4
10
|
l: number;
|
package/dist/rect.d.cts
ADDED
|
@@ -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
|
+
}
|
package/dist/rect.d.ts
CHANGED
|
@@ -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[];
|
package/dist/squarify.d.ts
CHANGED
|
@@ -1 +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;
|
|
1
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Color } from 'chart.js';
|
|
2
|
+
import type { DrawRect } from '../geometry.js';
|
|
3
|
+
import type { TreemapLabelsOptions } from '../types.js';
|
|
4
|
+
import type { Font, LabelSize } from './measure.js';
|
|
5
|
+
/**
|
|
6
|
+
* One block of text ready to draw: the lines, the styles they are drawn with,
|
|
7
|
+
* and where the block's top edge sits. Captions and labels differ only in how
|
|
8
|
+
* they arrive at this, which is why they can share the drawing code.
|
|
9
|
+
*/
|
|
10
|
+
export type TextBlock = {
|
|
11
|
+
/** Where the block sits inside the padded rect. */
|
|
12
|
+
align: CanvasTextAlign;
|
|
13
|
+
/** Vertical clip inset. Zero where the box was sized to hold the text. */
|
|
14
|
+
clipY: number;
|
|
15
|
+
colors: Color[];
|
|
16
|
+
fonts: Font[];
|
|
17
|
+
lines: string[];
|
|
18
|
+
padding: number;
|
|
19
|
+
/** Paragraph each line belongs to, which is what indexes fonts and colours. */
|
|
20
|
+
styles: number[];
|
|
21
|
+
/** How each line sits inside the block. Follows `align` when undefined. */
|
|
22
|
+
textAlign: CanvasTextAlign | undefined;
|
|
23
|
+
top: number;
|
|
24
|
+
/** Width of the widest line, which is the block's own width. */
|
|
25
|
+
width: number;
|
|
26
|
+
};
|
|
27
|
+
export declare function clipToPadding(ctx: CanvasRenderingContext2D, rect: DrawRect, padding: number, clipY: number): void;
|
|
28
|
+
export declare function drawTextBlock(ctx: CanvasRenderingContext2D, rect: DrawRect, block: TextBlock): void;
|
|
29
|
+
export declare function calculateBlockTop(rect: DrawRect, options: TreemapLabelsOptions, labelSize: LabelSize): number;
|
|
30
|
+
export declare function calculateLineX(rect: DrawRect, align: CanvasTextAlign, lineAlign: CanvasTextAlign, padding: number, width: number): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DrawRect } from '../geometry.js';
|
|
2
|
+
import type { TreemapLabelsOptions } from '../types.js';
|
|
3
|
+
import type { Font, LabelSize } from './measure.js';
|
|
4
|
+
export declare function sliceTextToFitWidth(ctx: CanvasRenderingContext2D, text: string, width: number, fonts: Font[]): string;
|
|
5
|
+
export declare function applyEllipsis(ctx: CanvasRenderingContext2D, lines: string[], styles: number[], fonts: Font[], maxWidth: number, maxHeight: number): {
|
|
6
|
+
lines: string[];
|
|
7
|
+
styles: number[];
|
|
8
|
+
};
|
|
9
|
+
export declare function labelToDraw(rect: DrawRect, options: TreemapLabelsOptions, labelSize: LabelSize): number | boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Element } from 'chart.js';
|
|
2
|
-
import type { DrawRect } from '
|
|
3
|
-
import type { TreemapCaptionsOptions, TreemapConfig, TreemapDataPoint, TreemapDisplayMode, TreemapOptions, TreemapScriptableContext } from '
|
|
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;
|
|
@@ -15,6 +15,5 @@ export declare function shouldDrawCaption(displayMode: TreemapDisplayMode, rect:
|
|
|
15
15
|
export declare function getCaptionHeight(displayMode: TreemapDisplayMode, rect: RectHeight, font: {
|
|
16
16
|
lineHeight: number;
|
|
17
17
|
}, padding: number): number;
|
|
18
|
-
export declare function drawText(ctx: CanvasRenderingContext2D, rect: DrawRect, options: TreemapOptions, item: TreemapDataPoint, element: TextElement): void;
|
|
19
|
-
export declare function drawDivider(ctx: CanvasRenderingContext2D, rect: DrawRect, options: TreemapOptions, item: TreemapDataPoint): void;
|
|
18
|
+
export declare function drawText(ctx: CanvasRenderingContext2D, rect: DrawRect, options: TreemapOptions, item: TreemapDataPoint, element: TextElement, layout: TreemapLayoutOptions): void;
|
|
20
19
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toFont } from 'chart.js/helpers';
|
|
2
|
+
export type Font = ReturnType<typeof toFont>;
|
|
3
|
+
export type LabelSize = {
|
|
4
|
+
height: number;
|
|
5
|
+
width: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const fontFor: (fonts: Font[], index: number) => {
|
|
8
|
+
family: string;
|
|
9
|
+
lineHeight: number;
|
|
10
|
+
size: number;
|
|
11
|
+
style: "normal" | "inherit" | "italic" | "oblique" | "initial";
|
|
12
|
+
weight: number | "bold" | "normal" | "lighter" | "bolder";
|
|
13
|
+
string: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function measureLabelSize(ctx: CanvasRenderingContext2D & {
|
|
16
|
+
_measureText?: unknown;
|
|
17
|
+
}, lines: string[], fonts: Font[]): LabelSize;
|
|
18
|
+
export declare function measureLines(ctx: CanvasRenderingContext2D, lines: string[], styles: number[], fonts: Font[]): LabelSize;
|
|
19
|
+
export declare function toFonts(fonts: Font[], fitRatio: number): {
|
|
20
|
+
family: string;
|
|
21
|
+
lineHeight: number;
|
|
22
|
+
size: number;
|
|
23
|
+
style: "normal" | "inherit" | "italic" | "oblique" | "initial";
|
|
24
|
+
weight: number | "bold" | "normal" | "lighter" | "bolder";
|
|
25
|
+
string: string;
|
|
26
|
+
}[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Font } from './measure.js';
|
|
2
|
+
export declare function wrapToWidth(ctx: CanvasRenderingContext2D, text: string, font: Font, width: number): string[];
|
|
3
|
+
export declare function toLines(ctx: CanvasRenderingContext2D, content: string | string[], fonts: Font[], width: number, wrap: boolean): {
|
|
4
|
+
lines: string[];
|
|
5
|
+
styles: number[];
|
|
6
|
+
};
|