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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -90
  3. 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
- Готовый к публикации на npm пакет с самостоятельным TreeMap-компонентом для Angular.
4
- Компонент работает как standalone, поддерживает подсветку по `TreeMapColorScale`,
5
- источники данных в виде массива, Observable или лоадера, а также кастомные шаблоны плиток и заголовков.
6
-
7
- ## Сборка и публикация
8
- 1. Соберите библиотеку:
9
- ```bash
10
- npm run ng -- build stockchart-treemap
11
- ```
12
- 2. Перейдите в папку сборки и опубликуйте пакет (убедитесь, что вошли в npm):
13
- ```bash
14
- cd dist/stockchart-treemap
15
- npm publish --access public
16
- ```
17
-
18
- ## Сборка примерных компонентов для отладки
19
- Для локального тестирования и пошаговой отладки демо-компонентов соберите отдельный пакет `stockchart-treemap-examples`:
20
- ```bash
21
- npm run build:stockchart-treemap-examples
22
- ```
23
- Сборка использует tsconfig для примеров и кладёт артефакты в `dist/stockchart-treemap-examples`, чтобы их можно было подключить в песочнице или во внешнем приложении без вмешательства в основной пакет.
24
-
25
- Для живого просмотра примеров запустите дев-сервер с подходящей конфигурацией:
26
- ```bash
27
- # карта рынка на стандартном порту 4200
28
- ng serve stockchart-treemap-examples
29
-
30
- # вариант с собственными цветами на порту 4200
31
- ng serve stockchart-treemap-examples --configuration self-colored
32
- ```
33
-
34
- ## Подключение
35
- ```ts
36
- import { bootstrapApplication } from '@angular/platform-browser';
37
- import { AppComponent } from './app/app.component';
38
- import { TreeMapComponent } from 'stockchart-treemap';
39
-
40
- bootstrapApplication(AppComponent, {
41
- providers: [
42
- // TreeMapComponent подключается как standalone в импортах компонентов
43
- ]
44
- });
45
- ```
46
-
47
- В компоненте-доме добавьте `TreeMapComponent` или готовые демо-обёртки в секцию `imports` и используйте селектор
48
- `<stockchart-treemap>` прямо в шаблоне.
49
-
50
- ## Пример «app-stockchart-treemap» с сгенерированными данными
51
- ```ts
52
- import { AppStockchartTreemapExampleComponent, createMockMarketMap } from 'stockchart-treemap';
53
-
54
- @Component({
55
- standalone: true,
56
- imports: [AppStockchartTreemapExampleComponent]
57
- })
58
- export class DemoHost {}
59
- ```
60
-
61
- Компонент сам генерирует дерево с секторами и тикерами, выставляет `colorValueField: 'change'` и
62
- использует `TreeMapColorScale` для плавной подсветки приростов и падений.
63
-
64
- ## Базовое использование с авторасчётом цветов
65
- ```html
66
- <stockchart-treemap
67
- [data]="data"
68
- [options]="{ textField: 'name', valueField: 'value', colorValueField: 'change', colorScale: performanceColorScale }">
69
- </stockchart-treemap>
70
- ```
71
- ```ts
72
- import { performanceColorScale, createPerformanceTreemap } from 'stockchart-treemap';
73
-
74
- @Component({
75
- standalone: true,
76
- imports: [TreeMapComponent]
77
- })
78
- export class SimpleDemo {
79
- data = createPerformanceTreemap();
80
- options = {
81
- textField: 'name',
82
- valueField: 'value',
83
- colorValueField: 'change',
84
- colorScale: performanceColorScale,
85
- colors: []
86
- };
87
- }
88
- ```
89
-
90
- Плитки не содержат поля `color`, поэтому библиотека самостоятельно рассчитывает оттенки на основе значений из `change`.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stockchart-treemap",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Standalone Angular treemap component with StockChart-themed demos and mock data generators.",
5
5
  "keywords": [
6
6
  "angular",