squarified 0.3.2 → 0.3.5
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 +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +24 -20
- package/dist/index.mjs +24 -20
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -219,7 +219,6 @@ declare const defaultFontOptions: {
|
|
|
219
219
|
};
|
|
220
220
|
declare function presetDecorator(app: TreemapLayout): void;
|
|
221
221
|
|
|
222
|
-
type AnyObject = Record<keyof Any, Any>;
|
|
223
222
|
declare function sortChildrenByKey<T extends AnyObject, K extends keyof T = 'weight'>(data: T[], ...keys: K[]): T[];
|
|
224
223
|
declare function c2m<T extends AnyObject & {
|
|
225
224
|
groups: Any[];
|
package/dist/index.d.ts
CHANGED
|
@@ -219,7 +219,6 @@ declare const defaultFontOptions: {
|
|
|
219
219
|
};
|
|
220
220
|
declare function presetDecorator(app: TreemapLayout): void;
|
|
221
221
|
|
|
222
|
-
type AnyObject = Record<keyof Any, Any>;
|
|
223
222
|
declare function sortChildrenByKey<T extends AnyObject, K extends keyof T = 'weight'>(data: T[], ...keys: K[]): T[];
|
|
224
223
|
declare function c2m<T extends AnyObject & {
|
|
225
224
|
groups: Any[];
|
package/dist/index.js
CHANGED
|
@@ -758,14 +758,14 @@ class RenderCache extends Canvas {
|
|
|
758
758
|
if (width * a >= size || height * d >= size) {
|
|
759
759
|
return;
|
|
760
760
|
}
|
|
761
|
+
if (width * a * height * d >= size * size) {
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
761
764
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
762
765
|
this.setOptions({ width: width * a, height: height * d, devicePixelRatio });
|
|
763
766
|
resetLayout(treemap, width * a, height * d);
|
|
764
767
|
drawGraphIntoCanvas(treemap, { c: this.canvas, ctx: this.ctx, dpr: devicePixelRatio });
|
|
765
768
|
this.$memory = true;
|
|
766
|
-
if (this.ctx.isContextLost()) {
|
|
767
|
-
this.$memory = false;
|
|
768
|
-
}
|
|
769
769
|
}
|
|
770
770
|
destroy() {
|
|
771
771
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
@@ -874,7 +874,7 @@ function createEffectStop(c) {
|
|
|
874
874
|
}
|
|
875
875
|
};
|
|
876
876
|
}
|
|
877
|
-
function
|
|
877
|
+
function createSmoothFrame() {
|
|
878
878
|
const c = {
|
|
879
879
|
animationFrameID: null
|
|
880
880
|
};
|
|
@@ -1024,8 +1024,8 @@ const INTERNAL_EVENT_MAPPINGS = {
|
|
|
1024
1024
|
};
|
|
1025
1025
|
const ANIMATION_DURATION = 300;
|
|
1026
1026
|
const fill = { desc: { r: 255, g: 255, b: 255 }, mode: "rgb" };
|
|
1027
|
-
function
|
|
1028
|
-
const
|
|
1027
|
+
function smoothFrame(callback, opts) {
|
|
1028
|
+
const frame = createSmoothFrame();
|
|
1029
1029
|
const startTime = Date.now();
|
|
1030
1030
|
const condtion = (process) => {
|
|
1031
1031
|
if (Array.isArray(opts.deps)) {
|
|
@@ -1033,17 +1033,17 @@ function runEffect(callback, opts) {
|
|
|
1033
1033
|
}
|
|
1034
1034
|
return process >= 1;
|
|
1035
1035
|
};
|
|
1036
|
-
|
|
1036
|
+
frame.run(() => {
|
|
1037
1037
|
const elapsed = Date.now() - startTime;
|
|
1038
1038
|
const progress = Math.min(elapsed / opts.duration, 1);
|
|
1039
1039
|
if (condtion(progress)) {
|
|
1040
|
-
|
|
1040
|
+
frame.stop();
|
|
1041
1041
|
if (opts.onStop) {
|
|
1042
1042
|
opts.onStop();
|
|
1043
1043
|
}
|
|
1044
1044
|
return true;
|
|
1045
1045
|
}
|
|
1046
|
-
return callback(progress,
|
|
1046
|
+
return callback(progress, frame.stop);
|
|
1047
1047
|
});
|
|
1048
1048
|
}
|
|
1049
1049
|
const HIGH_LIGHT_OPACITY = 0.3;
|
|
@@ -1052,7 +1052,7 @@ function drawHighlight(treemap, evt) {
|
|
|
1052
1052
|
const { currentNode } = evt.state;
|
|
1053
1053
|
if (currentNode) {
|
|
1054
1054
|
const [x, y, w, h] = currentNode.layout;
|
|
1055
|
-
|
|
1055
|
+
smoothFrame((_, cleanup) => {
|
|
1056
1056
|
cleanup();
|
|
1057
1057
|
highlight.reset();
|
|
1058
1058
|
const mask = createRoundBlock(x, y, w, h, { fill, opacity: HIGH_LIGHT_OPACITY, radius: 4, padding: 2 });
|
|
@@ -1120,7 +1120,7 @@ class TreemapEvent extends DOMEvent {
|
|
|
1120
1120
|
drawHighlight(ctx.treemap, this);
|
|
1121
1121
|
} else {
|
|
1122
1122
|
const { treemap } = ctx;
|
|
1123
|
-
|
|
1123
|
+
smoothFrame((_, cleanup) => {
|
|
1124
1124
|
cleanup();
|
|
1125
1125
|
const { offsetX: x, offsetY: y } = metadata.native;
|
|
1126
1126
|
const { dragX: lastX, dragY: lastY } = this.state;
|
|
@@ -1175,6 +1175,7 @@ class TreemapEvent extends DOMEvent {
|
|
|
1175
1175
|
}
|
|
1176
1176
|
onwheel(ctx, metadata) {
|
|
1177
1177
|
ctx.treemap.renderCache.destroy();
|
|
1178
|
+
ctx.treemap.event.silent(INTERNAL_EVENT_MAPPINGS.ON_ZOOM);
|
|
1178
1179
|
const { native } = metadata;
|
|
1179
1180
|
const { treemap } = ctx;
|
|
1180
1181
|
const wheelDelta = native.wheelDelta;
|
|
@@ -1190,13 +1191,11 @@ class TreemapEvent extends DOMEvent {
|
|
|
1190
1191
|
const targetScaleRatio = this.matrix.a * delta;
|
|
1191
1192
|
const translateX = offsetX - (offsetX - this.matrix.e) * delta;
|
|
1192
1193
|
const translateY = offsetY - (offsetY - this.matrix.f) * delta;
|
|
1193
|
-
|
|
1194
|
-
this.silent("mousedown");
|
|
1194
|
+
smoothFrame((progress, cleanup) => {
|
|
1195
1195
|
this.exposedEvent.silent("mousemove");
|
|
1196
1196
|
this.silent("mousemove");
|
|
1197
1197
|
this.silent("click");
|
|
1198
1198
|
this.exposedEvent.silent("click");
|
|
1199
|
-
cleanup();
|
|
1200
1199
|
treemap.highlight.reset();
|
|
1201
1200
|
treemap.highlight.setZIndexForHighlight();
|
|
1202
1201
|
treemap.fontCache.flush(treemap, this.matrix);
|
|
@@ -1213,16 +1212,17 @@ class TreemapEvent extends DOMEvent {
|
|
|
1213
1212
|
);
|
|
1214
1213
|
stackMatrixTransformWithGraphAndLayer(treemap.elements, this.matrix.e, this.matrix.f, 1);
|
|
1215
1214
|
treemap.update();
|
|
1215
|
+
cleanup();
|
|
1216
1216
|
}, {
|
|
1217
1217
|
duration: ANIMATION_DURATION,
|
|
1218
1218
|
onStop: () => {
|
|
1219
1219
|
this.state.forceDestroy = false;
|
|
1220
1220
|
this.state.isWheeling = false;
|
|
1221
|
-
this.active("mousedown");
|
|
1222
1221
|
this.active("mousemove");
|
|
1223
1222
|
this.exposedEvent.active("mousemove");
|
|
1224
1223
|
this.active("click");
|
|
1225
1224
|
this.exposedEvent.active("click");
|
|
1225
|
+
treemap.event.active(INTERNAL_EVENT_MAPPINGS.ON_ZOOM);
|
|
1226
1226
|
}
|
|
1227
1227
|
});
|
|
1228
1228
|
}
|
|
@@ -1254,8 +1254,10 @@ function createOnZoom(treemap, evt) {
|
|
|
1254
1254
|
const targetScale = factor * evt.matrix.a;
|
|
1255
1255
|
const translateX = boundingClientRect.width / 2 - (mx + mw / 2) * factor;
|
|
1256
1256
|
const translateY = boundingClientRect.height / 2 - (my + mh / 2) * factor;
|
|
1257
|
-
|
|
1257
|
+
smoothFrame((progress, cleanup) => {
|
|
1258
1258
|
cleanup();
|
|
1259
|
+
evt.silent("mousemove");
|
|
1260
|
+
evt.exposedEvent.silent("mousemove");
|
|
1259
1261
|
treemap.fontCache.flush(treemap, evt.matrix);
|
|
1260
1262
|
const easedProgress = easing.cubicInOut(progress);
|
|
1261
1263
|
const scale = (targetScale - evt.matrix.a) * easedProgress;
|
|
@@ -1273,6 +1275,8 @@ function createOnZoom(treemap, evt) {
|
|
|
1273
1275
|
duration: ANIMATION_DURATION,
|
|
1274
1276
|
onStop: () => {
|
|
1275
1277
|
evt.state.isZooming = false;
|
|
1278
|
+
evt.active("mousemove");
|
|
1279
|
+
evt.exposedEvent.active("mousemove");
|
|
1276
1280
|
}
|
|
1277
1281
|
});
|
|
1278
1282
|
}
|
|
@@ -1637,8 +1641,8 @@ function evaluateColorMappings(data) {
|
|
|
1637
1641
|
const hash = Math.abs(hashCode(id));
|
|
1638
1642
|
return hash % 360;
|
|
1639
1643
|
};
|
|
1640
|
-
const lightScale = (depth) =>
|
|
1641
|
-
const baseSaturation =
|
|
1644
|
+
const lightScale = (depth) => 50 - depth * 5;
|
|
1645
|
+
const baseSaturation = 80;
|
|
1642
1646
|
const siblingHueShift = 30;
|
|
1643
1647
|
const rc = 0.2126;
|
|
1644
1648
|
const gc = 0.7152;
|
|
@@ -1666,8 +1670,8 @@ function evaluateColorMappings(data) {
|
|
|
1666
1670
|
const { r, g, b } = hslToRgb(hslColor.h, hslColor.s / 100, hslColor.l);
|
|
1667
1671
|
const luminance = calculateLuminance(r, g, b);
|
|
1668
1672
|
if (luminance < 0.6) {
|
|
1669
|
-
hslColor.l += 0.
|
|
1670
|
-
} else if (luminance > 0.
|
|
1673
|
+
hslColor.l += 0.2;
|
|
1674
|
+
} else if (luminance > 0.8) {
|
|
1671
1675
|
hslColor.l -= 0.1;
|
|
1672
1676
|
}
|
|
1673
1677
|
hslColor.l *= 100;
|
package/dist/index.mjs
CHANGED
|
@@ -756,14 +756,14 @@ class RenderCache extends Canvas {
|
|
|
756
756
|
if (width * a >= size || height * d >= size) {
|
|
757
757
|
return;
|
|
758
758
|
}
|
|
759
|
+
if (width * a * height * d >= size * size) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
759
762
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
760
763
|
this.setOptions({ width: width * a, height: height * d, devicePixelRatio });
|
|
761
764
|
resetLayout(treemap, width * a, height * d);
|
|
762
765
|
drawGraphIntoCanvas(treemap, { c: this.canvas, ctx: this.ctx, dpr: devicePixelRatio });
|
|
763
766
|
this.$memory = true;
|
|
764
|
-
if (this.ctx.isContextLost()) {
|
|
765
|
-
this.$memory = false;
|
|
766
|
-
}
|
|
767
767
|
}
|
|
768
768
|
destroy() {
|
|
769
769
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
@@ -872,7 +872,7 @@ function createEffectStop(c) {
|
|
|
872
872
|
}
|
|
873
873
|
};
|
|
874
874
|
}
|
|
875
|
-
function
|
|
875
|
+
function createSmoothFrame() {
|
|
876
876
|
const c = {
|
|
877
877
|
animationFrameID: null
|
|
878
878
|
};
|
|
@@ -1022,8 +1022,8 @@ const INTERNAL_EVENT_MAPPINGS = {
|
|
|
1022
1022
|
};
|
|
1023
1023
|
const ANIMATION_DURATION = 300;
|
|
1024
1024
|
const fill = { desc: { r: 255, g: 255, b: 255 }, mode: "rgb" };
|
|
1025
|
-
function
|
|
1026
|
-
const
|
|
1025
|
+
function smoothFrame(callback, opts) {
|
|
1026
|
+
const frame = createSmoothFrame();
|
|
1027
1027
|
const startTime = Date.now();
|
|
1028
1028
|
const condtion = (process) => {
|
|
1029
1029
|
if (Array.isArray(opts.deps)) {
|
|
@@ -1031,17 +1031,17 @@ function runEffect(callback, opts) {
|
|
|
1031
1031
|
}
|
|
1032
1032
|
return process >= 1;
|
|
1033
1033
|
};
|
|
1034
|
-
|
|
1034
|
+
frame.run(() => {
|
|
1035
1035
|
const elapsed = Date.now() - startTime;
|
|
1036
1036
|
const progress = Math.min(elapsed / opts.duration, 1);
|
|
1037
1037
|
if (condtion(progress)) {
|
|
1038
|
-
|
|
1038
|
+
frame.stop();
|
|
1039
1039
|
if (opts.onStop) {
|
|
1040
1040
|
opts.onStop();
|
|
1041
1041
|
}
|
|
1042
1042
|
return true;
|
|
1043
1043
|
}
|
|
1044
|
-
return callback(progress,
|
|
1044
|
+
return callback(progress, frame.stop);
|
|
1045
1045
|
});
|
|
1046
1046
|
}
|
|
1047
1047
|
const HIGH_LIGHT_OPACITY = 0.3;
|
|
@@ -1050,7 +1050,7 @@ function drawHighlight(treemap, evt) {
|
|
|
1050
1050
|
const { currentNode } = evt.state;
|
|
1051
1051
|
if (currentNode) {
|
|
1052
1052
|
const [x, y, w, h] = currentNode.layout;
|
|
1053
|
-
|
|
1053
|
+
smoothFrame((_, cleanup) => {
|
|
1054
1054
|
cleanup();
|
|
1055
1055
|
highlight.reset();
|
|
1056
1056
|
const mask = createRoundBlock(x, y, w, h, { fill, opacity: HIGH_LIGHT_OPACITY, radius: 4, padding: 2 });
|
|
@@ -1118,7 +1118,7 @@ class TreemapEvent extends DOMEvent {
|
|
|
1118
1118
|
drawHighlight(ctx.treemap, this);
|
|
1119
1119
|
} else {
|
|
1120
1120
|
const { treemap } = ctx;
|
|
1121
|
-
|
|
1121
|
+
smoothFrame((_, cleanup) => {
|
|
1122
1122
|
cleanup();
|
|
1123
1123
|
const { offsetX: x, offsetY: y } = metadata.native;
|
|
1124
1124
|
const { dragX: lastX, dragY: lastY } = this.state;
|
|
@@ -1173,6 +1173,7 @@ class TreemapEvent extends DOMEvent {
|
|
|
1173
1173
|
}
|
|
1174
1174
|
onwheel(ctx, metadata) {
|
|
1175
1175
|
ctx.treemap.renderCache.destroy();
|
|
1176
|
+
ctx.treemap.event.silent(INTERNAL_EVENT_MAPPINGS.ON_ZOOM);
|
|
1176
1177
|
const { native } = metadata;
|
|
1177
1178
|
const { treemap } = ctx;
|
|
1178
1179
|
const wheelDelta = native.wheelDelta;
|
|
@@ -1188,13 +1189,11 @@ class TreemapEvent extends DOMEvent {
|
|
|
1188
1189
|
const targetScaleRatio = this.matrix.a * delta;
|
|
1189
1190
|
const translateX = offsetX - (offsetX - this.matrix.e) * delta;
|
|
1190
1191
|
const translateY = offsetY - (offsetY - this.matrix.f) * delta;
|
|
1191
|
-
|
|
1192
|
-
this.silent("mousedown");
|
|
1192
|
+
smoothFrame((progress, cleanup) => {
|
|
1193
1193
|
this.exposedEvent.silent("mousemove");
|
|
1194
1194
|
this.silent("mousemove");
|
|
1195
1195
|
this.silent("click");
|
|
1196
1196
|
this.exposedEvent.silent("click");
|
|
1197
|
-
cleanup();
|
|
1198
1197
|
treemap.highlight.reset();
|
|
1199
1198
|
treemap.highlight.setZIndexForHighlight();
|
|
1200
1199
|
treemap.fontCache.flush(treemap, this.matrix);
|
|
@@ -1211,16 +1210,17 @@ class TreemapEvent extends DOMEvent {
|
|
|
1211
1210
|
);
|
|
1212
1211
|
stackMatrixTransformWithGraphAndLayer(treemap.elements, this.matrix.e, this.matrix.f, 1);
|
|
1213
1212
|
treemap.update();
|
|
1213
|
+
cleanup();
|
|
1214
1214
|
}, {
|
|
1215
1215
|
duration: ANIMATION_DURATION,
|
|
1216
1216
|
onStop: () => {
|
|
1217
1217
|
this.state.forceDestroy = false;
|
|
1218
1218
|
this.state.isWheeling = false;
|
|
1219
|
-
this.active("mousedown");
|
|
1220
1219
|
this.active("mousemove");
|
|
1221
1220
|
this.exposedEvent.active("mousemove");
|
|
1222
1221
|
this.active("click");
|
|
1223
1222
|
this.exposedEvent.active("click");
|
|
1223
|
+
treemap.event.active(INTERNAL_EVENT_MAPPINGS.ON_ZOOM);
|
|
1224
1224
|
}
|
|
1225
1225
|
});
|
|
1226
1226
|
}
|
|
@@ -1252,8 +1252,10 @@ function createOnZoom(treemap, evt) {
|
|
|
1252
1252
|
const targetScale = factor * evt.matrix.a;
|
|
1253
1253
|
const translateX = boundingClientRect.width / 2 - (mx + mw / 2) * factor;
|
|
1254
1254
|
const translateY = boundingClientRect.height / 2 - (my + mh / 2) * factor;
|
|
1255
|
-
|
|
1255
|
+
smoothFrame((progress, cleanup) => {
|
|
1256
1256
|
cleanup();
|
|
1257
|
+
evt.silent("mousemove");
|
|
1258
|
+
evt.exposedEvent.silent("mousemove");
|
|
1257
1259
|
treemap.fontCache.flush(treemap, evt.matrix);
|
|
1258
1260
|
const easedProgress = easing.cubicInOut(progress);
|
|
1259
1261
|
const scale = (targetScale - evt.matrix.a) * easedProgress;
|
|
@@ -1271,6 +1273,8 @@ function createOnZoom(treemap, evt) {
|
|
|
1271
1273
|
duration: ANIMATION_DURATION,
|
|
1272
1274
|
onStop: () => {
|
|
1273
1275
|
evt.state.isZooming = false;
|
|
1276
|
+
evt.active("mousemove");
|
|
1277
|
+
evt.exposedEvent.active("mousemove");
|
|
1274
1278
|
}
|
|
1275
1279
|
});
|
|
1276
1280
|
}
|
|
@@ -1635,8 +1639,8 @@ function evaluateColorMappings(data) {
|
|
|
1635
1639
|
const hash = Math.abs(hashCode(id));
|
|
1636
1640
|
return hash % 360;
|
|
1637
1641
|
};
|
|
1638
|
-
const lightScale = (depth) =>
|
|
1639
|
-
const baseSaturation =
|
|
1642
|
+
const lightScale = (depth) => 50 - depth * 5;
|
|
1643
|
+
const baseSaturation = 80;
|
|
1640
1644
|
const siblingHueShift = 30;
|
|
1641
1645
|
const rc = 0.2126;
|
|
1642
1646
|
const gc = 0.7152;
|
|
@@ -1664,8 +1668,8 @@ function evaluateColorMappings(data) {
|
|
|
1664
1668
|
const { r, g, b } = hslToRgb(hslColor.h, hslColor.s / 100, hslColor.l);
|
|
1665
1669
|
const luminance = calculateLuminance(r, g, b);
|
|
1666
1670
|
if (luminance < 0.6) {
|
|
1667
|
-
hslColor.l += 0.
|
|
1668
|
-
} else if (luminance > 0.
|
|
1671
|
+
hslColor.l += 0.2;
|
|
1672
|
+
} else if (luminance > 0.8) {
|
|
1669
1673
|
hslColor.l -= 0.1;
|
|
1670
1674
|
}
|
|
1671
1675
|
hslColor.l *= 100;
|