stockchart-treemap 1.0.0 → 1.0.2
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/LICENSE +21 -0
- package/README.md +119 -90
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 stockchart-treemap contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,90 +1,119 @@
|
|
|
1
|
-
# stockchart-treemap
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
1
|
+
# stockchart-treemap
|
|
2
|
+
|
|
3
|
+
Standalone TreeMap for Angular: no external runtime dependencies, color scaling by values, custom templates, and multiple data sources. Great for market heatmaps, portfolios, resource hierarchies, or any weighted tree.
|
|
4
|
+
|
|
5
|
+
## Demo
|
|
6
|
+
- StackBlitz: https://stackblitz.com/edit/stackblitz-starters-drgync8z?file=README.md
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
- Angular 20+ standalone component, no Kendo UI or extra runtimes.
|
|
10
|
+
+- Three data source modes: array, `Observable`, or loader function with optional polling.
|
|
11
|
+
_- Palette or value-driven colors (`colorScale` with `min`/`center`/`max`), automatic shades for nested nodes._
|
|
12
|
+
_- Custom tile and title templates; control showing top-level titles._
|
|
13
|
+
_- Click/hover events with the full path to the node; `refreshNow()` for manual refresh._
|
|
14
|
+
_- Layout choices: `squarified` (default) or slice-and-dice (`horizontal` / `vertical`)._
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
```bash
|
|
18
|
+
npm install stockchart-treemap
|
|
19
|
+
```
|
|
20
|
+
Peer deps: `@angular/core` and `@angular/common` 20.x.
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
```ts
|
|
24
|
+
import { Component } from '@angular/core';
|
|
25
|
+
import { TreeMapComponent, TreeMapOptions } from 'stockchart-treemap';
|
|
26
|
+
|
|
27
|
+
@Component({
|
|
28
|
+
standalone: true,
|
|
29
|
+
selector: 'app-treemap-demo',
|
|
30
|
+
imports: [TreeMapComponent],
|
|
31
|
+
template: `
|
|
32
|
+
<stockchart-treemap
|
|
33
|
+
[data]="data"
|
|
34
|
+
[options]="options">
|
|
35
|
+
</stockchart-treemap>
|
|
36
|
+
`
|
|
37
|
+
})
|
|
38
|
+
export class TreemapDemoComponent {
|
|
39
|
+
data = [
|
|
40
|
+
{ name: 'Tech', value: 35, change: 4.2, items: [
|
|
41
|
+
{ name: 'A', value: 20, change: 5.1 },
|
|
42
|
+
{ name: 'B', value: 15, change: 2.0 }
|
|
43
|
+
]},
|
|
44
|
+
{ name: 'Energy', value: 25, change: -3.4 },
|
|
45
|
+
{ name: 'Health', value: 18, change: 1.6 }
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
options: Partial<TreeMapOptions> = {
|
|
49
|
+
textField: 'name',
|
|
50
|
+
valueField: 'value',
|
|
51
|
+
colorValueField: 'change',
|
|
52
|
+
colorScale: { min: '#E53935', center: '#F5F5F5', max: '#2E7D32' },
|
|
53
|
+
colors: [] // keep empty to rely on colorScale
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Data sources
|
|
59
|
+
- `data`: plain array.
|
|
60
|
+
- `data$`: `Observable<T[]>`; the component subscribes and re-renders on updates.
|
|
61
|
+
- `loader`: function returning an array / `Promise` / `Observable`; optionally poll with `refreshMs`.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
loader = () => this.http.get<Item[]>('/api/treemap');
|
|
65
|
+
refreshMs = 5000; // poll every 5s
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Colors and scales
|
|
69
|
+
- Palette: `colors: ['#5B8FF9', '#5AD8A6', ...]` or pairs `[min, max]` to generate a gradient per level.
|
|
70
|
+
- Value-driven gradient: `colorScale: { min, center?, max }` + `colorValueField` (defaults to `valueField`).
|
|
71
|
+
- If your data has no `color` field, the shade is computed automatically.
|
|
72
|
+
|
|
73
|
+
## Layouts
|
|
74
|
+
- `type: 'squarified'` (default, aims for square tiles).
|
|
75
|
+
- `type: 'horizontal' | 'vertical'` — slice-and-dice with alternating orientation by level.
|
|
76
|
+
|
|
77
|
+
## Custom templates
|
|
78
|
+
```html
|
|
79
|
+
<stockchart-treemap
|
|
80
|
+
[data]="data"
|
|
81
|
+
[options]="options"
|
|
82
|
+
[tileTemplate]="tile"
|
|
83
|
+
[titleTemplate]="title"
|
|
84
|
+
(tileClick)="onTile($event)">
|
|
85
|
+
</stockchart-treemap>
|
|
86
|
+
|
|
87
|
+
<ng-template #title let-item let-node="node">
|
|
88
|
+
<div class="title">{{ item.name }} · {{ node.value | number:'1.0-0' }}</div>
|
|
89
|
+
</ng-template>
|
|
90
|
+
|
|
91
|
+
<ng-template #tile let-item let-isLeaf="isLeaf">
|
|
92
|
+
<div class="tile">
|
|
93
|
+
<strong>{{ item.name }}</strong>
|
|
94
|
+
<span *ngIf="isLeaf">{{ item.change }}%</span>
|
|
95
|
+
</div>
|
|
96
|
+
</ng-template>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Events
|
|
100
|
+
```ts
|
|
101
|
+
import { TreeMapEvent } from 'stockchart-treemap';
|
|
102
|
+
|
|
103
|
+
onTile(ev: TreeMapEvent<MyNode>) {
|
|
104
|
+
// ev.dataItem — your original object
|
|
105
|
+
// ev.path — chain of data items from root to the node
|
|
106
|
+
console.log(ev);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Key options
|
|
111
|
+
- `textField` / `valueField` / `colorField` / `childrenField` — fields in your data (`name`/`value`/`color`/`items` by default).
|
|
112
|
+
- `colorValueField` — field used for colorScale calculations (defaults to `valueField`).
|
|
113
|
+
- `colors` — palette of strings or `[min, max]` pairs; empty array enables gray fallback.
|
|
114
|
+
- `titleSize` (px), `showTopLevelTitles` (bool) — title rendering control.
|
|
115
|
+
- `deriveParentValueFromChildren` — if a container has no value, sum is derived from children.
|
|
116
|
+
- `roundDecimals` — coordinate rounding; `minTileSize` — minimum tile size to recurse.
|
|
117
|
+
|
|
118
|
+
## Exports
|
|
119
|
+
Package exports: `TreeMapComponent`, types `TreeMapOptions`, `TreeMapType`, `TreeMapColorScale`, and utilities like `projectColorByValue`, `colorsByLength`, `roundN` for working with colors and layout math.
|