squarified 0.3.7 → 0.4.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.
- package/README.md +2 -41
- package/dist/dom-event-BLJt9knO.mjs +1646 -0
- package/dist/dom-event-CeVZ44nB.js +1686 -0
- package/dist/index-DcZTC3Az.d.ts +512 -0
- package/dist/index.d.mts +1 -352
- package/dist/index.d.ts +1 -352
- package/dist/index.js +82 -1953
- package/dist/index.mjs +51 -1940
- package/dist/plugin.d.mts +78 -0
- package/dist/plugin.d.ts +78 -0
- package/dist/plugin.js +478 -0
- package/dist/plugin.mjs +472 -0
- package/package.json +24 -7
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-DcZTC3Az.js';
|
|
2
|
+
|
|
3
|
+
declare const presetHighlightPlugin: {
|
|
4
|
+
name: "treemap:preset-highlight";
|
|
5
|
+
onLoad(this: PluginContext): void;
|
|
6
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, name: N, _: DOMEventMetadata<N>, module: LayoutModule | null, { stateManager: state, matrix }: DOMEvent): void;
|
|
7
|
+
onResize(this: PluginContext): void;
|
|
8
|
+
onDispose(this: PluginContext): void;
|
|
9
|
+
meta: {
|
|
10
|
+
highlight: null;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare const presetDragElementPlugin: {
|
|
15
|
+
name: "treemap:preset-drag-element";
|
|
16
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, name: N, event: DOMEventMetadata<N>, module: LayoutModule | null, domEvent: DOMEvent): void;
|
|
17
|
+
meta: {
|
|
18
|
+
dragOptions: {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
lastX: number;
|
|
22
|
+
lastY: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
declare const presetColorPlugin: {
|
|
29
|
+
name: "treemap:preset-color";
|
|
30
|
+
onModuleInit(this: PluginContext, modules: LayoutModule[]): {
|
|
31
|
+
colorMappings: ColorMappings;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
interface ScalePluginOptions {
|
|
36
|
+
/**
|
|
37
|
+
* @default Infinity
|
|
38
|
+
* @description The maximum scale factor for the treemap.
|
|
39
|
+
*/
|
|
40
|
+
max?: number;
|
|
41
|
+
/**
|
|
42
|
+
* @default 0.1
|
|
43
|
+
* @description The minimum scale factor for the treemap.
|
|
44
|
+
*/
|
|
45
|
+
min?: number;
|
|
46
|
+
}
|
|
47
|
+
declare function presetScalePlugin(options?: ScalePluginOptions): {
|
|
48
|
+
name: "treemap:preset-scale";
|
|
49
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, _: N, event: DOMEventMetadata<N>, module: LayoutModule | null, evt: DOMEvent): void;
|
|
50
|
+
meta: {
|
|
51
|
+
scaleOptions: {
|
|
52
|
+
scale: number;
|
|
53
|
+
minScale: number;
|
|
54
|
+
maxScale: number;
|
|
55
|
+
scaleFactor: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
interface ZoomableMetadata {
|
|
62
|
+
isZooming: boolean;
|
|
63
|
+
previousMatrixState?: {
|
|
64
|
+
e: number;
|
|
65
|
+
f: number;
|
|
66
|
+
a: number;
|
|
67
|
+
d: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
declare const presetZoomablePlugin: {
|
|
71
|
+
name: "treemap:preset-zoomable";
|
|
72
|
+
onLoad(this: PluginContext, treemap: BasicTreemapInstance, { stateManager: state, matrix }: DOMEvent): BasicTreemapInstance & {
|
|
73
|
+
zoom: (id: string) => void;
|
|
74
|
+
} & Record<string, never>;
|
|
75
|
+
meta: ZoomableMetadata;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-DcZTC3Az.js';
|
|
2
|
+
|
|
3
|
+
declare const presetHighlightPlugin: {
|
|
4
|
+
name: "treemap:preset-highlight";
|
|
5
|
+
onLoad(this: PluginContext): void;
|
|
6
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, name: N, _: DOMEventMetadata<N>, module: LayoutModule | null, { stateManager: state, matrix }: DOMEvent): void;
|
|
7
|
+
onResize(this: PluginContext): void;
|
|
8
|
+
onDispose(this: PluginContext): void;
|
|
9
|
+
meta: {
|
|
10
|
+
highlight: null;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare const presetDragElementPlugin: {
|
|
15
|
+
name: "treemap:preset-drag-element";
|
|
16
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, name: N, event: DOMEventMetadata<N>, module: LayoutModule | null, domEvent: DOMEvent): void;
|
|
17
|
+
meta: {
|
|
18
|
+
dragOptions: {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
lastX: number;
|
|
22
|
+
lastY: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
declare const presetColorPlugin: {
|
|
29
|
+
name: "treemap:preset-color";
|
|
30
|
+
onModuleInit(this: PluginContext, modules: LayoutModule[]): {
|
|
31
|
+
colorMappings: ColorMappings;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
interface ScalePluginOptions {
|
|
36
|
+
/**
|
|
37
|
+
* @default Infinity
|
|
38
|
+
* @description The maximum scale factor for the treemap.
|
|
39
|
+
*/
|
|
40
|
+
max?: number;
|
|
41
|
+
/**
|
|
42
|
+
* @default 0.1
|
|
43
|
+
* @description The minimum scale factor for the treemap.
|
|
44
|
+
*/
|
|
45
|
+
min?: number;
|
|
46
|
+
}
|
|
47
|
+
declare function presetScalePlugin(options?: ScalePluginOptions): {
|
|
48
|
+
name: "treemap:preset-scale";
|
|
49
|
+
onDOMEventTriggered<N extends DOMEventType>(this: PluginContext, _: N, event: DOMEventMetadata<N>, module: LayoutModule | null, evt: DOMEvent): void;
|
|
50
|
+
meta: {
|
|
51
|
+
scaleOptions: {
|
|
52
|
+
scale: number;
|
|
53
|
+
minScale: number;
|
|
54
|
+
maxScale: number;
|
|
55
|
+
scaleFactor: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
onResize(this: PluginContext, { matrix, stateManager: state }: DOMEvent): void;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
interface ZoomableMetadata {
|
|
62
|
+
isZooming: boolean;
|
|
63
|
+
previousMatrixState?: {
|
|
64
|
+
e: number;
|
|
65
|
+
f: number;
|
|
66
|
+
a: number;
|
|
67
|
+
d: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
declare const presetZoomablePlugin: {
|
|
71
|
+
name: "treemap:preset-zoomable";
|
|
72
|
+
onLoad(this: PluginContext, treemap: BasicTreemapInstance, { stateManager: state, matrix }: DOMEvent): BasicTreemapInstance & {
|
|
73
|
+
zoom: (id: string) => void;
|
|
74
|
+
} & Record<string, never>;
|
|
75
|
+
meta: ZoomableMetadata;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { presetColorPlugin, presetDragElementPlugin, presetHighlightPlugin, presetScalePlugin, presetZoomablePlugin };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var domEvent = require('./dom-event-CeVZ44nB.js');
|
|
4
|
+
|
|
5
|
+
// Currently, etoile is an internal module, so we won't need too much easing functions.
|
|
6
|
+
// And the animation logic is implemented by user code.
|
|
7
|
+
const easing = {
|
|
8
|
+
linear: (k)=>k,
|
|
9
|
+
quadraticIn: (k)=>k * k,
|
|
10
|
+
quadraticOut: (k)=>k * (2 - k),
|
|
11
|
+
quadraticInOut: (k)=>{
|
|
12
|
+
if ((k *= 2) < 1) {
|
|
13
|
+
return 0.5 * k * k;
|
|
14
|
+
}
|
|
15
|
+
return -0.5 * (--k * (k - 2) - 1);
|
|
16
|
+
},
|
|
17
|
+
cubicIn: (k)=>k * k * k,
|
|
18
|
+
cubicOut: (k)=>{
|
|
19
|
+
if ((k *= 2) < 1) {
|
|
20
|
+
return 0.5 * k * k * k;
|
|
21
|
+
}
|
|
22
|
+
return 0.5 * ((k -= 2) * k * k + 2);
|
|
23
|
+
},
|
|
24
|
+
cubicInOut: (k)=>{
|
|
25
|
+
if ((k *= 2) < 1) {
|
|
26
|
+
return 0.5 * k * k * k;
|
|
27
|
+
}
|
|
28
|
+
return 0.5 * ((k -= 2) * k * k + 2);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
class Highlight extends domEvent.Schedule {
|
|
33
|
+
reset() {
|
|
34
|
+
this.destory();
|
|
35
|
+
this.update();
|
|
36
|
+
}
|
|
37
|
+
get canvas() {
|
|
38
|
+
return this.render.canvas;
|
|
39
|
+
}
|
|
40
|
+
setZIndexForHighlight(zIndex = '-1') {
|
|
41
|
+
this.canvas.style.zIndex = zIndex;
|
|
42
|
+
}
|
|
43
|
+
init() {
|
|
44
|
+
this.setZIndexForHighlight();
|
|
45
|
+
this.canvas.style.position = 'absolute';
|
|
46
|
+
this.canvas.style.pointerEvents = 'none';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const ANIMATION_DURATION = 300;
|
|
50
|
+
const HIGH_LIGHT_OPACITY = 0.3;
|
|
51
|
+
const fill = {
|
|
52
|
+
desc: {
|
|
53
|
+
r: 255,
|
|
54
|
+
g: 255,
|
|
55
|
+
b: 255
|
|
56
|
+
},
|
|
57
|
+
mode: 'rgb'
|
|
58
|
+
};
|
|
59
|
+
const presetHighlightPlugin = domEvent.definePlugin({
|
|
60
|
+
name: 'treemap:preset-highlight',
|
|
61
|
+
onLoad () {
|
|
62
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
63
|
+
if (!meta) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!meta.highlight) {
|
|
67
|
+
meta.highlight = new Highlight(this.instance.to);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
onDOMEventTriggered (name, _, module, { stateManager: state, matrix }) {
|
|
71
|
+
if (name === 'mousemove') {
|
|
72
|
+
if (state.canTransition('MOVE')) {
|
|
73
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
74
|
+
if (!module) {
|
|
75
|
+
meta.highlight?.reset();
|
|
76
|
+
meta.highlight?.update();
|
|
77
|
+
meta.highlight?.setZIndexForHighlight();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const [x, y, w, h] = module.layout;
|
|
81
|
+
const effectiveRadius = Math.min(module.config.rectRadius, w / 4, h / 4);
|
|
82
|
+
domEvent.smoothFrame((_, cleanup)=>{
|
|
83
|
+
cleanup();
|
|
84
|
+
meta.highlight?.reset();
|
|
85
|
+
const mask = domEvent.createRoundBlock(x, y, w, h, {
|
|
86
|
+
fill,
|
|
87
|
+
opacity: HIGH_LIGHT_OPACITY,
|
|
88
|
+
radius: effectiveRadius,
|
|
89
|
+
padding: 0
|
|
90
|
+
});
|
|
91
|
+
meta.highlight?.add(mask);
|
|
92
|
+
meta.highlight?.setZIndexForHighlight('1');
|
|
93
|
+
domEvent.stackMatrixTransform(mask, matrix.e, matrix.f, matrix.a);
|
|
94
|
+
meta.highlight?.update();
|
|
95
|
+
}, {
|
|
96
|
+
duration: ANIMATION_DURATION
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onResize () {
|
|
102
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
103
|
+
if (!meta) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
meta.highlight?.render.initOptions({
|
|
107
|
+
...this.instance.render.options
|
|
108
|
+
});
|
|
109
|
+
meta.highlight?.reset();
|
|
110
|
+
meta.highlight?.init();
|
|
111
|
+
},
|
|
112
|
+
onDispose () {
|
|
113
|
+
const meta = this.getPluginMetadata('treemap:preset-highlight');
|
|
114
|
+
if (meta && meta.highlight) {
|
|
115
|
+
meta.highlight.destory();
|
|
116
|
+
meta.highlight = null;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
meta: {
|
|
120
|
+
highlight: null
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const presetDragElementPlugin = domEvent.definePlugin({
|
|
125
|
+
name: 'treemap:preset-drag-element',
|
|
126
|
+
onDOMEventTriggered (name, event, module, domEvent$1) {
|
|
127
|
+
const { stateManager: state, matrix, component } = domEvent$1;
|
|
128
|
+
switch(name){
|
|
129
|
+
case 'mousemove':
|
|
130
|
+
{
|
|
131
|
+
if (state.isInState('DRAGGING')) {
|
|
132
|
+
domEvent$1.silent('click');
|
|
133
|
+
} else {
|
|
134
|
+
domEvent$1.active('click');
|
|
135
|
+
}
|
|
136
|
+
const meta = getDragOptions.call(this);
|
|
137
|
+
if (!meta) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (meta.dragOptions.x === 0 && meta.dragOptions.y === 0) {
|
|
141
|
+
state.transition('IDLE');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
state.transition('DRAGGING');
|
|
145
|
+
if (state.isInState('DRAGGING')) {
|
|
146
|
+
const highlight = getHighlightInstance.call(this);
|
|
147
|
+
domEvent.smoothFrame((_, cleanup)=>{
|
|
148
|
+
cleanup();
|
|
149
|
+
const { offsetX, offsetY } = event.native;
|
|
150
|
+
const drawX = offsetX - meta.dragOptions.x;
|
|
151
|
+
const drawY = offsetY - meta.dragOptions.y;
|
|
152
|
+
const lastX = meta.dragOptions.x;
|
|
153
|
+
const lastY = meta.dragOptions.y;
|
|
154
|
+
if (highlight?.highlight) {
|
|
155
|
+
highlight.highlight.reset();
|
|
156
|
+
highlight.highlight.setZIndexForHighlight();
|
|
157
|
+
}
|
|
158
|
+
matrix.translation(drawX, drawY);
|
|
159
|
+
meta.dragOptions.x = offsetX;
|
|
160
|
+
meta.dragOptions.y = offsetY;
|
|
161
|
+
meta.dragOptions.lastX = lastX;
|
|
162
|
+
meta.dragOptions.lastY = lastY;
|
|
163
|
+
component.cleanup();
|
|
164
|
+
component.draw(false, false);
|
|
165
|
+
domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
|
|
166
|
+
component.update();
|
|
167
|
+
return true;
|
|
168
|
+
}, {
|
|
169
|
+
duration: ANIMATION_DURATION,
|
|
170
|
+
deps: [
|
|
171
|
+
()=>state.isInState('IDLE')
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case 'mouseup':
|
|
178
|
+
{
|
|
179
|
+
if (state.isInState('PRESSED')) {
|
|
180
|
+
const meta = getDragOptions.call(this);
|
|
181
|
+
if (meta && meta.dragOptions) {
|
|
182
|
+
if (meta.dragOptions.x === meta.dragOptions.lastX && meta.dragOptions.y === meta.dragOptions.lastY) {
|
|
183
|
+
state.transition('IDLE');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (state.isInState('DRAGGING') && state.canTransition('IDLE')) {
|
|
189
|
+
const highlight = getHighlightInstance.call(this);
|
|
190
|
+
if (highlight && highlight.highlight) {
|
|
191
|
+
highlight.highlight.reset();
|
|
192
|
+
highlight.highlight.setZIndexForHighlight();
|
|
193
|
+
}
|
|
194
|
+
const meta = getDragOptions.call(this);
|
|
195
|
+
if (meta && meta.dragOptions) {
|
|
196
|
+
meta.dragOptions.x = 0;
|
|
197
|
+
meta.dragOptions.y = 0;
|
|
198
|
+
meta.dragOptions.lastX = 0;
|
|
199
|
+
meta.dragOptions.lastY = 0;
|
|
200
|
+
state.transition('IDLE');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'mousedown':
|
|
206
|
+
{
|
|
207
|
+
if (domEvent.isScrollWheelOrRightButtonOnMouseupAndDown(event.native)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const meta = getDragOptions.call(this);
|
|
211
|
+
if (!meta) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
meta.dragOptions.x = event.native.offsetX;
|
|
215
|
+
meta.dragOptions.y = event.native.offsetY;
|
|
216
|
+
meta.dragOptions.lastX = event.native.offsetX;
|
|
217
|
+
meta.dragOptions.lastY = event.native.offsetY;
|
|
218
|
+
state.transition('PRESSED');
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
meta: {
|
|
224
|
+
dragOptions: {
|
|
225
|
+
x: 0,
|
|
226
|
+
y: 0,
|
|
227
|
+
lastX: 0,
|
|
228
|
+
lastY: 0
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
onResize ({ matrix, stateManager: state }) {
|
|
232
|
+
matrix.create(domEvent.DEFAULT_MATRIX_LOC);
|
|
233
|
+
state.reset();
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
function getHighlightInstance() {
|
|
237
|
+
return this.getPluginMetadata('treemap:preset-highlight');
|
|
238
|
+
}
|
|
239
|
+
function getDragOptions() {
|
|
240
|
+
const meta = this.getPluginMetadata('treemap:preset-drag-element');
|
|
241
|
+
return meta;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const presetColorPlugin = domEvent.definePlugin({
|
|
245
|
+
name: 'treemap:preset-color',
|
|
246
|
+
onModuleInit (modules) {
|
|
247
|
+
const colorMappings = {};
|
|
248
|
+
for(let i = 0; i < modules.length; i++){
|
|
249
|
+
const module = modules[i];
|
|
250
|
+
assignColorMappings(colorMappings, module, Math.abs(domEvent.hashCode(module.node.id)) % domEvent.PI_2, 0);
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
colorMappings
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
function assignColorMappings(colorMappings, module, ancestorHue, depth) {
|
|
258
|
+
const hueOffset = Math.abs(domEvent.hashCode(module.node.id)) % 60 - 30;
|
|
259
|
+
const hue = (ancestorHue + hueOffset) % 360;
|
|
260
|
+
const saturation = Math.max(75 - depth * 5, 40);
|
|
261
|
+
const baseLightness = 55 - depth * 3;
|
|
262
|
+
const color = adjustColorToComfortableForHumanEye(hue, saturation, baseLightness);
|
|
263
|
+
colorMappings[module.node.id] = color;
|
|
264
|
+
if (module.node.isCombinedNode && module.node.originalNodes) {
|
|
265
|
+
for (const combined of module.node.originalNodes){
|
|
266
|
+
colorMappings[combined.id] = color;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (module.children && module.children.length) {
|
|
270
|
+
const childCount = module.children.length;
|
|
271
|
+
for(let i = 0; i < childCount; i++){
|
|
272
|
+
const childHueOffset = 40 * i / childCount;
|
|
273
|
+
const childHue = (hue + childHueOffset) % 360;
|
|
274
|
+
assignColorMappings(colorMappings, module.children[i], childHue, depth + 1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function adjustColorToComfortableForHumanEye(hue, saturation, lightness) {
|
|
279
|
+
hue = (hue % 360 + 360) % 360;
|
|
280
|
+
saturation = Math.min(Math.max(saturation, 40), 85);
|
|
281
|
+
lightness = Math.min(Math.max(lightness, 35), 75);
|
|
282
|
+
if (hue >= 60 && hue <= 180) {
|
|
283
|
+
saturation = Math.max(saturation - 10, 40);
|
|
284
|
+
lightness = Math.min(lightness + 5, 75);
|
|
285
|
+
} else if (hue >= 200 && hue <= 280) {
|
|
286
|
+
lightness = Math.min(lightness + 8, 75);
|
|
287
|
+
} else if (hue >= 0 && hue <= 30) {
|
|
288
|
+
saturation = Math.max(saturation - 5, 40);
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
mode: 'hsl',
|
|
292
|
+
desc: {
|
|
293
|
+
h: hue,
|
|
294
|
+
s: saturation,
|
|
295
|
+
l: lightness
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function presetScalePlugin(options) {
|
|
301
|
+
return domEvent.definePlugin({
|
|
302
|
+
name: 'treemap:preset-scale',
|
|
303
|
+
onDOMEventTriggered (_, event, module, evt) {
|
|
304
|
+
if (domEvent.isWheelEvent(event)) {
|
|
305
|
+
onWheel(this, event, evt);
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
meta: {
|
|
309
|
+
scaleOptions: {
|
|
310
|
+
scale: 1,
|
|
311
|
+
minScale: options?.min || 0.1,
|
|
312
|
+
maxScale: options?.max || Infinity,
|
|
313
|
+
scaleFactor: 0.05
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
onResize ({ matrix, stateManager: state }) {
|
|
317
|
+
const meta = getScaleOptions.call(this);
|
|
318
|
+
if (meta) {
|
|
319
|
+
meta.scaleOptions.scale = 1;
|
|
320
|
+
}
|
|
321
|
+
matrix.create(domEvent.DEFAULT_MATRIX_LOC);
|
|
322
|
+
state.reset();
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
function getScaleOptions() {
|
|
327
|
+
const meta = this.getPluginMetadata('treemap:preset-scale');
|
|
328
|
+
return meta;
|
|
329
|
+
}
|
|
330
|
+
function onWheel(pluginContext, event, { stateManager: state, component, matrix }) {
|
|
331
|
+
event.native.preventDefault();
|
|
332
|
+
const meta = getScaleOptions.call(pluginContext);
|
|
333
|
+
if (!meta) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
|
|
337
|
+
const delta = event.native.deltaY < 0 ? scaleFactor : -scaleFactor;
|
|
338
|
+
const newScale = Math.max(minScale, Math.min(maxScale, scale + delta));
|
|
339
|
+
if (newScale === scale) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
state.transition('SCALING');
|
|
343
|
+
const mouseX = event.native.offsetX;
|
|
344
|
+
const mouseY = event.native.offsetY;
|
|
345
|
+
const scaleDiff = newScale / scale;
|
|
346
|
+
meta.scaleOptions.scale = newScale;
|
|
347
|
+
const highlight = getHighlightInstance.apply(pluginContext);
|
|
348
|
+
domEvent.smoothFrame((_, cleanup)=>{
|
|
349
|
+
cleanup();
|
|
350
|
+
if (highlight && highlight.highlight) {
|
|
351
|
+
highlight.highlight.reset();
|
|
352
|
+
highlight.highlight.setZIndexForHighlight();
|
|
353
|
+
}
|
|
354
|
+
matrix.scale(scaleDiff, scaleDiff);
|
|
355
|
+
matrix.e = mouseX - (mouseX - matrix.e) * scaleDiff;
|
|
356
|
+
matrix.f = mouseY - (mouseY - matrix.f) * scaleDiff;
|
|
357
|
+
component.cleanup();
|
|
358
|
+
const { width, height } = component.render.options;
|
|
359
|
+
component.layoutNodes = component.calculateLayoutNodes(component.data, {
|
|
360
|
+
w: width,
|
|
361
|
+
h: height,
|
|
362
|
+
x: 0,
|
|
363
|
+
y: 0
|
|
364
|
+
}, matrix.a);
|
|
365
|
+
component.draw(true, false);
|
|
366
|
+
domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, newScale);
|
|
367
|
+
component.update();
|
|
368
|
+
if (state.canTransition('IDLE')) {
|
|
369
|
+
state.transition('IDLE');
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
}, {
|
|
373
|
+
duration: ANIMATION_DURATION
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const MAX_SCALE_MULTIPLIER = 2.0;
|
|
378
|
+
const presetZoomablePlugin = domEvent.definePlugin({
|
|
379
|
+
name: 'treemap:preset-zoomable',
|
|
380
|
+
onLoad (treemap, { stateManager: state, matrix }) {
|
|
381
|
+
return domEvent.mixinWithParams(treemap, [
|
|
382
|
+
{
|
|
383
|
+
name: 'zoom',
|
|
384
|
+
fn: ()=>(id)=>{
|
|
385
|
+
const meta = this.getPluginMetadata('treemap:preset-zoomable');
|
|
386
|
+
if (!meta || state.isInState('ZOOMING')) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const targetModule = this.resolveModuleById(id);
|
|
390
|
+
if (!targetModule) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
meta.previousMatrixState = {
|
|
394
|
+
e: matrix.e,
|
|
395
|
+
f: matrix.f,
|
|
396
|
+
a: matrix.a,
|
|
397
|
+
d: matrix.d
|
|
398
|
+
};
|
|
399
|
+
const component = this.instance;
|
|
400
|
+
state.transition('ZOOMING');
|
|
401
|
+
const [nodeX, nodeY, nodeW, nodeH] = targetModule.layout;
|
|
402
|
+
const { width, height } = component.render.options;
|
|
403
|
+
const currentScale = matrix.a;
|
|
404
|
+
const scaleX = width / nodeW;
|
|
405
|
+
const scaleY = height / nodeH;
|
|
406
|
+
const fullScale = Math.min(scaleX, scaleY) * 0.9;
|
|
407
|
+
const targetScale = Math.min(fullScale, currentScale * MAX_SCALE_MULTIPLIER);
|
|
408
|
+
const scale = targetScale;
|
|
409
|
+
const nodeCenterX = nodeX + nodeW / 2;
|
|
410
|
+
const nodeCenterY = nodeY + nodeH / 2;
|
|
411
|
+
const viewCenterX = width / 2;
|
|
412
|
+
const viewCenterY = height / 2;
|
|
413
|
+
const targetE = viewCenterX - nodeCenterX * scale;
|
|
414
|
+
const targetF = viewCenterY - nodeCenterY * scale;
|
|
415
|
+
const scaleMeta = getScaleOptions.call(this);
|
|
416
|
+
if (scaleMeta) {
|
|
417
|
+
scaleMeta.scaleOptions.scale = scale;
|
|
418
|
+
}
|
|
419
|
+
const highlight = getHighlightInstance.call(this);
|
|
420
|
+
const dragMeta = getDragOptions.call(this);
|
|
421
|
+
if (dragMeta) {
|
|
422
|
+
dragMeta.dragOptions.x = 0;
|
|
423
|
+
dragMeta.dragOptions.y = 0;
|
|
424
|
+
dragMeta.dragOptions.lastX = 0;
|
|
425
|
+
dragMeta.dragOptions.lastY = 0;
|
|
426
|
+
}
|
|
427
|
+
const startMatrix = {
|
|
428
|
+
e: matrix.e,
|
|
429
|
+
f: matrix.f,
|
|
430
|
+
a: matrix.a,
|
|
431
|
+
d: matrix.d
|
|
432
|
+
};
|
|
433
|
+
domEvent.smoothFrame((progress)=>{
|
|
434
|
+
const easedProgress = easing.cubicInOut(progress);
|
|
435
|
+
const currentE = startMatrix.e + (targetE - startMatrix.e) * easedProgress;
|
|
436
|
+
const currentF = startMatrix.f + (targetF - startMatrix.f) * easedProgress;
|
|
437
|
+
const currentA = startMatrix.a + (scale - startMatrix.a) * easedProgress;
|
|
438
|
+
const currentD = startMatrix.d + (scale - startMatrix.d) * easedProgress;
|
|
439
|
+
matrix.create(domEvent.DEFAULT_MATRIX_LOC);
|
|
440
|
+
matrix.e = currentE;
|
|
441
|
+
matrix.f = currentF;
|
|
442
|
+
matrix.a = currentA;
|
|
443
|
+
matrix.d = currentD;
|
|
444
|
+
if (highlight?.highlight) {
|
|
445
|
+
highlight.highlight.reset();
|
|
446
|
+
highlight.highlight.setZIndexForHighlight();
|
|
447
|
+
}
|
|
448
|
+
component.cleanup();
|
|
449
|
+
const { width, height } = component.render.options;
|
|
450
|
+
component.layoutNodes = component.calculateLayoutNodes(component.data, {
|
|
451
|
+
w: width,
|
|
452
|
+
h: height,
|
|
453
|
+
x: 0,
|
|
454
|
+
y: 0
|
|
455
|
+
}, matrix.a);
|
|
456
|
+
component.draw(true, false);
|
|
457
|
+
domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
|
|
458
|
+
component.update();
|
|
459
|
+
}, {
|
|
460
|
+
duration: ANIMATION_DURATION,
|
|
461
|
+
onStop: ()=>{
|
|
462
|
+
state.reset();
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
]);
|
|
468
|
+
},
|
|
469
|
+
meta: {
|
|
470
|
+
isZooming: false
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
exports.presetColorPlugin = presetColorPlugin;
|
|
475
|
+
exports.presetDragElementPlugin = presetDragElementPlugin;
|
|
476
|
+
exports.presetHighlightPlugin = presetHighlightPlugin;
|
|
477
|
+
exports.presetScalePlugin = presetScalePlugin;
|
|
478
|
+
exports.presetZoomablePlugin = presetZoomablePlugin;
|