@ggterm/core 0.2.12 → 0.2.16
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/dist/cli-plot.js +999 -3
- package/dist/cli.js +958 -0
- package/dist/geoms/calendar.d.ts +48 -0
- package/dist/geoms/calendar.d.ts.map +1 -0
- package/dist/geoms/corrmat.d.ts +59 -0
- package/dist/geoms/corrmat.d.ts.map +1 -0
- package/dist/geoms/density.d.ts +60 -0
- package/dist/geoms/density.d.ts.map +1 -0
- package/dist/geoms/flame.d.ts +50 -0
- package/dist/geoms/flame.d.ts.map +1 -0
- package/dist/geoms/index.d.ts +6 -0
- package/dist/geoms/index.d.ts.map +1 -1
- package/dist/geoms/sankey.d.ts +57 -0
- package/dist/geoms/sankey.d.ts.map +1 -0
- package/dist/geoms/treemap.d.ts +70 -0
- package/dist/geoms/treemap.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +972 -0
- package/dist/pipeline/render-geoms.d.ts +29 -0
- package/dist/pipeline/render-geoms.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1564,6 +1564,82 @@ function renderGeomFreqpoly(data, _geom, aes, scales, canvas) {
|
|
|
1564
1564
|
}
|
|
1565
1565
|
}
|
|
1566
1566
|
}
|
|
1567
|
+
function renderGeomDensity(data, geom, aes, scales, canvas) {
|
|
1568
|
+
if (data.length < 2)
|
|
1569
|
+
return;
|
|
1570
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
1571
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
1572
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
1573
|
+
const plotBottom = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
|
|
1574
|
+
const groups = new Map;
|
|
1575
|
+
const groupField = aes.group || aes.color || aes.fill;
|
|
1576
|
+
if (groupField) {
|
|
1577
|
+
for (const row of data) {
|
|
1578
|
+
const key = String(row[groupField] ?? "default");
|
|
1579
|
+
if (!groups.has(key))
|
|
1580
|
+
groups.set(key, []);
|
|
1581
|
+
groups.get(key).push(row);
|
|
1582
|
+
}
|
|
1583
|
+
} else {
|
|
1584
|
+
groups.set("default", data);
|
|
1585
|
+
}
|
|
1586
|
+
let baseline = Math.round(scales.y.map(0));
|
|
1587
|
+
baseline = Math.max(plotTop, Math.min(plotBottom, baseline));
|
|
1588
|
+
const alpha = geom.params.alpha ?? 0.3;
|
|
1589
|
+
const fillChar = "░";
|
|
1590
|
+
for (const [groupKey, groupData] of groups) {
|
|
1591
|
+
if (groupData.length < 2)
|
|
1592
|
+
continue;
|
|
1593
|
+
const sorted = [...groupData].sort((a, b) => {
|
|
1594
|
+
const ax = Number(a.x) || 0;
|
|
1595
|
+
const bx = Number(b.x) || 0;
|
|
1596
|
+
return ax - bx;
|
|
1597
|
+
});
|
|
1598
|
+
let baseColor = scales.color?.map(groupKey) ?? DEFAULT_POINT_COLOR;
|
|
1599
|
+
const fillColor = {
|
|
1600
|
+
r: Math.round(baseColor.r * alpha),
|
|
1601
|
+
g: Math.round(baseColor.g * alpha),
|
|
1602
|
+
b: Math.round(baseColor.b * alpha),
|
|
1603
|
+
a: baseColor.a
|
|
1604
|
+
};
|
|
1605
|
+
for (let i = 0;i < sorted.length - 1; i++) {
|
|
1606
|
+
const row1 = sorted[i];
|
|
1607
|
+
const row2 = sorted[i + 1];
|
|
1608
|
+
const density1 = Number(row1.y ?? row1.density) || 0;
|
|
1609
|
+
const density2 = Number(row2.y ?? row2.density) || 0;
|
|
1610
|
+
const x1 = Math.round(scales.x.map(row1.x));
|
|
1611
|
+
const y1 = Math.round(scales.y.map(density1));
|
|
1612
|
+
const x2 = Math.round(scales.x.map(row2.x));
|
|
1613
|
+
const y2 = Math.round(scales.y.map(density2));
|
|
1614
|
+
for (let x = x1;x <= x2; x++) {
|
|
1615
|
+
if (x < plotLeft || x > plotRight)
|
|
1616
|
+
continue;
|
|
1617
|
+
const t = x2 !== x1 ? (x - x1) / (x2 - x1) : 0;
|
|
1618
|
+
const yInterp = Math.round(y1 + (y2 - y1) * t);
|
|
1619
|
+
const top = Math.min(yInterp, baseline);
|
|
1620
|
+
const bottom = Math.max(yInterp, baseline);
|
|
1621
|
+
for (let y = top;y <= bottom; y++) {
|
|
1622
|
+
if (y >= plotTop && y <= plotBottom) {
|
|
1623
|
+
canvas.drawChar(x, y, fillChar, fillColor);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
for (let i = 0;i < sorted.length - 1; i++) {
|
|
1629
|
+
const row1 = sorted[i];
|
|
1630
|
+
const row2 = sorted[i + 1];
|
|
1631
|
+
const density1 = Number(row1.y ?? row1.density) || 0;
|
|
1632
|
+
const density2 = Number(row2.y ?? row2.density) || 0;
|
|
1633
|
+
const x1 = Math.round(scales.x.map(row1.x));
|
|
1634
|
+
const y1 = Math.round(scales.y.map(density1));
|
|
1635
|
+
const x2 = Math.round(scales.x.map(row2.x));
|
|
1636
|
+
const y2 = Math.round(scales.y.map(density2));
|
|
1637
|
+
if (x1 >= plotLeft && x1 <= plotRight && x2 >= plotLeft && x2 <= plotRight && y1 >= plotTop && y1 <= plotBottom && y2 >= plotTop && y2 <= plotBottom) {
|
|
1638
|
+
drawLine(canvas, x1, y1, x2, y2, baseColor);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1567
1643
|
function renderGeomBoxplot(data, geom, _aes, scales, canvas) {
|
|
1568
1644
|
const widthFactor = geom.params.width ?? 0.75;
|
|
1569
1645
|
let boxWidth;
|
|
@@ -2208,6 +2284,78 @@ function renderGeomLinerange(data, geom, aes, scales, canvas) {
|
|
|
2208
2284
|
}
|
|
2209
2285
|
}
|
|
2210
2286
|
}
|
|
2287
|
+
function renderGeomCrossbar(data, geom, aes, scales, canvas) {
|
|
2288
|
+
const width = geom.params.width ?? 0.5;
|
|
2289
|
+
const fatten = geom.params.fatten ?? 2.5;
|
|
2290
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
2291
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
2292
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
2293
|
+
const plotBottom = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
|
|
2294
|
+
const halfWidth = Math.max(2, Math.round(width * 4));
|
|
2295
|
+
for (const row of data) {
|
|
2296
|
+
const xVal = row[aes.x];
|
|
2297
|
+
const yVal = row[aes.y];
|
|
2298
|
+
const ymin = row["ymin"];
|
|
2299
|
+
const ymax = row["ymax"];
|
|
2300
|
+
if (xVal === null || xVal === undefined || ymin === undefined || ymax === undefined) {
|
|
2301
|
+
continue;
|
|
2302
|
+
}
|
|
2303
|
+
const cx = Math.round(scales.x.map(xVal));
|
|
2304
|
+
const cy = yVal !== null && yVal !== undefined ? Math.round(scales.y.map(yVal)) : null;
|
|
2305
|
+
const cyMin = Math.round(scales.y.map(ymin));
|
|
2306
|
+
const cyMax = Math.round(scales.y.map(ymax));
|
|
2307
|
+
const color = getPointColor(row, aes, scales.color);
|
|
2308
|
+
const top = Math.min(cyMin, cyMax);
|
|
2309
|
+
const bottom = Math.max(cyMin, cyMax);
|
|
2310
|
+
const left = cx - halfWidth;
|
|
2311
|
+
const right = cx + halfWidth;
|
|
2312
|
+
for (let y = top;y <= bottom; y++) {
|
|
2313
|
+
if (y >= plotTop && y <= plotBottom) {
|
|
2314
|
+
if (left >= plotLeft && left <= plotRight) {
|
|
2315
|
+
canvas.drawChar(left, y, "│", color);
|
|
2316
|
+
}
|
|
2317
|
+
if (right >= plotLeft && right <= plotRight) {
|
|
2318
|
+
canvas.drawChar(right, y, "│", color);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
for (let x = left;x <= right; x++) {
|
|
2323
|
+
if (x >= plotLeft && x <= plotRight) {
|
|
2324
|
+
if (top >= plotTop && top <= plotBottom) {
|
|
2325
|
+
canvas.drawChar(x, top, "─", color);
|
|
2326
|
+
}
|
|
2327
|
+
if (bottom >= plotTop && bottom <= plotBottom) {
|
|
2328
|
+
canvas.drawChar(x, bottom, "─", color);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
if (left >= plotLeft && left <= plotRight) {
|
|
2333
|
+
if (top >= plotTop && top <= plotBottom)
|
|
2334
|
+
canvas.drawChar(left, top, "┌", color);
|
|
2335
|
+
if (bottom >= plotTop && bottom <= plotBottom)
|
|
2336
|
+
canvas.drawChar(left, bottom, "└", color);
|
|
2337
|
+
}
|
|
2338
|
+
if (right >= plotLeft && right <= plotRight) {
|
|
2339
|
+
if (top >= plotTop && top <= plotBottom)
|
|
2340
|
+
canvas.drawChar(right, top, "┐", color);
|
|
2341
|
+
if (bottom >= plotTop && bottom <= plotBottom)
|
|
2342
|
+
canvas.drawChar(right, bottom, "┘", color);
|
|
2343
|
+
}
|
|
2344
|
+
if (cy !== null && cy >= plotTop && cy <= plotBottom) {
|
|
2345
|
+
const fattenLines = Math.max(1, Math.round(fatten / 2));
|
|
2346
|
+
for (let dy = -fattenLines + 1;dy < fattenLines; dy++) {
|
|
2347
|
+
const lineY = cy + dy;
|
|
2348
|
+
if (lineY >= plotTop && lineY <= plotBottom && lineY >= top && lineY <= bottom) {
|
|
2349
|
+
for (let x = left + 1;x < right; x++) {
|
|
2350
|
+
if (x >= plotLeft && x <= plotRight) {
|
|
2351
|
+
canvas.drawChar(x, lineY, "━", color);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2211
2359
|
function renderGeomPointrange(data, geom, aes, scales, canvas) {
|
|
2212
2360
|
renderGeomLinerange(data, geom, aes, scales, canvas);
|
|
2213
2361
|
const plotLeft = Math.round(scales.x.range[0]);
|
|
@@ -2823,6 +2971,670 @@ function renderGeomBraille(data, geom, aes, scales, canvas) {
|
|
|
2823
2971
|
}
|
|
2824
2972
|
}
|
|
2825
2973
|
}
|
|
2974
|
+
function renderGeomCalendar(data, geom, aes, scales, canvas) {
|
|
2975
|
+
if (data.length === 0)
|
|
2976
|
+
return;
|
|
2977
|
+
const cellChar = geom.params.cell_char ?? "█";
|
|
2978
|
+
const emptyColor = parseColorToRgba(geom.params.empty_color ?? "#161b22");
|
|
2979
|
+
const fillColor = parseColorToRgba(geom.params.fill_color ?? "#39d353");
|
|
2980
|
+
const levels = geom.params.levels ?? 5;
|
|
2981
|
+
const showDays = geom.params.show_days ?? true;
|
|
2982
|
+
const showMonths = geom.params.show_months ?? true;
|
|
2983
|
+
const weekStart = geom.params.week_start ?? 0;
|
|
2984
|
+
const dateField = aes.x;
|
|
2985
|
+
const valueField = aes.fill || aes.y || "value";
|
|
2986
|
+
const entries = [];
|
|
2987
|
+
let minValue = Infinity;
|
|
2988
|
+
let maxValue = -Infinity;
|
|
2989
|
+
for (const row of data) {
|
|
2990
|
+
const dateVal = row[dateField];
|
|
2991
|
+
const val = Number(row[valueField]) || 0;
|
|
2992
|
+
let date;
|
|
2993
|
+
if (dateVal instanceof Date) {
|
|
2994
|
+
date = dateVal;
|
|
2995
|
+
} else if (typeof dateVal === "string" || typeof dateVal === "number") {
|
|
2996
|
+
date = new Date(dateVal);
|
|
2997
|
+
} else {
|
|
2998
|
+
continue;
|
|
2999
|
+
}
|
|
3000
|
+
if (isNaN(date.getTime()))
|
|
3001
|
+
continue;
|
|
3002
|
+
entries.push({ date, value: val });
|
|
3003
|
+
if (val < minValue)
|
|
3004
|
+
minValue = val;
|
|
3005
|
+
if (val > maxValue)
|
|
3006
|
+
maxValue = val;
|
|
3007
|
+
}
|
|
3008
|
+
if (entries.length === 0)
|
|
3009
|
+
return;
|
|
3010
|
+
entries.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
3011
|
+
const startDate = new Date(entries[0].date);
|
|
3012
|
+
const endDate = new Date(entries[entries.length - 1].date);
|
|
3013
|
+
startDate.setDate(startDate.getDate() - (startDate.getDay() - weekStart + 7) % 7);
|
|
3014
|
+
const valueMap = new Map;
|
|
3015
|
+
for (const entry of entries) {
|
|
3016
|
+
const key = entry.date.toISOString().slice(0, 10);
|
|
3017
|
+
valueMap.set(key, (valueMap.get(key) || 0) + entry.value);
|
|
3018
|
+
}
|
|
3019
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
3020
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
3021
|
+
const dayLabels = ["S", "M", "T", "W", "T", "F", "S"];
|
|
3022
|
+
const monthLabels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
3023
|
+
const msPerDay = 24 * 60 * 60 * 1000;
|
|
3024
|
+
const totalDays = Math.ceil((endDate.getTime() - startDate.getTime()) / msPerDay) + 7;
|
|
3025
|
+
const numWeeks = Math.ceil(totalDays / 7);
|
|
3026
|
+
const getColor = (value) => {
|
|
3027
|
+
if (value === 0 || maxValue === minValue)
|
|
3028
|
+
return emptyColor;
|
|
3029
|
+
const t = Math.min(1, Math.max(0, (value - minValue) / (maxValue - minValue)));
|
|
3030
|
+
const level = Math.floor(t * (levels - 1));
|
|
3031
|
+
const levelT = level / (levels - 1);
|
|
3032
|
+
return {
|
|
3033
|
+
r: Math.round(emptyColor.r + (fillColor.r - emptyColor.r) * levelT),
|
|
3034
|
+
g: Math.round(emptyColor.g + (fillColor.g - emptyColor.g) * levelT),
|
|
3035
|
+
b: Math.round(emptyColor.b + (fillColor.b - emptyColor.b) * levelT),
|
|
3036
|
+
a: 1
|
|
3037
|
+
};
|
|
3038
|
+
};
|
|
3039
|
+
const xOffset = showDays ? 3 : 0;
|
|
3040
|
+
const yOffset = showMonths ? 2 : 0;
|
|
3041
|
+
if (showDays) {
|
|
3042
|
+
for (let d = 0;d < 7; d++) {
|
|
3043
|
+
const dayIndex = (d + weekStart) % 7;
|
|
3044
|
+
const y = plotTop + yOffset + d;
|
|
3045
|
+
canvas.drawChar(plotLeft, y, dayLabels[dayIndex], { r: 128, g: 128, b: 128, a: 1 });
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
let lastMonth = -1;
|
|
3049
|
+
const currentDate = new Date(startDate);
|
|
3050
|
+
for (let week = 0;week < numWeeks; week++) {
|
|
3051
|
+
const x = plotLeft + xOffset + week * 2;
|
|
3052
|
+
if (showMonths && currentDate.getMonth() !== lastMonth) {
|
|
3053
|
+
const monthLabel = monthLabels[currentDate.getMonth()];
|
|
3054
|
+
for (let i = 0;i < monthLabel.length; i++) {
|
|
3055
|
+
canvas.drawChar(x + i, plotTop, monthLabel[i], { r: 128, g: 128, b: 128, a: 1 });
|
|
3056
|
+
}
|
|
3057
|
+
lastMonth = currentDate.getMonth();
|
|
3058
|
+
}
|
|
3059
|
+
for (let day = 0;day < 7; day++) {
|
|
3060
|
+
const dayDate = new Date(currentDate);
|
|
3061
|
+
dayDate.setDate(dayDate.getDate() + day);
|
|
3062
|
+
if (dayDate > endDate)
|
|
3063
|
+
break;
|
|
3064
|
+
const key = dayDate.toISOString().slice(0, 10);
|
|
3065
|
+
const value = valueMap.get(key) || 0;
|
|
3066
|
+
const color = getColor(value);
|
|
3067
|
+
const y = plotTop + yOffset + day;
|
|
3068
|
+
canvas.drawChar(x, y, cellChar, color);
|
|
3069
|
+
}
|
|
3070
|
+
currentDate.setDate(currentDate.getDate() + 7);
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
function renderGeomFlame(data, geom, aes, scales, canvas) {
|
|
3074
|
+
if (data.length === 0)
|
|
3075
|
+
return;
|
|
3076
|
+
const style = geom.params.style ?? "flame";
|
|
3077
|
+
const palette = geom.params.palette ?? "warm";
|
|
3078
|
+
const showLabels = geom.params.show_labels ?? true;
|
|
3079
|
+
const minLabelWidth = geom.params.min_label_width ?? 10;
|
|
3080
|
+
const barChar = geom.params.bar_char ?? "█";
|
|
3081
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
3082
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
3083
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
3084
|
+
const plotBottom = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
|
|
3085
|
+
const plotWidth = plotRight - plotLeft;
|
|
3086
|
+
const plotHeight = plotBottom - plotTop;
|
|
3087
|
+
const nameField = aes.x || "name";
|
|
3088
|
+
const valueField = aes.fill || "value";
|
|
3089
|
+
const depthField = aes.y || "depth";
|
|
3090
|
+
const startField = "start";
|
|
3091
|
+
const frames = [];
|
|
3092
|
+
let totalValue = 0;
|
|
3093
|
+
let maxDepth = 0;
|
|
3094
|
+
for (const row of data) {
|
|
3095
|
+
const name = String(row[nameField] || "");
|
|
3096
|
+
const value = Number(row[valueField]) || 0;
|
|
3097
|
+
const depth = Number(row[depthField]) || 0;
|
|
3098
|
+
const start = row[startField] !== undefined ? Number(row[startField]) : -1;
|
|
3099
|
+
frames.push({ name, value, depth, start, width: 0 });
|
|
3100
|
+
if (depth === 0)
|
|
3101
|
+
totalValue += value;
|
|
3102
|
+
if (depth > maxDepth)
|
|
3103
|
+
maxDepth = depth;
|
|
3104
|
+
}
|
|
3105
|
+
if (totalValue === 0)
|
|
3106
|
+
return;
|
|
3107
|
+
for (const frame of frames) {
|
|
3108
|
+
frame.width = frame.value / totalValue * plotWidth;
|
|
3109
|
+
}
|
|
3110
|
+
frames.sort((a, b) => {
|
|
3111
|
+
if (a.depth !== b.depth)
|
|
3112
|
+
return a.depth - b.depth;
|
|
3113
|
+
if (a.start !== b.start)
|
|
3114
|
+
return a.start - b.start;
|
|
3115
|
+
return a.name.localeCompare(b.name);
|
|
3116
|
+
});
|
|
3117
|
+
const depthOffsets = new Array(maxDepth + 1).fill(0);
|
|
3118
|
+
for (const frame of frames) {
|
|
3119
|
+
if (frame.start < 0) {
|
|
3120
|
+
frame.start = depthOffsets[frame.depth];
|
|
3121
|
+
}
|
|
3122
|
+
depthOffsets[frame.depth] = frame.start + frame.width;
|
|
3123
|
+
}
|
|
3124
|
+
const getPaletteColor = (name) => {
|
|
3125
|
+
let hash = 0;
|
|
3126
|
+
for (let i = 0;i < name.length; i++) {
|
|
3127
|
+
hash = (hash << 5) - hash + name.charCodeAt(i);
|
|
3128
|
+
hash = hash & hash;
|
|
3129
|
+
}
|
|
3130
|
+
const hue = Math.abs(hash) % 360;
|
|
3131
|
+
let h;
|
|
3132
|
+
if (palette === "warm") {
|
|
3133
|
+
h = hue % 60 + 0;
|
|
3134
|
+
} else if (palette === "cool") {
|
|
3135
|
+
h = hue % 60 + 180;
|
|
3136
|
+
} else {
|
|
3137
|
+
h = hue % 40 + 10;
|
|
3138
|
+
}
|
|
3139
|
+
const s = 0.7;
|
|
3140
|
+
const l = 0.5;
|
|
3141
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
3142
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
3143
|
+
const m = l - c / 2;
|
|
3144
|
+
let r = 0, g = 0, b = 0;
|
|
3145
|
+
if (h < 60) {
|
|
3146
|
+
r = c;
|
|
3147
|
+
g = x;
|
|
3148
|
+
b = 0;
|
|
3149
|
+
} else if (h < 120) {
|
|
3150
|
+
r = x;
|
|
3151
|
+
g = c;
|
|
3152
|
+
b = 0;
|
|
3153
|
+
} else if (h < 180) {
|
|
3154
|
+
r = 0;
|
|
3155
|
+
g = c;
|
|
3156
|
+
b = x;
|
|
3157
|
+
} else if (h < 240) {
|
|
3158
|
+
r = 0;
|
|
3159
|
+
g = x;
|
|
3160
|
+
b = c;
|
|
3161
|
+
} else if (h < 300) {
|
|
3162
|
+
r = x;
|
|
3163
|
+
g = 0;
|
|
3164
|
+
b = c;
|
|
3165
|
+
} else {
|
|
3166
|
+
r = c;
|
|
3167
|
+
g = 0;
|
|
3168
|
+
b = x;
|
|
3169
|
+
}
|
|
3170
|
+
return {
|
|
3171
|
+
r: Math.round((r + m) * 255),
|
|
3172
|
+
g: Math.round((g + m) * 255),
|
|
3173
|
+
b: Math.round((b + m) * 255),
|
|
3174
|
+
a: 1
|
|
3175
|
+
};
|
|
3176
|
+
};
|
|
3177
|
+
const rowHeight = Math.max(1, Math.floor(plotHeight / (maxDepth + 1)));
|
|
3178
|
+
for (const frame of frames) {
|
|
3179
|
+
const x1 = plotLeft + Math.round(frame.start);
|
|
3180
|
+
const x2 = plotLeft + Math.round(frame.start + frame.width);
|
|
3181
|
+
const width = x2 - x1;
|
|
3182
|
+
if (width < 1)
|
|
3183
|
+
continue;
|
|
3184
|
+
let y;
|
|
3185
|
+
if (style === "icicle") {
|
|
3186
|
+
y = plotTop + frame.depth * rowHeight;
|
|
3187
|
+
} else {
|
|
3188
|
+
y = plotBottom - (frame.depth + 1) * rowHeight;
|
|
3189
|
+
}
|
|
3190
|
+
const color = getPaletteColor(frame.name);
|
|
3191
|
+
for (let row = 0;row < rowHeight; row++) {
|
|
3192
|
+
for (let col = x1;col < x2; col++) {
|
|
3193
|
+
if (col >= plotLeft && col < plotRight && y + row >= plotTop && y + row < plotBottom) {
|
|
3194
|
+
canvas.drawChar(col, y + row, barChar, color);
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
if (showLabels && width >= minLabelWidth) {
|
|
3199
|
+
const label = frame.name.slice(0, width - 2);
|
|
3200
|
+
const labelX = x1 + 1;
|
|
3201
|
+
const labelY = y + Math.floor(rowHeight / 2);
|
|
3202
|
+
const textColor = { r: 255, g: 255, b: 255, a: 1 };
|
|
3203
|
+
for (let i = 0;i < label.length; i++) {
|
|
3204
|
+
if (labelX + i < x2 - 1) {
|
|
3205
|
+
canvas.drawChar(labelX + i, labelY, label[i], textColor);
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
function renderGeomCorrmat(data, geom, aes, scales, canvas) {
|
|
3212
|
+
if (data.length === 0)
|
|
3213
|
+
return;
|
|
3214
|
+
const showValues = geom.params.show_values ?? true;
|
|
3215
|
+
const decimals = geom.params.decimals ?? 2;
|
|
3216
|
+
const positiveColor = parseColorToRgba(geom.params.positive_color ?? "#2166ac");
|
|
3217
|
+
const negativeColor = parseColorToRgba(geom.params.negative_color ?? "#b2182b");
|
|
3218
|
+
const neutralColor = parseColorToRgba(geom.params.neutral_color ?? "#f7f7f7");
|
|
3219
|
+
const lowerTriangle = geom.params.lower_triangle ?? false;
|
|
3220
|
+
const upperTriangle = geom.params.upper_triangle ?? false;
|
|
3221
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
3222
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
3223
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
3224
|
+
const plotBottom = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
|
|
3225
|
+
const xField = aes.x || "var1";
|
|
3226
|
+
const yField = aes.y || "var2";
|
|
3227
|
+
const valueField = aes.fill || "correlation";
|
|
3228
|
+
const xVars = new Set;
|
|
3229
|
+
const yVars = new Set;
|
|
3230
|
+
const corrMap = new Map;
|
|
3231
|
+
for (const row of data) {
|
|
3232
|
+
const x = String(row[xField] || "");
|
|
3233
|
+
const y = String(row[yField] || "");
|
|
3234
|
+
const r = Number(row[valueField]) || 0;
|
|
3235
|
+
xVars.add(x);
|
|
3236
|
+
yVars.add(y);
|
|
3237
|
+
corrMap.set(`${x}|${y}`, r);
|
|
3238
|
+
}
|
|
3239
|
+
const xList = [...xVars];
|
|
3240
|
+
const yList = [...yVars];
|
|
3241
|
+
const numX = xList.length;
|
|
3242
|
+
const numY = yList.length;
|
|
3243
|
+
if (numX === 0 || numY === 0)
|
|
3244
|
+
return;
|
|
3245
|
+
const cellWidth = Math.max(4, Math.floor((plotRight - plotLeft) / numX));
|
|
3246
|
+
const cellHeight = Math.max(2, Math.floor((plotBottom - plotTop) / numY));
|
|
3247
|
+
const getColor = (r) => {
|
|
3248
|
+
const t = (r + 1) / 2;
|
|
3249
|
+
if (t < 0.5) {
|
|
3250
|
+
const s = t * 2;
|
|
3251
|
+
return {
|
|
3252
|
+
r: Math.round(negativeColor.r + (neutralColor.r - negativeColor.r) * s),
|
|
3253
|
+
g: Math.round(negativeColor.g + (neutralColor.g - negativeColor.g) * s),
|
|
3254
|
+
b: Math.round(negativeColor.b + (neutralColor.b - negativeColor.b) * s),
|
|
3255
|
+
a: 1
|
|
3256
|
+
};
|
|
3257
|
+
} else {
|
|
3258
|
+
const s = (t - 0.5) * 2;
|
|
3259
|
+
return {
|
|
3260
|
+
r: Math.round(neutralColor.r + (positiveColor.r - neutralColor.r) * s),
|
|
3261
|
+
g: Math.round(neutralColor.g + (positiveColor.g - neutralColor.g) * s),
|
|
3262
|
+
b: Math.round(neutralColor.b + (positiveColor.b - neutralColor.b) * s),
|
|
3263
|
+
a: 1
|
|
3264
|
+
};
|
|
3265
|
+
}
|
|
3266
|
+
};
|
|
3267
|
+
for (let i = 0;i < numX; i++) {
|
|
3268
|
+
for (let j = 0;j < numY; j++) {
|
|
3269
|
+
if (lowerTriangle && i < j)
|
|
3270
|
+
continue;
|
|
3271
|
+
if (upperTriangle && i > j)
|
|
3272
|
+
continue;
|
|
3273
|
+
const x = xList[i];
|
|
3274
|
+
const y = yList[j];
|
|
3275
|
+
const key = `${x}|${y}`;
|
|
3276
|
+
const r = corrMap.get(key) ?? corrMap.get(`${y}|${x}`) ?? (i === j ? 1 : 0);
|
|
3277
|
+
const color = getColor(r);
|
|
3278
|
+
const cellX = plotLeft + i * cellWidth;
|
|
3279
|
+
const cellY = plotTop + j * cellHeight;
|
|
3280
|
+
for (let cy = 0;cy < cellHeight; cy++) {
|
|
3281
|
+
for (let cx = 0;cx < cellWidth; cx++) {
|
|
3282
|
+
if (cellX + cx < plotRight && cellY + cy < plotBottom) {
|
|
3283
|
+
canvas.drawChar(cellX + cx, cellY + cy, "█", color);
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
if (showValues && cellWidth >= 4) {
|
|
3288
|
+
const valueStr = r.toFixed(decimals);
|
|
3289
|
+
const textX = cellX + Math.floor((cellWidth - valueStr.length) / 2);
|
|
3290
|
+
const textY = cellY + Math.floor(cellHeight / 2);
|
|
3291
|
+
const brightness = (color.r * 299 + color.g * 587 + color.b * 114) / 1000;
|
|
3292
|
+
const textColor = brightness > 128 ? { r: 0, g: 0, b: 0, a: 1 } : { r: 255, g: 255, b: 255, a: 1 };
|
|
3293
|
+
for (let k = 0;k < valueStr.length; k++) {
|
|
3294
|
+
if (textX + k < cellX + cellWidth && textX + k < plotRight) {
|
|
3295
|
+
canvas.drawChar(textX + k, textY, valueStr[k], textColor);
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
function renderGeomSankey(data, geom, aes, scales, canvas) {
|
|
3303
|
+
if (data.length === 0)
|
|
3304
|
+
return;
|
|
3305
|
+
const nodeWidth = geom.params.node_width ?? 3;
|
|
3306
|
+
const nodePadding = geom.params.node_padding ?? 2;
|
|
3307
|
+
const nodeChar = geom.params.node_char ?? "█";
|
|
3308
|
+
const showLabels = geom.params.show_labels ?? true;
|
|
3309
|
+
const showValues = geom.params.show_values ?? false;
|
|
3310
|
+
const minFlowWidth = geom.params.min_flow_width ?? 1;
|
|
3311
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
3312
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
3313
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
3314
|
+
const plotBottom = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
|
|
3315
|
+
const plotHeight = plotBottom - plotTop;
|
|
3316
|
+
const sourceField = aes.x || "source";
|
|
3317
|
+
const targetField = aes.y || "target";
|
|
3318
|
+
const valueField = aes.fill || "value";
|
|
3319
|
+
const nodes = new Map;
|
|
3320
|
+
const links = [];
|
|
3321
|
+
const sourceNodes = new Set;
|
|
3322
|
+
const targetNodes = new Set;
|
|
3323
|
+
for (const row of data) {
|
|
3324
|
+
const source = String(row[sourceField] ?? "");
|
|
3325
|
+
const target = String(row[targetField] ?? "");
|
|
3326
|
+
const value = Number(row[valueField]) || 0;
|
|
3327
|
+
if (!source || !target)
|
|
3328
|
+
continue;
|
|
3329
|
+
sourceNodes.add(source);
|
|
3330
|
+
targetNodes.add(target);
|
|
3331
|
+
links.push({ source, target, value });
|
|
3332
|
+
if (!nodes.has(source)) {
|
|
3333
|
+
nodes.set(source, { name: source, value: 0, column: 0, y: 0, height: 0 });
|
|
3334
|
+
}
|
|
3335
|
+
if (!nodes.has(target)) {
|
|
3336
|
+
nodes.set(target, { name: target, value: 0, column: 1, y: 0, height: 0 });
|
|
3337
|
+
}
|
|
3338
|
+
nodes.get(source).value += value;
|
|
3339
|
+
nodes.get(target).value += value;
|
|
3340
|
+
}
|
|
3341
|
+
for (const [name, node] of nodes) {
|
|
3342
|
+
if (sourceNodes.has(name) && !targetNodes.has(name)) {
|
|
3343
|
+
node.column = 0;
|
|
3344
|
+
} else if (targetNodes.has(name) && !sourceNodes.has(name)) {
|
|
3345
|
+
node.column = 1;
|
|
3346
|
+
} else {
|
|
3347
|
+
node.column = 0;
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
const columns = [[], []];
|
|
3351
|
+
for (const [, node] of nodes) {
|
|
3352
|
+
if (!columns[node.column])
|
|
3353
|
+
columns[node.column] = [];
|
|
3354
|
+
columns[node.column].push(node);
|
|
3355
|
+
}
|
|
3356
|
+
const maxColumnValue = Math.max(columns[0]?.reduce((sum, n) => sum + n.value, 0) || 0, columns[1]?.reduce((sum, n) => sum + n.value, 0) || 0);
|
|
3357
|
+
if (maxColumnValue === 0)
|
|
3358
|
+
return;
|
|
3359
|
+
const availableHeight = plotHeight - nodePadding * Math.max(columns[0]?.length || 0, columns[1]?.length || 0);
|
|
3360
|
+
for (let col = 0;col < 2; col++) {
|
|
3361
|
+
if (!columns[col])
|
|
3362
|
+
continue;
|
|
3363
|
+
let currentY = plotTop;
|
|
3364
|
+
columns[col].sort((a, b) => b.value - a.value);
|
|
3365
|
+
for (const node of columns[col]) {
|
|
3366
|
+
node.height = Math.max(1, Math.round(node.value / maxColumnValue * availableHeight));
|
|
3367
|
+
node.y = currentY;
|
|
3368
|
+
currentY += node.height + nodePadding;
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
const colorPalette = [
|
|
3372
|
+
{ r: 79, g: 169, b: 238, a: 1 },
|
|
3373
|
+
{ r: 240, g: 128, b: 60, a: 1 },
|
|
3374
|
+
{ r: 102, g: 194, b: 114, a: 1 },
|
|
3375
|
+
{ r: 218, g: 98, b: 125, a: 1 },
|
|
3376
|
+
{ r: 169, g: 140, b: 204, a: 1 },
|
|
3377
|
+
{ r: 255, g: 204, b: 102, a: 1 }
|
|
3378
|
+
];
|
|
3379
|
+
const nodeColors = new Map;
|
|
3380
|
+
let colorIdx = 0;
|
|
3381
|
+
for (const [name] of nodes) {
|
|
3382
|
+
nodeColors.set(name, colorPalette[colorIdx % colorPalette.length]);
|
|
3383
|
+
colorIdx++;
|
|
3384
|
+
}
|
|
3385
|
+
const labelSpace = showLabels ? 8 : 0;
|
|
3386
|
+
const col0X = plotLeft + labelSpace;
|
|
3387
|
+
const col1X = plotRight - nodeWidth - labelSpace;
|
|
3388
|
+
for (const [name, node] of nodes) {
|
|
3389
|
+
const x = node.column === 0 ? col0X : col1X;
|
|
3390
|
+
const color = nodeColors.get(name);
|
|
3391
|
+
for (let dy = 0;dy < node.height; dy++) {
|
|
3392
|
+
for (let dx = 0;dx < nodeWidth; dx++) {
|
|
3393
|
+
canvas.drawChar(x + dx, node.y + dy, nodeChar, color);
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
if (showLabels) {
|
|
3397
|
+
const labelX = node.column === 0 ? x - name.length - 1 : x + nodeWidth + 1;
|
|
3398
|
+
const labelY = node.y + Math.floor(node.height / 2);
|
|
3399
|
+
const labelColor = { r: 180, g: 180, b: 180, a: 1 };
|
|
3400
|
+
for (let i = 0;i < name.length && labelX + i >= plotLeft && labelX + i < plotRight; i++) {
|
|
3401
|
+
canvas.drawChar(labelX + i, labelY, name[i], labelColor);
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
for (const link of links) {
|
|
3406
|
+
const sourceNode = nodes.get(link.source);
|
|
3407
|
+
const targetNode = nodes.get(link.target);
|
|
3408
|
+
if (!sourceNode || !targetNode)
|
|
3409
|
+
continue;
|
|
3410
|
+
const flowWidth = Math.max(minFlowWidth, Math.round(link.value / maxColumnValue * (plotHeight / 4)));
|
|
3411
|
+
const sourceColor = nodeColors.get(link.source);
|
|
3412
|
+
const x1 = col0X + nodeWidth;
|
|
3413
|
+
const x2 = col1X;
|
|
3414
|
+
const y1 = sourceNode.y + Math.floor(sourceNode.height / 2);
|
|
3415
|
+
const y2 = targetNode.y + Math.floor(targetNode.height / 2);
|
|
3416
|
+
const steps = Math.abs(x2 - x1);
|
|
3417
|
+
for (let i = 0;i <= steps; i++) {
|
|
3418
|
+
const t = i / steps;
|
|
3419
|
+
const x = Math.round(x1 + (x2 - x1) * t);
|
|
3420
|
+
const y = Math.round(y1 + (y2 - y1) * (3 * t * t - 2 * t * t * t));
|
|
3421
|
+
const halfWidth = Math.floor(flowWidth / 2);
|
|
3422
|
+
for (let dy = -halfWidth;dy <= halfWidth; dy++) {
|
|
3423
|
+
const flowY = y + dy;
|
|
3424
|
+
if (flowY >= plotTop && flowY < plotBottom && x >= plotLeft && x < plotRight) {
|
|
3425
|
+
const flowColor = {
|
|
3426
|
+
r: sourceColor.r,
|
|
3427
|
+
g: sourceColor.g,
|
|
3428
|
+
b: sourceColor.b,
|
|
3429
|
+
a: 0.4
|
|
3430
|
+
};
|
|
3431
|
+
const char = dy === 0 ? "─" : "░";
|
|
3432
|
+
canvas.drawChar(x, flowY, char, flowColor);
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
if (showValues) {
|
|
3437
|
+
const midX = Math.round((x1 + x2) / 2);
|
|
3438
|
+
const midY = Math.round((y1 + y2) / 2);
|
|
3439
|
+
const valueStr = String(link.value);
|
|
3440
|
+
const textColor = { r: 200, g: 200, b: 200, a: 1 };
|
|
3441
|
+
for (let i = 0;i < valueStr.length; i++) {
|
|
3442
|
+
canvas.drawChar(midX - Math.floor(valueStr.length / 2) + i, midY, valueStr[i], textColor);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
function renderGeomTreemap(data, geom, aes, scales, canvas) {
|
|
3448
|
+
if (data.length === 0)
|
|
3449
|
+
return;
|
|
3450
|
+
const showLabels = geom.params.show_labels ?? true;
|
|
3451
|
+
const showValues = geom.params.show_values ?? false;
|
|
3452
|
+
const border = geom.params.border ?? true;
|
|
3453
|
+
const minLabelSize = geom.params.min_label_size ?? 4;
|
|
3454
|
+
const fillChar = geom.params.fill_char ?? "█";
|
|
3455
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
3456
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
3457
|
+
const plotTop = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
|
|
3458
|
+
const plotBottom = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
|
|
3459
|
+
const labelField = aes.x || "name";
|
|
3460
|
+
const valueField = aes.fill || aes.y || "value";
|
|
3461
|
+
const parentField = aes.group || "parent";
|
|
3462
|
+
const idField = aes.x || "id";
|
|
3463
|
+
const nodeMap = new Map;
|
|
3464
|
+
const roots = [];
|
|
3465
|
+
for (const row of data) {
|
|
3466
|
+
const id = String(row[idField] ?? row[labelField] ?? "");
|
|
3467
|
+
const label = String(row[labelField] ?? id);
|
|
3468
|
+
const value = Number(row[valueField]) || 0;
|
|
3469
|
+
const parent = row[parentField] ? String(row[parentField]) : undefined;
|
|
3470
|
+
const node = {
|
|
3471
|
+
id,
|
|
3472
|
+
label,
|
|
3473
|
+
value,
|
|
3474
|
+
parent,
|
|
3475
|
+
children: [],
|
|
3476
|
+
x: 0,
|
|
3477
|
+
y: 0,
|
|
3478
|
+
width: 0,
|
|
3479
|
+
height: 0
|
|
3480
|
+
};
|
|
3481
|
+
nodeMap.set(id, node);
|
|
3482
|
+
}
|
|
3483
|
+
for (const [, node] of nodeMap) {
|
|
3484
|
+
if (node.parent && nodeMap.has(node.parent)) {
|
|
3485
|
+
nodeMap.get(node.parent).children.push(node);
|
|
3486
|
+
} else {
|
|
3487
|
+
roots.push(node);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
if (roots.length === 0) {
|
|
3491
|
+
for (const [, node] of nodeMap) {
|
|
3492
|
+
roots.push(node);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
function calculateValue(node) {
|
|
3496
|
+
if (node.children.length === 0) {
|
|
3497
|
+
return node.value;
|
|
3498
|
+
}
|
|
3499
|
+
const childSum = node.children.reduce((sum, child) => sum + calculateValue(child), 0);
|
|
3500
|
+
return node.value || childSum;
|
|
3501
|
+
}
|
|
3502
|
+
for (const root of roots) {
|
|
3503
|
+
root.value = calculateValue(root);
|
|
3504
|
+
}
|
|
3505
|
+
const validRoots = roots.filter((n) => n.value > 0).sort((a, b) => b.value - a.value);
|
|
3506
|
+
if (validRoots.length === 0)
|
|
3507
|
+
return;
|
|
3508
|
+
function squarify(nodes, x, y, width, height) {
|
|
3509
|
+
if (nodes.length === 0 || width <= 0 || height <= 0)
|
|
3510
|
+
return;
|
|
3511
|
+
const totalValue = nodes.reduce((sum, n) => sum + n.value, 0);
|
|
3512
|
+
if (totalValue === 0)
|
|
3513
|
+
return;
|
|
3514
|
+
if (nodes.length === 1) {
|
|
3515
|
+
const node = nodes[0];
|
|
3516
|
+
node.x = x;
|
|
3517
|
+
node.y = y;
|
|
3518
|
+
node.width = width;
|
|
3519
|
+
node.height = height;
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
const isHorizontal = width > height;
|
|
3523
|
+
let currentPos = isHorizontal ? x : y;
|
|
3524
|
+
const totalSize = isHorizontal ? width : height;
|
|
3525
|
+
for (const node of nodes) {
|
|
3526
|
+
const fraction = node.value / totalValue;
|
|
3527
|
+
const size = Math.round(totalSize * fraction);
|
|
3528
|
+
if (isHorizontal) {
|
|
3529
|
+
node.x = currentPos;
|
|
3530
|
+
node.y = y;
|
|
3531
|
+
node.width = Math.max(1, size);
|
|
3532
|
+
node.height = height;
|
|
3533
|
+
currentPos += node.width;
|
|
3534
|
+
} else {
|
|
3535
|
+
node.x = x;
|
|
3536
|
+
node.y = currentPos;
|
|
3537
|
+
node.width = width;
|
|
3538
|
+
node.height = Math.max(1, size);
|
|
3539
|
+
currentPos += node.height;
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
squarify(validRoots, plotLeft, plotTop, plotRight - plotLeft, plotBottom - plotTop);
|
|
3544
|
+
const colorPalette = [
|
|
3545
|
+
{ r: 66, g: 133, b: 244, a: 1 },
|
|
3546
|
+
{ r: 234, g: 67, b: 53, a: 1 },
|
|
3547
|
+
{ r: 251, g: 188, b: 5, a: 1 },
|
|
3548
|
+
{ r: 52, g: 168, b: 83, a: 1 },
|
|
3549
|
+
{ r: 154, g: 102, b: 255, a: 1 },
|
|
3550
|
+
{ r: 255, g: 109, b: 0, a: 1 },
|
|
3551
|
+
{ r: 0, g: 188, b: 212, a: 1 },
|
|
3552
|
+
{ r: 233, g: 30, b: 99, a: 1 }
|
|
3553
|
+
];
|
|
3554
|
+
function renderNode(node, colorIndex, depth) {
|
|
3555
|
+
if (node.width <= 0 || node.height <= 0)
|
|
3556
|
+
return;
|
|
3557
|
+
const baseColor = colorPalette[colorIndex % colorPalette.length];
|
|
3558
|
+
const depthFactor = Math.max(0.5, 1 - depth * 0.15);
|
|
3559
|
+
const color = {
|
|
3560
|
+
r: Math.round(baseColor.r * depthFactor),
|
|
3561
|
+
g: Math.round(baseColor.g * depthFactor),
|
|
3562
|
+
b: Math.round(baseColor.b * depthFactor),
|
|
3563
|
+
a: 1
|
|
3564
|
+
};
|
|
3565
|
+
for (let dy = 0;dy < node.height; dy++) {
|
|
3566
|
+
for (let dx = 0;dx < node.width; dx++) {
|
|
3567
|
+
const px = node.x + dx;
|
|
3568
|
+
const py = node.y + dy;
|
|
3569
|
+
if (px >= plotLeft && px < plotRight && py >= plotTop && py < plotBottom) {
|
|
3570
|
+
canvas.drawChar(px, py, fillChar, color);
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
if (border && node.width >= 2 && node.height >= 2) {
|
|
3575
|
+
const borderColor = { r: 40, g: 40, b: 40, a: 1 };
|
|
3576
|
+
for (let dx = 0;dx < node.width; dx++) {
|
|
3577
|
+
const px = node.x + dx;
|
|
3578
|
+
if (px >= plotLeft && px < plotRight) {
|
|
3579
|
+
if (node.y >= plotTop)
|
|
3580
|
+
canvas.drawChar(px, node.y, "─", borderColor);
|
|
3581
|
+
if (node.y + node.height - 1 < plotBottom)
|
|
3582
|
+
canvas.drawChar(px, node.y + node.height - 1, "─", borderColor);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
for (let dy = 0;dy < node.height; dy++) {
|
|
3586
|
+
const py = node.y + dy;
|
|
3587
|
+
if (py >= plotTop && py < plotBottom) {
|
|
3588
|
+
if (node.x >= plotLeft)
|
|
3589
|
+
canvas.drawChar(node.x, py, "│", borderColor);
|
|
3590
|
+
if (node.x + node.width - 1 < plotRight)
|
|
3591
|
+
canvas.drawChar(node.x + node.width - 1, py, "│", borderColor);
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
if (node.x >= plotLeft && node.y >= plotTop)
|
|
3595
|
+
canvas.drawChar(node.x, node.y, "┌", borderColor);
|
|
3596
|
+
if (node.x + node.width - 1 < plotRight && node.y >= plotTop)
|
|
3597
|
+
canvas.drawChar(node.x + node.width - 1, node.y, "┐", borderColor);
|
|
3598
|
+
if (node.x >= plotLeft && node.y + node.height - 1 < plotBottom)
|
|
3599
|
+
canvas.drawChar(node.x, node.y + node.height - 1, "└", borderColor);
|
|
3600
|
+
if (node.x + node.width - 1 < plotRight && node.y + node.height - 1 < plotBottom)
|
|
3601
|
+
canvas.drawChar(node.x + node.width - 1, node.y + node.height - 1, "┘", borderColor);
|
|
3602
|
+
}
|
|
3603
|
+
if (showLabels && node.width >= minLabelSize && node.height >= 1) {
|
|
3604
|
+
const label = node.label.substring(0, node.width - 2);
|
|
3605
|
+
const labelX = node.x + 1;
|
|
3606
|
+
const labelY = node.y + Math.floor(node.height / 2);
|
|
3607
|
+
const brightness = (color.r * 299 + color.g * 587 + color.b * 114) / 1000;
|
|
3608
|
+
const textColor = brightness > 128 ? { r: 0, g: 0, b: 0, a: 1 } : { r: 255, g: 255, b: 255, a: 1 };
|
|
3609
|
+
for (let i = 0;i < label.length; i++) {
|
|
3610
|
+
const px = labelX + i;
|
|
3611
|
+
if (px >= plotLeft && px < node.x + node.width - 1 && px < plotRight) {
|
|
3612
|
+
canvas.drawChar(px, labelY, label[i], textColor);
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
if (showValues && node.height >= 3) {
|
|
3616
|
+
const valueStr = String(node.value);
|
|
3617
|
+
const valueY = labelY + 1;
|
|
3618
|
+
for (let i = 0;i < valueStr.length; i++) {
|
|
3619
|
+
const px = labelX + i;
|
|
3620
|
+
if (px >= plotLeft && px < node.x + node.width - 1 && px < plotRight && valueY < plotBottom) {
|
|
3621
|
+
canvas.drawChar(px, valueY, valueStr[i], textColor);
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
if (node.children.length > 0) {
|
|
3627
|
+
const childrenSorted = [...node.children].sort((a, b) => b.value - a.value);
|
|
3628
|
+
squarify(childrenSorted, node.x + (border ? 1 : 0), node.y + (border ? 1 : 0), node.width - (border ? 2 : 0), node.height - (border ? 2 : 0));
|
|
3629
|
+
for (let i = 0;i < childrenSorted.length; i++) {
|
|
3630
|
+
renderNode(childrenSorted[i], colorIndex, depth + 1);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
for (let i = 0;i < validRoots.length; i++) {
|
|
3635
|
+
renderNode(validRoots[i], i, 0);
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
2826
3638
|
function renderGeom(data, geom, aes, scales, canvas, coordType) {
|
|
2827
3639
|
switch (geom.type) {
|
|
2828
3640
|
case "point":
|
|
@@ -2860,6 +3672,9 @@ function renderGeom(data, geom, aes, scales, canvas, coordType) {
|
|
|
2860
3672
|
case "freqpoly":
|
|
2861
3673
|
renderGeomFreqpoly(data, geom, aes, scales, canvas);
|
|
2862
3674
|
break;
|
|
3675
|
+
case "density":
|
|
3676
|
+
renderGeomDensity(data, geom, aes, scales, canvas);
|
|
3677
|
+
break;
|
|
2863
3678
|
case "boxplot":
|
|
2864
3679
|
renderGeomBoxplot(data, geom, aes, scales, canvas);
|
|
2865
3680
|
break;
|
|
@@ -2898,6 +3713,9 @@ function renderGeom(data, geom, aes, scales, canvas, coordType) {
|
|
|
2898
3713
|
case "linerange":
|
|
2899
3714
|
renderGeomLinerange(data, geom, aes, scales, canvas);
|
|
2900
3715
|
break;
|
|
3716
|
+
case "crossbar":
|
|
3717
|
+
renderGeomCrossbar(data, geom, aes, scales, canvas);
|
|
3718
|
+
break;
|
|
2901
3719
|
case "pointrange":
|
|
2902
3720
|
renderGeomPointrange(data, geom, aes, scales, canvas);
|
|
2903
3721
|
break;
|
|
@@ -2926,6 +3744,22 @@ function renderGeom(data, geom, aes, scales, canvas, coordType) {
|
|
|
2926
3744
|
case "braille":
|
|
2927
3745
|
renderGeomBraille(data, geom, aes, scales, canvas);
|
|
2928
3746
|
break;
|
|
3747
|
+
case "calendar":
|
|
3748
|
+
renderGeomCalendar(data, geom, aes, scales, canvas);
|
|
3749
|
+
break;
|
|
3750
|
+
case "flame":
|
|
3751
|
+
case "icicle":
|
|
3752
|
+
renderGeomFlame(data, geom, aes, scales, canvas);
|
|
3753
|
+
break;
|
|
3754
|
+
case "corrmat":
|
|
3755
|
+
renderGeomCorrmat(data, geom, aes, scales, canvas);
|
|
3756
|
+
break;
|
|
3757
|
+
case "sankey":
|
|
3758
|
+
renderGeomSankey(data, geom, aes, scales, canvas);
|
|
3759
|
+
break;
|
|
3760
|
+
case "treemap":
|
|
3761
|
+
renderGeomTreemap(data, geom, aes, scales, canvas);
|
|
3762
|
+
break;
|
|
2929
3763
|
default:
|
|
2930
3764
|
break;
|
|
2931
3765
|
}
|
|
@@ -5931,6 +6765,26 @@ function geom_freqpoly(options = {}) {
|
|
|
5931
6765
|
};
|
|
5932
6766
|
}
|
|
5933
6767
|
|
|
6768
|
+
// src/geoms/density.ts
|
|
6769
|
+
function geom_density(options = {}) {
|
|
6770
|
+
return {
|
|
6771
|
+
type: "density",
|
|
6772
|
+
stat: "density",
|
|
6773
|
+
position: "identity",
|
|
6774
|
+
params: {
|
|
6775
|
+
n: options.n ?? 512,
|
|
6776
|
+
bw: options.bw,
|
|
6777
|
+
kernel: options.kernel ?? "gaussian",
|
|
6778
|
+
adjust: options.adjust ?? 1,
|
|
6779
|
+
alpha: options.alpha ?? 0.3,
|
|
6780
|
+
color: options.color,
|
|
6781
|
+
fill: options.fill,
|
|
6782
|
+
linewidth: options.linewidth ?? 1,
|
|
6783
|
+
linetype: options.linetype ?? "solid"
|
|
6784
|
+
}
|
|
6785
|
+
};
|
|
6786
|
+
}
|
|
6787
|
+
|
|
5934
6788
|
// src/geoms/boxplot.ts
|
|
5935
6789
|
function geom_boxplot(options = {}) {
|
|
5936
6790
|
return {
|
|
@@ -6423,6 +7277,110 @@ var init_braille = __esm(() => {
|
|
|
6423
7277
|
];
|
|
6424
7278
|
});
|
|
6425
7279
|
|
|
7280
|
+
// src/geoms/calendar.ts
|
|
7281
|
+
function geom_calendar(options = {}) {
|
|
7282
|
+
return {
|
|
7283
|
+
type: "calendar",
|
|
7284
|
+
stat: "identity",
|
|
7285
|
+
position: "identity",
|
|
7286
|
+
params: {
|
|
7287
|
+
cell_char: options.cell_char ?? "█",
|
|
7288
|
+
empty_char: options.empty_char ?? "░",
|
|
7289
|
+
empty_color: options.empty_color ?? "#161b22",
|
|
7290
|
+
fill_color: options.fill_color ?? "#39d353",
|
|
7291
|
+
show_months: options.show_months ?? true,
|
|
7292
|
+
show_days: options.show_days ?? true,
|
|
7293
|
+
week_start: options.week_start ?? 0,
|
|
7294
|
+
levels: options.levels ?? 5
|
|
7295
|
+
}
|
|
7296
|
+
};
|
|
7297
|
+
}
|
|
7298
|
+
|
|
7299
|
+
// src/geoms/flame.ts
|
|
7300
|
+
function geom_flame(options = {}) {
|
|
7301
|
+
return {
|
|
7302
|
+
type: "flame",
|
|
7303
|
+
stat: "identity",
|
|
7304
|
+
position: "identity",
|
|
7305
|
+
params: {
|
|
7306
|
+
style: options.style ?? "flame",
|
|
7307
|
+
palette: options.palette ?? "warm",
|
|
7308
|
+
show_labels: options.show_labels ?? true,
|
|
7309
|
+
min_label_width: options.min_label_width ?? 10,
|
|
7310
|
+
sort: options.sort ?? "alpha",
|
|
7311
|
+
bar_char: options.bar_char ?? "█"
|
|
7312
|
+
}
|
|
7313
|
+
};
|
|
7314
|
+
}
|
|
7315
|
+
function geom_icicle(options = {}) {
|
|
7316
|
+
return geom_flame({ ...options, style: "icicle" });
|
|
7317
|
+
}
|
|
7318
|
+
|
|
7319
|
+
// src/geoms/corrmat.ts
|
|
7320
|
+
function geom_corrmat(options = {}) {
|
|
7321
|
+
return {
|
|
7322
|
+
type: "corrmat",
|
|
7323
|
+
stat: "identity",
|
|
7324
|
+
position: "identity",
|
|
7325
|
+
params: {
|
|
7326
|
+
show_values: options.show_values ?? true,
|
|
7327
|
+
decimals: options.decimals ?? 2,
|
|
7328
|
+
show_significance: options.show_significance ?? false,
|
|
7329
|
+
sig_threshold: options.sig_threshold ?? 0.05,
|
|
7330
|
+
sig_marker: options.sig_marker ?? "*",
|
|
7331
|
+
positive_color: options.positive_color ?? "#2166ac",
|
|
7332
|
+
negative_color: options.negative_color ?? "#b2182b",
|
|
7333
|
+
neutral_color: options.neutral_color ?? "#f7f7f7",
|
|
7334
|
+
lower_triangle: options.lower_triangle ?? false,
|
|
7335
|
+
upper_triangle: options.upper_triangle ?? false,
|
|
7336
|
+
show_diagonal: options.show_diagonal ?? true,
|
|
7337
|
+
method: options.method ?? "pearson"
|
|
7338
|
+
}
|
|
7339
|
+
};
|
|
7340
|
+
}
|
|
7341
|
+
|
|
7342
|
+
// src/geoms/sankey.ts
|
|
7343
|
+
function geom_sankey(options = {}) {
|
|
7344
|
+
return {
|
|
7345
|
+
type: "sankey",
|
|
7346
|
+
stat: "identity",
|
|
7347
|
+
position: "identity",
|
|
7348
|
+
params: {
|
|
7349
|
+
node_width: options.node_width ?? 3,
|
|
7350
|
+
node_padding: options.node_padding ?? 2,
|
|
7351
|
+
node_char: options.node_char ?? "█",
|
|
7352
|
+
flow_char: options.flow_char ?? "─",
|
|
7353
|
+
show_labels: options.show_labels ?? true,
|
|
7354
|
+
show_values: options.show_values ?? false,
|
|
7355
|
+
align: options.align ?? "justify",
|
|
7356
|
+
color_by: options.color_by ?? "auto",
|
|
7357
|
+
min_flow_width: options.min_flow_width ?? 1,
|
|
7358
|
+
flow_gap: options.flow_gap ?? 0
|
|
7359
|
+
}
|
|
7360
|
+
};
|
|
7361
|
+
}
|
|
7362
|
+
|
|
7363
|
+
// src/geoms/treemap.ts
|
|
7364
|
+
function geom_treemap(options = {}) {
|
|
7365
|
+
return {
|
|
7366
|
+
type: "treemap",
|
|
7367
|
+
stat: "identity",
|
|
7368
|
+
position: "identity",
|
|
7369
|
+
params: {
|
|
7370
|
+
algorithm: options.algorithm ?? "squarify",
|
|
7371
|
+
show_labels: options.show_labels ?? true,
|
|
7372
|
+
show_values: options.show_values ?? false,
|
|
7373
|
+
border: options.border ?? true,
|
|
7374
|
+
padding: options.padding ?? 0,
|
|
7375
|
+
min_label_size: options.min_label_size ?? 4,
|
|
7376
|
+
color_by: options.color_by ?? "value",
|
|
7377
|
+
fill_char: options.fill_char ?? "█",
|
|
7378
|
+
max_depth: options.max_depth,
|
|
7379
|
+
aspect_ratio: options.aspect_ratio ?? 1.618
|
|
7380
|
+
}
|
|
7381
|
+
};
|
|
7382
|
+
}
|
|
7383
|
+
|
|
6426
7384
|
// src/geoms/index.ts
|
|
6427
7385
|
var init_geoms = __esm(() => {
|
|
6428
7386
|
init_ridgeline();
|
|
@@ -10933,12 +11891,14 @@ __export(exports_src, {
|
|
|
10933
11891
|
geom_waffle: () => geom_waffle,
|
|
10934
11892
|
geom_vline: () => geom_vline,
|
|
10935
11893
|
geom_violin: () => geom_violin,
|
|
11894
|
+
geom_treemap: () => geom_treemap,
|
|
10936
11895
|
geom_tile: () => geom_tile,
|
|
10937
11896
|
geom_text: () => geom_text,
|
|
10938
11897
|
geom_step: () => geom_step,
|
|
10939
11898
|
geom_sparkline: () => geom_sparkline,
|
|
10940
11899
|
geom_smooth: () => geom_smooth,
|
|
10941
11900
|
geom_segment: () => geom_segment,
|
|
11901
|
+
geom_sankey: () => geom_sankey,
|
|
10942
11902
|
geom_rug: () => geom_rug,
|
|
10943
11903
|
geom_ridgeline: () => geom_ridgeline,
|
|
10944
11904
|
geom_ribbon: () => geom_ribbon,
|
|
@@ -10955,18 +11915,23 @@ __export(exports_src, {
|
|
|
10955
11915
|
geom_line: () => geom_line,
|
|
10956
11916
|
geom_label: () => geom_label,
|
|
10957
11917
|
geom_joy: () => geom_joy,
|
|
11918
|
+
geom_icicle: () => geom_icicle,
|
|
10958
11919
|
geom_hline: () => geom_hline,
|
|
10959
11920
|
geom_histogram: () => geom_histogram,
|
|
10960
11921
|
geom_freqpoly: () => geom_freqpoly,
|
|
11922
|
+
geom_flame: () => geom_flame,
|
|
10961
11923
|
geom_errorbarh: () => geom_errorbarh,
|
|
10962
11924
|
geom_errorbar: () => geom_errorbar,
|
|
10963
11925
|
geom_dumbbell: () => geom_dumbbell,
|
|
10964
11926
|
geom_density_2d: () => geom_density_2d,
|
|
11927
|
+
geom_density: () => geom_density,
|
|
10965
11928
|
geom_curve: () => geom_curve,
|
|
10966
11929
|
geom_crossbar: () => geom_crossbar,
|
|
11930
|
+
geom_corrmat: () => geom_corrmat,
|
|
10967
11931
|
geom_contour_filled: () => geom_contour_filled,
|
|
10968
11932
|
geom_contour: () => geom_contour,
|
|
10969
11933
|
geom_col: () => geom_col,
|
|
11934
|
+
geom_calendar: () => geom_calendar,
|
|
10970
11935
|
geom_bullet: () => geom_bullet,
|
|
10971
11936
|
geom_braille: () => geom_braille,
|
|
10972
11937
|
geom_boxplot: () => geom_boxplot,
|
|
@@ -11195,12 +12160,14 @@ export {
|
|
|
11195
12160
|
geom_waffle,
|
|
11196
12161
|
geom_vline,
|
|
11197
12162
|
geom_violin,
|
|
12163
|
+
geom_treemap,
|
|
11198
12164
|
geom_tile,
|
|
11199
12165
|
geom_text,
|
|
11200
12166
|
geom_step,
|
|
11201
12167
|
geom_sparkline,
|
|
11202
12168
|
geom_smooth,
|
|
11203
12169
|
geom_segment,
|
|
12170
|
+
geom_sankey,
|
|
11204
12171
|
geom_rug,
|
|
11205
12172
|
geom_ridgeline,
|
|
11206
12173
|
geom_ribbon,
|
|
@@ -11217,18 +12184,23 @@ export {
|
|
|
11217
12184
|
geom_line,
|
|
11218
12185
|
geom_label,
|
|
11219
12186
|
geom_joy,
|
|
12187
|
+
geom_icicle,
|
|
11220
12188
|
geom_hline,
|
|
11221
12189
|
geom_histogram,
|
|
11222
12190
|
geom_freqpoly,
|
|
12191
|
+
geom_flame,
|
|
11223
12192
|
geom_errorbarh,
|
|
11224
12193
|
geom_errorbar,
|
|
11225
12194
|
geom_dumbbell,
|
|
11226
12195
|
geom_density_2d,
|
|
12196
|
+
geom_density,
|
|
11227
12197
|
geom_curve,
|
|
11228
12198
|
geom_crossbar,
|
|
12199
|
+
geom_corrmat,
|
|
11229
12200
|
geom_contour_filled,
|
|
11230
12201
|
geom_contour,
|
|
11231
12202
|
geom_col,
|
|
12203
|
+
geom_calendar,
|
|
11232
12204
|
geom_bullet,
|
|
11233
12205
|
geom_braille,
|
|
11234
12206
|
geom_boxplot,
|