@ggterm/core 0.2.16 → 0.2.20

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 (42) hide show
  1. package/dist/cli-plot.js +2526 -26
  2. package/dist/cli.js +2378 -25
  3. package/dist/geoms/biplot.d.ts +35 -0
  4. package/dist/geoms/biplot.d.ts.map +1 -0
  5. package/dist/geoms/bland-altman.d.ts +50 -0
  6. package/dist/geoms/bland-altman.d.ts.map +1 -0
  7. package/dist/geoms/control.d.ts +118 -0
  8. package/dist/geoms/control.d.ts.map +1 -0
  9. package/dist/geoms/dendrogram.d.ts +74 -0
  10. package/dist/geoms/dendrogram.d.ts.map +1 -0
  11. package/dist/geoms/ecdf.d.ts +66 -0
  12. package/dist/geoms/ecdf.d.ts.map +1 -0
  13. package/dist/geoms/forest.d.ts +45 -0
  14. package/dist/geoms/forest.d.ts.map +1 -0
  15. package/dist/geoms/funnel.d.ts +78 -0
  16. package/dist/geoms/funnel.d.ts.map +1 -0
  17. package/dist/geoms/heatmap.d.ts +34 -0
  18. package/dist/geoms/heatmap.d.ts.map +1 -0
  19. package/dist/geoms/index.d.ts +16 -1
  20. package/dist/geoms/index.d.ts.map +1 -1
  21. package/dist/geoms/kaplan-meier.d.ts +39 -0
  22. package/dist/geoms/kaplan-meier.d.ts.map +1 -0
  23. package/dist/geoms/ma.d.ts +77 -0
  24. package/dist/geoms/ma.d.ts.map +1 -0
  25. package/dist/geoms/manhattan.d.ts +29 -0
  26. package/dist/geoms/manhattan.d.ts.map +1 -0
  27. package/dist/geoms/qq.d.ts +51 -59
  28. package/dist/geoms/qq.d.ts.map +1 -1
  29. package/dist/geoms/roc.d.ts +44 -0
  30. package/dist/geoms/roc.d.ts.map +1 -0
  31. package/dist/geoms/scree.d.ts +97 -0
  32. package/dist/geoms/scree.d.ts.map +1 -0
  33. package/dist/geoms/upset.d.ts +63 -0
  34. package/dist/geoms/upset.d.ts.map +1 -0
  35. package/dist/geoms/volcano.d.ts +71 -0
  36. package/dist/geoms/volcano.d.ts.map +1 -0
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +2408 -27
  40. package/dist/pipeline/render-geoms.d.ts +8 -0
  41. package/dist/pipeline/render-geoms.d.ts.map +1 -1
  42. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3635,6 +3635,1550 @@ function renderGeomTreemap(data, geom, aes, scales, canvas) {
3635
3635
  renderNode(validRoots[i], i, 0);
3636
3636
  }
3637
3637
  }
3638
+ function renderGeomVolcano(data, geom, aes, scales, canvas) {
3639
+ const fcThreshold = geom.params.fc_threshold ?? 1;
3640
+ const pThreshold = geom.params.p_threshold ?? 0.05;
3641
+ const yIsNegLog10 = geom.params.y_is_neglog10 ?? false;
3642
+ const upColor = parseColorToRgba(geom.params.up_color ?? "#e41a1c");
3643
+ const downColor = parseColorToRgba(geom.params.down_color ?? "#377eb8");
3644
+ const nsColor = parseColorToRgba(geom.params.ns_color ?? "#999999");
3645
+ const showThresholds = geom.params.show_thresholds ?? true;
3646
+ const nLabels = geom.params.n_labels ?? 0;
3647
+ const pointChar = geom.params.point_char ?? "●";
3648
+ const negLog10PThreshold = -Math.log10(pThreshold);
3649
+ const points = [];
3650
+ for (const row of data) {
3651
+ const xVal = Number(row[aes.x]);
3652
+ let yVal = Number(row[aes.y]);
3653
+ if (isNaN(xVal) || isNaN(yVal) || yVal <= 0)
3654
+ continue;
3655
+ if (!yIsNegLog10) {
3656
+ yVal = -Math.log10(yVal);
3657
+ }
3658
+ let status = "ns";
3659
+ if (yVal >= negLog10PThreshold) {
3660
+ if (xVal >= fcThreshold) {
3661
+ status = "up";
3662
+ } else if (xVal <= -fcThreshold) {
3663
+ status = "down";
3664
+ }
3665
+ }
3666
+ const label = aes.label ? String(row[aes.label] ?? "") : undefined;
3667
+ points.push({
3668
+ row,
3669
+ x: xVal,
3670
+ y: yVal,
3671
+ significance: yVal,
3672
+ status,
3673
+ label
3674
+ });
3675
+ }
3676
+ if (showThresholds) {
3677
+ const thresholdColor = { r: 150, g: 150, b: 150, a: 0.7 };
3678
+ const cy = Math.round(scales.y.map(negLog10PThreshold));
3679
+ const startX = Math.round(scales.x.range[0]);
3680
+ const endX = Math.round(scales.x.range[1]);
3681
+ for (let x = startX;x <= endX; x += 2) {
3682
+ canvas.drawChar(x, cy, "─", thresholdColor);
3683
+ }
3684
+ const cxPos = Math.round(scales.x.map(fcThreshold));
3685
+ const cxNeg = Math.round(scales.x.map(-fcThreshold));
3686
+ const startY = Math.round(Math.min(scales.y.range[0], scales.y.range[1]));
3687
+ const endY = Math.round(Math.max(scales.y.range[0], scales.y.range[1]));
3688
+ for (let y = startY;y <= endY; y += 2) {
3689
+ canvas.drawChar(cxPos, y, "│", thresholdColor);
3690
+ canvas.drawChar(cxNeg, y, "│", thresholdColor);
3691
+ }
3692
+ }
3693
+ for (const point of points) {
3694
+ if (point.status === "ns") {
3695
+ const cx = Math.round(scales.x.map(point.x));
3696
+ const cy = Math.round(scales.y.map(point.y));
3697
+ canvas.drawPoint(cx, cy, nsColor, pointChar);
3698
+ }
3699
+ }
3700
+ for (const point of points) {
3701
+ if (point.status !== "ns") {
3702
+ const cx = Math.round(scales.x.map(point.x));
3703
+ const cy = Math.round(scales.y.map(point.y));
3704
+ const color = point.status === "up" ? upColor : downColor;
3705
+ canvas.drawPoint(cx, cy, color, pointChar);
3706
+ }
3707
+ }
3708
+ if (nLabels > 0 && aes.label) {
3709
+ const significantPoints = points.filter((p) => p.status !== "ns" && p.label).sort((a, b) => b.significance - a.significance).slice(0, nLabels);
3710
+ const labelColor = { r: 50, g: 50, b: 50, a: 1 };
3711
+ for (const point of significantPoints) {
3712
+ const cx = Math.round(scales.x.map(point.x));
3713
+ const cy = Math.round(scales.y.map(point.y));
3714
+ const label = point.label;
3715
+ const labelX = cx + 1;
3716
+ const labelY = cy;
3717
+ for (let i = 0;i < label.length; i++) {
3718
+ canvas.drawChar(labelX + i, labelY, label[i], labelColor);
3719
+ }
3720
+ }
3721
+ }
3722
+ }
3723
+ function renderGeomMA(data, geom, aes, scales, canvas) {
3724
+ const fcThreshold = geom.params.fc_threshold ?? 1;
3725
+ const pThreshold = geom.params.p_threshold ?? 0.05;
3726
+ const pCol = geom.params.p_col;
3727
+ const xIsLog2 = geom.params.x_is_log2 ?? false;
3728
+ const upColor = parseColorToRgba(geom.params.up_color ?? "#e41a1c");
3729
+ const downColor = parseColorToRgba(geom.params.down_color ?? "#377eb8");
3730
+ const nsColor = parseColorToRgba(geom.params.ns_color ?? "#999999");
3731
+ const showBaseline = geom.params.show_baseline ?? true;
3732
+ const showThresholds = geom.params.show_thresholds ?? true;
3733
+ const nLabels = geom.params.n_labels ?? 0;
3734
+ const pointChar = geom.params.point_char ?? "●";
3735
+ const points = [];
3736
+ for (const row of data) {
3737
+ let xVal = Number(row[aes.x]);
3738
+ const yVal = Number(row[aes.y]);
3739
+ if (isNaN(xVal) || isNaN(yVal))
3740
+ continue;
3741
+ if (xVal <= 0)
3742
+ continue;
3743
+ if (!xIsLog2) {
3744
+ xVal = Math.log2(xVal);
3745
+ }
3746
+ let status = "ns";
3747
+ const passesFcThreshold = Math.abs(yVal) >= fcThreshold;
3748
+ let passesPThreshold = true;
3749
+ if (pCol && row[pCol] !== undefined) {
3750
+ const pVal = Number(row[pCol]);
3751
+ passesPThreshold = !isNaN(pVal) && pVal < pThreshold;
3752
+ }
3753
+ if (passesFcThreshold && passesPThreshold) {
3754
+ status = yVal > 0 ? "up" : "down";
3755
+ }
3756
+ const label = aes.label ? String(row[aes.label] ?? "") : undefined;
3757
+ points.push({
3758
+ row,
3759
+ x: xVal,
3760
+ y: yVal,
3761
+ absM: Math.abs(yVal),
3762
+ status,
3763
+ label
3764
+ });
3765
+ }
3766
+ const lineColor = { r: 150, g: 150, b: 150, a: 0.7 };
3767
+ const startX = Math.round(scales.x.range[0]);
3768
+ const endX = Math.round(scales.x.range[1]);
3769
+ if (showBaseline) {
3770
+ const cy = Math.round(scales.y.map(0));
3771
+ for (let x = startX;x <= endX; x++) {
3772
+ canvas.drawChar(x, cy, "─", lineColor);
3773
+ }
3774
+ }
3775
+ if (showThresholds) {
3776
+ const cyUp = Math.round(scales.y.map(fcThreshold));
3777
+ const cyDown = Math.round(scales.y.map(-fcThreshold));
3778
+ for (let x = startX;x <= endX; x += 2) {
3779
+ canvas.drawChar(x, cyUp, "─", lineColor);
3780
+ canvas.drawChar(x, cyDown, "─", lineColor);
3781
+ }
3782
+ }
3783
+ for (const point of points) {
3784
+ if (point.status === "ns") {
3785
+ const cx = Math.round(scales.x.map(point.x));
3786
+ const cy = Math.round(scales.y.map(point.y));
3787
+ canvas.drawPoint(cx, cy, nsColor, pointChar);
3788
+ }
3789
+ }
3790
+ for (const point of points) {
3791
+ if (point.status !== "ns") {
3792
+ const cx = Math.round(scales.x.map(point.x));
3793
+ const cy = Math.round(scales.y.map(point.y));
3794
+ const color = point.status === "up" ? upColor : downColor;
3795
+ canvas.drawPoint(cx, cy, color, pointChar);
3796
+ }
3797
+ }
3798
+ if (nLabels > 0 && aes.label) {
3799
+ const significantPoints = points.filter((p) => p.status !== "ns" && p.label).sort((a, b) => b.absM - a.absM).slice(0, nLabels);
3800
+ const labelColor = { r: 50, g: 50, b: 50, a: 1 };
3801
+ for (const point of significantPoints) {
3802
+ const cx = Math.round(scales.x.map(point.x));
3803
+ const cy = Math.round(scales.y.map(point.y));
3804
+ const label = point.label;
3805
+ const labelX = cx + 1;
3806
+ const labelY = cy;
3807
+ for (let i = 0;i < label.length; i++) {
3808
+ canvas.drawChar(labelX + i, labelY, label[i], labelColor);
3809
+ }
3810
+ }
3811
+ }
3812
+ }
3813
+ function renderGeomManhattan(data, geom, aes, scales, canvas) {
3814
+ const params = geom.params || {};
3815
+ const suggestiveThreshold = Number(params.suggestive_threshold ?? 0.00001);
3816
+ const genomeWideThreshold = Number(params.genome_wide_threshold ?? 0.00000005);
3817
+ const yIsNegLog10 = Boolean(params.y_is_neglog10 ?? false);
3818
+ const chrColors = params.chr_colors ?? ["#1f78b4", "#a6cee3"];
3819
+ const highlightColor = String(params.highlight_color ?? "#e41a1c");
3820
+ const suggestiveColor = String(params.suggestive_color ?? "#ff7f00");
3821
+ const showThresholds = Boolean(params.show_thresholds ?? true);
3822
+ const nLabels = Number(params.n_labels ?? 0);
3823
+ const pointChar = String(params.point_char ?? "●");
3824
+ const chrGap = Number(params.chr_gap ?? 0.02);
3825
+ if (!Array.isArray(data) || data.length === 0)
3826
+ return;
3827
+ const parseHex = (hex) => {
3828
+ const r = parseInt(hex.slice(1, 3), 16);
3829
+ const g = parseInt(hex.slice(3, 5), 16);
3830
+ const b = parseInt(hex.slice(5, 7), 16);
3831
+ return { r, g, b, a: 1 };
3832
+ };
3833
+ const chrColorsParsed = chrColors.map((c) => parseHex(c));
3834
+ const highlightColorParsed = parseHex(highlightColor);
3835
+ const suggestiveColorParsed = parseHex(suggestiveColor);
3836
+ const suggestiveLine = -Math.log10(suggestiveThreshold);
3837
+ const genomeWideLine = -Math.log10(genomeWideThreshold);
3838
+ const xField = aes.x;
3839
+ const yField = aes.y;
3840
+ const labelField = aes.label;
3841
+ const points = [];
3842
+ const chrMap = new Map;
3843
+ for (const row of data) {
3844
+ let chr;
3845
+ let pos;
3846
+ const rawX = row[xField];
3847
+ const rawY = row[yField];
3848
+ if (typeof rawX === "string" && rawX.includes(":")) {
3849
+ const parts = rawX.split(":");
3850
+ chr = parts[0];
3851
+ pos = parseFloat(parts[1]);
3852
+ } else {
3853
+ chr = aes.color ? String(row[aes.color] ?? "1") : "1";
3854
+ pos = typeof rawX === "number" ? rawX : parseFloat(String(rawX));
3855
+ }
3856
+ const pval = typeof rawY === "number" ? rawY : parseFloat(String(rawY));
3857
+ if (isNaN(pos) || isNaN(pval) || pval <= 0)
3858
+ continue;
3859
+ const negLogP = yIsNegLog10 ? pval : -Math.log10(pval);
3860
+ const label = labelField ? String(row[labelField] ?? "") : undefined;
3861
+ const point = {
3862
+ chr,
3863
+ pos,
3864
+ pval: yIsNegLog10 ? Math.pow(10, -pval) : pval,
3865
+ negLogP,
3866
+ cumPos: 0,
3867
+ label,
3868
+ chrIndex: 0
3869
+ };
3870
+ if (!chrMap.has(chr)) {
3871
+ chrMap.set(chr, []);
3872
+ }
3873
+ chrMap.get(chr).push(point);
3874
+ points.push(point);
3875
+ }
3876
+ if (points.length === 0)
3877
+ return;
3878
+ const chrOrder = Array.from(chrMap.keys()).sort((a, b) => {
3879
+ const aNum = parseInt(String(a).replace(/^chr/i, ""));
3880
+ const bNum = parseInt(String(b).replace(/^chr/i, ""));
3881
+ if (!isNaN(aNum) && !isNaN(bNum))
3882
+ return aNum - bNum;
3883
+ if (!isNaN(aNum))
3884
+ return -1;
3885
+ if (!isNaN(bNum))
3886
+ return 1;
3887
+ return String(a).localeCompare(String(b));
3888
+ });
3889
+ let cumOffset = 0;
3890
+ const chrOffsets = new Map;
3891
+ for (let i = 0;i < chrOrder.length; i++) {
3892
+ const chr = chrOrder[i];
3893
+ chrOffsets.set(chr, cumOffset);
3894
+ const chrPoints = chrMap.get(chr);
3895
+ const maxPos = Math.max(...chrPoints.map((p) => p.pos));
3896
+ for (const point of chrPoints) {
3897
+ point.cumPos = cumOffset + point.pos;
3898
+ point.chrIndex = i;
3899
+ }
3900
+ cumOffset += maxPos * (1 + chrGap);
3901
+ }
3902
+ const minX = Math.min(...points.map((p) => p.cumPos));
3903
+ const maxX = Math.max(...points.map((p) => p.cumPos));
3904
+ const minY = 0;
3905
+ const maxY = Math.max(...points.map((p) => p.negLogP)) * 1.1;
3906
+ const plotLeft = Math.round(scales.x.range[0]);
3907
+ const plotRight = Math.round(scales.x.range[1]);
3908
+ const plotTop = Math.round(scales.y.range[1]);
3909
+ const plotBottom = Math.round(scales.y.range[0]);
3910
+ const mapX = (v) => plotLeft + (v - minX) / (maxX - minX) * (plotRight - plotLeft);
3911
+ const mapY = (v) => plotBottom - (v - minY) / (maxY - minY) * (plotBottom - plotTop);
3912
+ if (showThresholds) {
3913
+ const lineColor = { r: 150, g: 150, b: 150, a: 1 };
3914
+ if (suggestiveLine <= maxY) {
3915
+ const sy = Math.round(mapY(suggestiveLine));
3916
+ for (let x = plotLeft;x <= plotRight; x += 2) {
3917
+ canvas.drawChar(x, sy, "─", lineColor);
3918
+ }
3919
+ }
3920
+ if (genomeWideLine <= maxY) {
3921
+ const gy = Math.round(mapY(genomeWideLine));
3922
+ for (let x = plotLeft;x <= plotRight; x += 2) {
3923
+ canvas.drawChar(x, gy, "─", highlightColorParsed);
3924
+ }
3925
+ }
3926
+ }
3927
+ for (const point of points) {
3928
+ if (point.pval >= suggestiveThreshold) {
3929
+ const cx = Math.round(mapX(point.cumPos));
3930
+ const cy = Math.round(mapY(point.negLogP));
3931
+ const color = chrColorsParsed[point.chrIndex % chrColorsParsed.length];
3932
+ canvas.drawPoint(cx, cy, color, pointChar);
3933
+ }
3934
+ }
3935
+ for (const point of points) {
3936
+ if (point.pval < suggestiveThreshold && point.pval >= genomeWideThreshold) {
3937
+ const cx = Math.round(mapX(point.cumPos));
3938
+ const cy = Math.round(mapY(point.negLogP));
3939
+ canvas.drawPoint(cx, cy, suggestiveColorParsed, pointChar);
3940
+ }
3941
+ }
3942
+ for (const point of points) {
3943
+ if (point.pval < genomeWideThreshold) {
3944
+ const cx = Math.round(mapX(point.cumPos));
3945
+ const cy = Math.round(mapY(point.negLogP));
3946
+ canvas.drawPoint(cx, cy, highlightColorParsed, pointChar);
3947
+ }
3948
+ }
3949
+ if (nLabels > 0) {
3950
+ const labelColor = { r: 50, g: 50, b: 50, a: 1 };
3951
+ const topPoints = points.filter((p) => p.label && p.pval < suggestiveThreshold).sort((a, b) => a.pval - b.pval).slice(0, nLabels);
3952
+ for (const point of topPoints) {
3953
+ const cx = Math.round(mapX(point.cumPos));
3954
+ const cy = Math.round(mapY(point.negLogP));
3955
+ const label = point.label;
3956
+ for (let i = 0;i < label.length; i++) {
3957
+ canvas.drawChar(cx + 1 + i, cy, label[i], labelColor);
3958
+ }
3959
+ }
3960
+ }
3961
+ }
3962
+ function renderGeomHeatmap(data, geom, aes, scales, canvas) {
3963
+ const params = geom.params || {};
3964
+ const valueCol = String(params.value_col ?? "value");
3965
+ const lowColor = String(params.low_color ?? "#313695");
3966
+ const midColor = String(params.mid_color ?? "#ffffbf");
3967
+ const highColor = String(params.high_color ?? "#a50026");
3968
+ const naColor = String(params.na_color ?? "#808080");
3969
+ const clusterRows = Boolean(params.cluster_rows ?? false);
3970
+ const clusterCols = Boolean(params.cluster_cols ?? false);
3971
+ const showRowLabels = Boolean(params.show_row_labels ?? true);
3972
+ const showColLabels = Boolean(params.show_col_labels ?? true);
3973
+ const cellChar = String(params.cell_char ?? "█");
3974
+ const scaleMethod = String(params.scale ?? "none");
3975
+ if (!Array.isArray(data) || data.length === 0)
3976
+ return;
3977
+ const xField = typeof aes.x === "string" ? aes.x : "x";
3978
+ const yField = typeof aes.y === "string" ? aes.y : "y";
3979
+ const fillField = typeof aes.fill === "string" ? aes.fill : valueCol;
3980
+ const parseHex = (hex) => {
3981
+ const r = parseInt(hex.slice(1, 3), 16);
3982
+ const g = parseInt(hex.slice(3, 5), 16);
3983
+ const b = parseInt(hex.slice(5, 7), 16);
3984
+ return { r, g, b, a: 1 };
3985
+ };
3986
+ const lowRgb = parseHex(lowColor);
3987
+ const midRgb = parseHex(midColor);
3988
+ const highRgb = parseHex(highColor);
3989
+ const naRgb = parseHex(naColor);
3990
+ const rowSet = new Set;
3991
+ const colSet = new Set;
3992
+ const valueMap = new Map;
3993
+ for (const row of data) {
3994
+ const rowKey = String(row[yField] ?? "");
3995
+ const colKey = String(row[xField] ?? "");
3996
+ const val = row[fillField];
3997
+ if (rowKey && colKey) {
3998
+ rowSet.add(rowKey);
3999
+ colSet.add(colKey);
4000
+ if (typeof val === "number" && !isNaN(val)) {
4001
+ valueMap.set(`${rowKey}|${colKey}`, val);
4002
+ }
4003
+ }
4004
+ }
4005
+ let rowKeys = Array.from(rowSet);
4006
+ let colKeys = Array.from(colSet);
4007
+ if (rowKeys.length === 0 || colKeys.length === 0)
4008
+ return;
4009
+ const clusterOrder = (keys, getDistance) => {
4010
+ if (keys.length <= 2)
4011
+ return keys;
4012
+ const remaining = [...keys];
4013
+ const result = [];
4014
+ let minAvg = Infinity;
4015
+ let startIdx = 0;
4016
+ for (let i = 0;i < remaining.length; i++) {
4017
+ let sum = 0;
4018
+ for (let j = 0;j < remaining.length; j++) {
4019
+ if (i !== j)
4020
+ sum += getDistance(remaining[i], remaining[j]);
4021
+ }
4022
+ const avg = sum / (remaining.length - 1);
4023
+ if (avg < minAvg) {
4024
+ minAvg = avg;
4025
+ startIdx = i;
4026
+ }
4027
+ }
4028
+ result.push(remaining.splice(startIdx, 1)[0]);
4029
+ while (remaining.length > 0) {
4030
+ let minDist = Infinity;
4031
+ let minIdx = 0;
4032
+ for (let i = 0;i < remaining.length; i++) {
4033
+ const dist = getDistance(result[result.length - 1], remaining[i]);
4034
+ if (dist < minDist) {
4035
+ minDist = dist;
4036
+ minIdx = i;
4037
+ }
4038
+ }
4039
+ result.push(remaining.splice(minIdx, 1)[0]);
4040
+ }
4041
+ return result;
4042
+ };
4043
+ if (clusterRows) {
4044
+ const rowDistance = (a, b) => {
4045
+ let sum = 0;
4046
+ let count = 0;
4047
+ for (const col of colKeys) {
4048
+ const va = valueMap.get(`${a}|${col}`);
4049
+ const vb = valueMap.get(`${b}|${col}`);
4050
+ if (va !== undefined && vb !== undefined) {
4051
+ sum += (va - vb) ** 2;
4052
+ count++;
4053
+ }
4054
+ }
4055
+ return count > 0 ? Math.sqrt(sum / count) : Infinity;
4056
+ };
4057
+ rowKeys = clusterOrder(rowKeys, rowDistance);
4058
+ }
4059
+ if (clusterCols) {
4060
+ const colDistance = (a, b) => {
4061
+ let sum = 0;
4062
+ let count = 0;
4063
+ for (const row of rowKeys) {
4064
+ const va = valueMap.get(`${row}|${a}`);
4065
+ const vb = valueMap.get(`${row}|${b}`);
4066
+ if (va !== undefined && vb !== undefined) {
4067
+ sum += (va - vb) ** 2;
4068
+ count++;
4069
+ }
4070
+ }
4071
+ return count > 0 ? Math.sqrt(sum / count) : Infinity;
4072
+ };
4073
+ colKeys = clusterOrder(colKeys, colDistance);
4074
+ }
4075
+ const values = Array.from(valueMap.values());
4076
+ let minVal = Math.min(...values);
4077
+ let maxVal = Math.max(...values);
4078
+ const scaledValues = new Map;
4079
+ if (scaleMethod === "row") {
4080
+ for (const rowKey of rowKeys) {
4081
+ const rowVals = colKeys.map((c) => valueMap.get(`${rowKey}|${c}`)).filter((v) => v !== undefined);
4082
+ if (rowVals.length > 0) {
4083
+ const mean = rowVals.reduce((a, b) => a + b, 0) / rowVals.length;
4084
+ const std = Math.sqrt(rowVals.reduce((a, b) => a + (b - mean) ** 2, 0) / rowVals.length) || 1;
4085
+ for (const colKey of colKeys) {
4086
+ const v = valueMap.get(`${rowKey}|${colKey}`);
4087
+ if (v !== undefined) {
4088
+ scaledValues.set(`${rowKey}|${colKey}`, (v - mean) / std);
4089
+ }
4090
+ }
4091
+ }
4092
+ }
4093
+ } else if (scaleMethod === "column") {
4094
+ for (const colKey of colKeys) {
4095
+ const colVals = rowKeys.map((r) => valueMap.get(`${r}|${colKey}`)).filter((v) => v !== undefined);
4096
+ if (colVals.length > 0) {
4097
+ const mean = colVals.reduce((a, b) => a + b, 0) / colVals.length;
4098
+ const std = Math.sqrt(colVals.reduce((a, b) => a + (b - mean) ** 2, 0) / colVals.length) || 1;
4099
+ for (const rowKey of rowKeys) {
4100
+ const v = valueMap.get(`${rowKey}|${colKey}`);
4101
+ if (v !== undefined) {
4102
+ scaledValues.set(`${rowKey}|${colKey}`, (v - mean) / std);
4103
+ }
4104
+ }
4105
+ }
4106
+ }
4107
+ }
4108
+ const finalValues = scaleMethod === "none" ? valueMap : scaledValues;
4109
+ if (scaleMethod !== "none") {
4110
+ const scaled = Array.from(finalValues.values());
4111
+ minVal = Math.min(...scaled);
4112
+ maxVal = Math.max(...scaled);
4113
+ }
4114
+ const interpolateColor2 = (val) => {
4115
+ if (isNaN(val))
4116
+ return naRgb;
4117
+ const t = (val - minVal) / (maxVal - minVal || 1);
4118
+ if (t <= 0.5) {
4119
+ const t2 = t * 2;
4120
+ return {
4121
+ r: Math.round(lowRgb.r + (midRgb.r - lowRgb.r) * t2),
4122
+ g: Math.round(lowRgb.g + (midRgb.g - lowRgb.g) * t2),
4123
+ b: Math.round(lowRgb.b + (midRgb.b - lowRgb.b) * t2),
4124
+ a: 1
4125
+ };
4126
+ } else {
4127
+ const t2 = (t - 0.5) * 2;
4128
+ return {
4129
+ r: Math.round(midRgb.r + (highRgb.r - midRgb.r) * t2),
4130
+ g: Math.round(midRgb.g + (highRgb.g - midRgb.g) * t2),
4131
+ b: Math.round(midRgb.b + (highRgb.b - midRgb.b) * t2),
4132
+ a: 1
4133
+ };
4134
+ }
4135
+ };
4136
+ const plotLeft = Math.round(scales.x.range[0]);
4137
+ const plotRight = Math.round(scales.x.range[1]);
4138
+ const plotTop = Math.round(scales.y.range[1]);
4139
+ const plotBottom = Math.round(scales.y.range[0]);
4140
+ const labelWidth = showRowLabels ? Math.min(10, Math.max(...rowKeys.map((k) => k.length))) + 1 : 0;
4141
+ const labelHeight = showColLabels ? 1 : 0;
4142
+ const availWidth = plotRight - plotLeft - labelWidth;
4143
+ const availHeight = plotBottom - plotTop - labelHeight;
4144
+ const cellWidth = Math.max(1, Math.floor(availWidth / colKeys.length));
4145
+ const cellHeight = Math.max(1, Math.floor(availHeight / rowKeys.length));
4146
+ for (let ri = 0;ri < rowKeys.length; ri++) {
4147
+ const rowKey = rowKeys[ri];
4148
+ const baseY = plotTop + labelHeight + ri * cellHeight;
4149
+ for (let ci = 0;ci < colKeys.length; ci++) {
4150
+ const colKey = colKeys[ci];
4151
+ const baseX = plotLeft + labelWidth + ci * cellWidth;
4152
+ const val = finalValues.get(`${rowKey}|${colKey}`);
4153
+ const color = val !== undefined ? interpolateColor2(val) : naRgb;
4154
+ for (let dy = 0;dy < cellHeight; dy++) {
4155
+ for (let dx = 0;dx < cellWidth; dx++) {
4156
+ canvas.drawChar(baseX + dx, baseY + dy, cellChar, color);
4157
+ }
4158
+ }
4159
+ }
4160
+ }
4161
+ if (showRowLabels) {
4162
+ const labelColor = { r: 180, g: 180, b: 180, a: 1 };
4163
+ for (let ri = 0;ri < rowKeys.length; ri++) {
4164
+ const label = rowKeys[ri].slice(0, labelWidth - 1);
4165
+ const y = plotTop + labelHeight + ri * cellHeight + Math.floor(cellHeight / 2);
4166
+ for (let i = 0;i < label.length; i++) {
4167
+ canvas.drawChar(plotLeft + i, y, label[i], labelColor);
4168
+ }
4169
+ }
4170
+ }
4171
+ if (showColLabels) {
4172
+ const labelColor = { r: 180, g: 180, b: 180, a: 1 };
4173
+ for (let ci = 0;ci < colKeys.length; ci++) {
4174
+ const label = colKeys[ci].slice(0, cellWidth);
4175
+ const x = plotLeft + labelWidth + ci * cellWidth + Math.floor(cellWidth / 2);
4176
+ for (let i = 0;i < Math.min(label.length, 1); i++) {
4177
+ canvas.drawChar(x, plotTop + i, label[i], labelColor);
4178
+ }
4179
+ }
4180
+ }
4181
+ }
4182
+ function renderGeomBiplot(data, geom, aes, scales, canvas) {
4183
+ const params = geom.params || {};
4184
+ const pc1Col = params.pc1_col ?? "PC1";
4185
+ const pc2Col = params.pc2_col ?? "PC2";
4186
+ const loadings = params.loadings;
4187
+ const showScores = params.show_scores ?? true;
4188
+ const scoreChar = String(params.score_char ?? "●");
4189
+ const showScoreLabels = params.show_score_labels ?? false;
4190
+ const showLoadings = params.show_loadings ?? true;
4191
+ const loadingColor = String(params.loading_color ?? "#e41a1c");
4192
+ const loadingScale = params.loading_scale;
4193
+ const showLoadingLabels = params.show_loading_labels ?? true;
4194
+ const showOrigin = params.show_origin ?? true;
4195
+ const originColor = String(params.origin_color ?? "#999999");
4196
+ if (!Array.isArray(data) || data.length === 0)
4197
+ return;
4198
+ const parseHex = (hex) => {
4199
+ const r = parseInt(hex.slice(1, 3), 16);
4200
+ const g = parseInt(hex.slice(3, 5), 16);
4201
+ const b = parseInt(hex.slice(5, 7), 16);
4202
+ return { r, g, b, a: 1 };
4203
+ };
4204
+ const loadingColorParsed = parseHex(loadingColor);
4205
+ const originColorParsed = parseHex(originColor);
4206
+ const scores = [];
4207
+ const xField = typeof aes.x === "string" ? aes.x : pc1Col;
4208
+ const yField = typeof aes.y === "string" ? aes.y : pc2Col;
4209
+ const labelField = typeof aes.label === "string" ? aes.label : undefined;
4210
+ const colorField = typeof aes.color === "string" ? aes.color : undefined;
4211
+ for (const row of data) {
4212
+ const rawPc1 = row[xField];
4213
+ const rawPc2 = row[yField];
4214
+ const pc1 = typeof rawPc1 === "number" ? rawPc1 : parseFloat(String(rawPc1));
4215
+ const pc2 = typeof rawPc2 === "number" ? rawPc2 : parseFloat(String(rawPc2));
4216
+ if (!isNaN(pc1) && !isNaN(pc2)) {
4217
+ const point = { pc1, pc2 };
4218
+ if (labelField)
4219
+ point.label = String(row[labelField] ?? "");
4220
+ if (colorField && scales.color) {
4221
+ point.color = scales.color.map(row[colorField]);
4222
+ }
4223
+ scores.push(point);
4224
+ }
4225
+ }
4226
+ if (scores.length === 0)
4227
+ return;
4228
+ let minX = Math.min(...scores.map((s) => s.pc1));
4229
+ let maxX = Math.max(...scores.map((s) => s.pc1));
4230
+ let minY = Math.min(...scores.map((s) => s.pc2));
4231
+ let maxY = Math.max(...scores.map((s) => s.pc2));
4232
+ let actualLoadingScale = loadingScale;
4233
+ if (loadings && loadings.length > 0 && !actualLoadingScale) {
4234
+ const maxLoading = Math.max(...loadings.map((l) => Math.sqrt(l.pc1 ** 2 + l.pc2 ** 2)));
4235
+ const maxScore = Math.max(Math.abs(minX), Math.abs(maxX), Math.abs(minY), Math.abs(maxY));
4236
+ actualLoadingScale = maxScore * 0.8 / (maxLoading || 1);
4237
+ }
4238
+ if (loadings && actualLoadingScale) {
4239
+ for (const l of loadings) {
4240
+ const lx = l.pc1 * actualLoadingScale;
4241
+ const ly = l.pc2 * actualLoadingScale;
4242
+ minX = Math.min(minX, lx);
4243
+ maxX = Math.max(maxX, lx);
4244
+ minY = Math.min(minY, ly);
4245
+ maxY = Math.max(maxY, ly);
4246
+ }
4247
+ }
4248
+ const rangeX = maxX - minX || 1;
4249
+ const rangeY = maxY - minY || 1;
4250
+ minX -= rangeX * 0.1;
4251
+ maxX += rangeX * 0.1;
4252
+ minY -= rangeY * 0.1;
4253
+ maxY += rangeY * 0.1;
4254
+ const plotLeft = Math.round(scales.x.range[0]);
4255
+ const plotRight = Math.round(scales.x.range[1]);
4256
+ const plotTop = Math.round(scales.y.range[1]);
4257
+ const plotBottom = Math.round(scales.y.range[0]);
4258
+ const mapX = (v) => plotLeft + (v - minX) / (maxX - minX) * (plotRight - plotLeft);
4259
+ const mapY = (v) => plotBottom - (v - minY) / (maxY - minY) * (plotBottom - plotTop);
4260
+ if (showOrigin && minX <= 0 && maxX >= 0 && minY <= 0 && maxY >= 0) {
4261
+ const originX = Math.round(mapX(0));
4262
+ const originY = Math.round(mapY(0));
4263
+ for (let x = plotLeft;x <= plotRight; x++) {
4264
+ canvas.drawChar(x, originY, "─", originColorParsed);
4265
+ }
4266
+ for (let y = plotTop;y <= plotBottom; y++) {
4267
+ canvas.drawChar(originX, y, "│", originColorParsed);
4268
+ }
4269
+ canvas.drawChar(originX, originY, "┼", originColorParsed);
4270
+ }
4271
+ if (showLoadings && loadings && actualLoadingScale) {
4272
+ for (const loading of loadings) {
4273
+ const endX = loading.pc1 * actualLoadingScale;
4274
+ const endY = loading.pc2 * actualLoadingScale;
4275
+ const sx = Math.round(mapX(0));
4276
+ const sy = Math.round(mapY(0));
4277
+ const ex = Math.round(mapX(endX));
4278
+ const ey = Math.round(mapY(endY));
4279
+ const steps = Math.max(Math.abs(ex - sx), Math.abs(ey - sy));
4280
+ for (let i = 0;i <= steps; i++) {
4281
+ const t = steps > 0 ? i / steps : 0;
4282
+ const px = Math.round(sx + (ex - sx) * t);
4283
+ const py = Math.round(sy + (ey - sy) * t);
4284
+ const dx = ex - sx;
4285
+ const dy = ey - sy;
4286
+ let char = "·";
4287
+ if (Math.abs(dx) > Math.abs(dy) * 2) {
4288
+ char = dx > 0 ? "─" : "─";
4289
+ } else if (Math.abs(dy) > Math.abs(dx) * 2) {
4290
+ char = "│";
4291
+ } else if (dx > 0 && dy < 0 || dx < 0 && dy > 0) {
4292
+ char = "/";
4293
+ } else {
4294
+ char = "\\";
4295
+ }
4296
+ canvas.drawChar(px, py, char, loadingColorParsed);
4297
+ }
4298
+ const angle = Math.atan2(ey - sy, ex - sx);
4299
+ let arrowChar = "→";
4300
+ if (angle > Math.PI * 3 / 4 || angle < -Math.PI * 3 / 4)
4301
+ arrowChar = "←";
4302
+ else if (angle > Math.PI / 4)
4303
+ arrowChar = "↓";
4304
+ else if (angle < -Math.PI / 4)
4305
+ arrowChar = "↑";
4306
+ canvas.drawChar(ex, ey, arrowChar, loadingColorParsed);
4307
+ if (showLoadingLabels) {
4308
+ const labelX = ex + (ex >= sx ? 1 : -loading.variable.length);
4309
+ for (let i = 0;i < loading.variable.length; i++) {
4310
+ canvas.drawChar(labelX + i, ey, loading.variable[i], loadingColorParsed);
4311
+ }
4312
+ }
4313
+ }
4314
+ }
4315
+ if (showScores) {
4316
+ const defaultColor = { r: 31, g: 120, b: 180, a: 1 };
4317
+ for (const score of scores) {
4318
+ const cx = Math.round(mapX(score.pc1));
4319
+ const cy = Math.round(mapY(score.pc2));
4320
+ const color = score.color ?? defaultColor;
4321
+ canvas.drawPoint(cx, cy, color, scoreChar);
4322
+ if (showScoreLabels && score.label) {
4323
+ const labelColor = { r: 50, g: 50, b: 50, a: 1 };
4324
+ for (let i = 0;i < score.label.length; i++) {
4325
+ canvas.drawChar(cx + 1 + i, cy, score.label[i], labelColor);
4326
+ }
4327
+ }
4328
+ }
4329
+ }
4330
+ }
4331
+ function renderGeomKaplanMeier(data, geom, aes, scales, canvas) {
4332
+ const params = geom.params || {};
4333
+ const showCensored = Boolean(params.show_censored ?? true);
4334
+ const censorChar = String(params.censor_char ?? "+");
4335
+ const showMedian = Boolean(params.show_median ?? false);
4336
+ if (!Array.isArray(data) || data.length === 0)
4337
+ return;
4338
+ const xField = typeof aes.x === "string" ? aes.x : "time";
4339
+ const yField = typeof aes.y === "string" ? aes.y : "status";
4340
+ const colorField = typeof aes.color === "string" ? aes.color : undefined;
4341
+ const groups = new Map;
4342
+ for (const row of data) {
4343
+ const time = Number(row[xField] ?? 0);
4344
+ const status = Number(row[yField] ?? 0);
4345
+ const group = colorField ? String(row[colorField] ?? "default") : "default";
4346
+ if (!groups.has(group))
4347
+ groups.set(group, []);
4348
+ groups.get(group).push({ time, status });
4349
+ }
4350
+ const colors = [
4351
+ { r: 31, g: 119, b: 180, a: 1 },
4352
+ { r: 255, g: 127, b: 14, a: 1 },
4353
+ { r: 44, g: 160, b: 44, a: 1 },
4354
+ { r: 214, g: 39, b: 40, a: 1 },
4355
+ { r: 148, g: 103, b: 189, a: 1 }
4356
+ ];
4357
+ const plotLeft = Math.round(scales.x.range[0]);
4358
+ const plotRight = Math.round(scales.x.range[1]);
4359
+ const plotTop = Math.round(scales.y.range[1]);
4360
+ const plotBottom = Math.round(scales.y.range[0]);
4361
+ let maxTime = 0;
4362
+ for (const [, events] of groups) {
4363
+ for (const e of events) {
4364
+ if (e.time > maxTime)
4365
+ maxTime = e.time;
4366
+ }
4367
+ }
4368
+ const mapX = (t) => plotLeft + t / maxTime * (plotRight - plotLeft);
4369
+ const mapY = (s) => plotBottom - s * (plotBottom - plotTop);
4370
+ let colorIndex = 0;
4371
+ for (const [, events] of groups) {
4372
+ const color = colors[colorIndex % colors.length];
4373
+ colorIndex++;
4374
+ events.sort((a, b) => a.time - b.time);
4375
+ const n = events.length;
4376
+ let survival = 1;
4377
+ let atRisk = n;
4378
+ const survivalCurve = [];
4379
+ survivalCurve.push({ time: 0, survival: 1, censored: false });
4380
+ for (const event of events) {
4381
+ if (event.status === 1) {
4382
+ survival *= (atRisk - 1) / atRisk;
4383
+ survivalCurve.push({ time: event.time, survival, censored: false });
4384
+ } else {
4385
+ survivalCurve.push({ time: event.time, survival, censored: true });
4386
+ }
4387
+ atRisk--;
4388
+ }
4389
+ for (let i = 0;i < survivalCurve.length; i++) {
4390
+ const point = survivalCurve[i];
4391
+ const x = Math.round(mapX(point.time));
4392
+ const y = Math.round(mapY(point.survival));
4393
+ if (i > 0) {
4394
+ const prevPoint = survivalCurve[i - 1];
4395
+ const px = Math.round(mapX(prevPoint.time));
4396
+ const py = Math.round(mapY(prevPoint.survival));
4397
+ for (let hx = px;hx <= x; hx++) {
4398
+ canvas.drawChar(hx, py, "─", color);
4399
+ }
4400
+ if (py !== y) {
4401
+ for (let vy = Math.min(py, y);vy <= Math.max(py, y); vy++) {
4402
+ canvas.drawChar(x, vy, "│", color);
4403
+ }
4404
+ }
4405
+ }
4406
+ if (point.censored && showCensored) {
4407
+ canvas.drawChar(x, y, censorChar, color);
4408
+ }
4409
+ }
4410
+ if (showMedian) {
4411
+ const medianY = mapY(0.5);
4412
+ for (let mx = plotLeft;mx <= plotRight; mx += 2) {
4413
+ canvas.drawChar(mx, Math.round(medianY), "·", { r: 150, g: 150, b: 150, a: 1 });
4414
+ }
4415
+ }
4416
+ }
4417
+ }
4418
+ function renderGeomForest(data, geom, aes, scales, canvas) {
4419
+ const params = geom.params || {};
4420
+ const nullLine = Number(params.null_line ?? 1);
4421
+ const logScale = Boolean(params.log_scale ?? false);
4422
+ const nullLineColor = String(params.null_line_color ?? "#888888");
4423
+ const pointChar = String(params.point_char ?? "■");
4424
+ if (!Array.isArray(data) || data.length === 0)
4425
+ return;
4426
+ const parseHex = (hex) => {
4427
+ const r = parseInt(hex.slice(1, 3), 16);
4428
+ const g = parseInt(hex.slice(3, 5), 16);
4429
+ const b = parseInt(hex.slice(5, 7), 16);
4430
+ return { r, g, b, a: 1 };
4431
+ };
4432
+ const nullColor = parseHex(nullLineColor);
4433
+ const xField = typeof aes.x === "string" ? aes.x : "estimate";
4434
+ const yField = typeof aes.y === "string" ? aes.y : "study";
4435
+ const xminField = typeof aes.xmin === "string" ? aes.xmin : "ci_lower";
4436
+ const xmaxField = typeof aes.xmax === "string" ? aes.xmax : "ci_upper";
4437
+ const sizeField = typeof aes.size === "string" ? aes.size : undefined;
4438
+ const rows = [];
4439
+ let minWeight = Infinity;
4440
+ let maxWeight = -Infinity;
4441
+ for (const row of data) {
4442
+ const estimate = Number(row[xField] ?? 0);
4443
+ const ci_lower = Number(row[xminField] ?? estimate);
4444
+ const ci_upper = Number(row[xmaxField] ?? estimate);
4445
+ const study = String(row[yField] ?? "");
4446
+ const weight = sizeField ? Number(row[sizeField] ?? 1) : 1;
4447
+ if (weight < minWeight)
4448
+ minWeight = weight;
4449
+ if (weight > maxWeight)
4450
+ maxWeight = weight;
4451
+ rows.push({ study, estimate, ci_lower, ci_upper, weight });
4452
+ }
4453
+ const plotLeft = Math.round(scales.x.range[0]);
4454
+ const plotRight = Math.round(scales.x.range[1]);
4455
+ const plotTop = Math.round(scales.y.range[1]);
4456
+ const plotBottom = Math.round(scales.y.range[0]);
4457
+ let xMin = Math.min(...rows.map((r) => r.ci_lower), nullLine);
4458
+ let xMax = Math.max(...rows.map((r) => r.ci_upper), nullLine);
4459
+ if (logScale) {
4460
+ xMin = Math.log10(Math.max(xMin, 0.001));
4461
+ xMax = Math.log10(Math.max(xMax, 0.001));
4462
+ }
4463
+ const mapX = (v) => {
4464
+ const val = logScale ? Math.log10(Math.max(v, 0.001)) : v;
4465
+ return plotLeft + (val - xMin) / (xMax - xMin) * (plotRight - plotLeft);
4466
+ };
4467
+ const nullX = Math.round(mapX(nullLine));
4468
+ for (let y = plotTop;y <= plotBottom; y++) {
4469
+ if ((y - plotTop) % 2 === 0) {
4470
+ canvas.drawChar(nullX, y, "│", nullColor);
4471
+ }
4472
+ }
4473
+ const rowHeight = (plotBottom - plotTop) / rows.length;
4474
+ const pointColor = { r: 31, g: 119, b: 180, a: 1 };
4475
+ const ciColor = { r: 80, g: 80, b: 80, a: 1 };
4476
+ for (let i = 0;i < rows.length; i++) {
4477
+ const row = rows[i];
4478
+ const y = Math.round(plotTop + (i + 0.5) * rowHeight);
4479
+ const x1 = Math.round(mapX(row.ci_lower));
4480
+ const x2 = Math.round(mapX(row.ci_upper));
4481
+ for (let x = x1;x <= x2; x++) {
4482
+ canvas.drawChar(x, y, "─", ciColor);
4483
+ }
4484
+ canvas.drawChar(x1, y, "├", ciColor);
4485
+ canvas.drawChar(x2, y, "┤", ciColor);
4486
+ const px = Math.round(mapX(row.estimate));
4487
+ canvas.drawChar(px, y, pointChar, pointColor);
4488
+ }
4489
+ }
4490
+ function renderGeomRoc(data, geom, aes, scales, canvas) {
4491
+ const params = geom.params || {};
4492
+ const showDiagonal = Boolean(params.show_diagonal ?? true);
4493
+ const diagonalColor = String(params.diagonal_color ?? "#888888");
4494
+ const showAuc = Boolean(params.show_auc ?? true);
4495
+ const showOptimal = Boolean(params.show_optimal ?? false);
4496
+ const optimalChar = String(params.optimal_char ?? "●");
4497
+ if (!Array.isArray(data) || data.length === 0)
4498
+ return;
4499
+ const parseHex = (hex) => {
4500
+ const r = parseInt(hex.slice(1, 3), 16);
4501
+ const g = parseInt(hex.slice(3, 5), 16);
4502
+ const b = parseInt(hex.slice(5, 7), 16);
4503
+ return { r, g, b, a: 1 };
4504
+ };
4505
+ const diagColor = parseHex(diagonalColor);
4506
+ const xField = typeof aes.x === "string" ? aes.x : "fpr";
4507
+ const yField = typeof aes.y === "string" ? aes.y : "tpr";
4508
+ const colorField = typeof aes.color === "string" ? aes.color : undefined;
4509
+ const groups = new Map;
4510
+ for (const row of data) {
4511
+ const fpr = Number(row[xField] ?? 0);
4512
+ const tpr = Number(row[yField] ?? 0);
4513
+ const group = colorField ? String(row[colorField] ?? "default") : "default";
4514
+ if (!groups.has(group))
4515
+ groups.set(group, []);
4516
+ groups.get(group).push({ fpr, tpr });
4517
+ }
4518
+ const plotLeft = Math.round(scales.x.range[0]);
4519
+ const plotRight = Math.round(scales.x.range[1]);
4520
+ const plotTop = Math.round(scales.y.range[1]);
4521
+ const plotBottom = Math.round(scales.y.range[0]);
4522
+ const mapX = (v) => plotLeft + v * (plotRight - plotLeft);
4523
+ const mapY = (v) => plotBottom - v * (plotBottom - plotTop);
4524
+ if (showDiagonal) {
4525
+ const steps = plotRight - plotLeft;
4526
+ for (let i = 0;i <= steps; i += 2) {
4527
+ const t = i / steps;
4528
+ const x = Math.round(mapX(t));
4529
+ const y = Math.round(mapY(t));
4530
+ canvas.drawChar(x, y, "·", diagColor);
4531
+ }
4532
+ }
4533
+ const colors = [
4534
+ { r: 31, g: 119, b: 180, a: 1 },
4535
+ { r: 255, g: 127, b: 14, a: 1 },
4536
+ { r: 44, g: 160, b: 44, a: 1 },
4537
+ { r: 214, g: 39, b: 40, a: 1 }
4538
+ ];
4539
+ let colorIndex = 0;
4540
+ for (const [, points] of groups) {
4541
+ const color = colors[colorIndex % colors.length];
4542
+ colorIndex++;
4543
+ points.sort((a, b) => a.fpr - b.fpr);
4544
+ let auc = 0;
4545
+ for (let i = 1;i < points.length; i++) {
4546
+ const dx = points[i].fpr - points[i - 1].fpr;
4547
+ const avgY = (points[i].tpr + points[i - 1].tpr) / 2;
4548
+ auc += dx * avgY;
4549
+ }
4550
+ let optimalPoint = points[0];
4551
+ let maxJ = -Infinity;
4552
+ for (const p of points) {
4553
+ const j = p.tpr - p.fpr;
4554
+ if (j > maxJ) {
4555
+ maxJ = j;
4556
+ optimalPoint = p;
4557
+ }
4558
+ }
4559
+ for (let i = 0;i < points.length; i++) {
4560
+ const p = points[i];
4561
+ const x = Math.round(mapX(p.fpr));
4562
+ const y = Math.round(mapY(p.tpr));
4563
+ if (i > 0) {
4564
+ const prev = points[i - 1];
4565
+ const px = Math.round(mapX(prev.fpr));
4566
+ const py = Math.round(mapY(prev.tpr));
4567
+ const steps = Math.max(Math.abs(x - px), Math.abs(y - py));
4568
+ for (let s = 0;s <= steps; s++) {
4569
+ const t = steps > 0 ? s / steps : 0;
4570
+ const lx = Math.round(px + (x - px) * t);
4571
+ const ly = Math.round(py + (y - py) * t);
4572
+ canvas.drawChar(lx, ly, "─", color);
4573
+ }
4574
+ }
4575
+ canvas.drawChar(x, y, "●", color);
4576
+ }
4577
+ if (showOptimal) {
4578
+ const ox = Math.round(mapX(optimalPoint.fpr));
4579
+ const oy = Math.round(mapY(optimalPoint.tpr));
4580
+ canvas.drawChar(ox, oy, optimalChar, { r: 255, g: 0, b: 0, a: 1 });
4581
+ }
4582
+ if (showAuc && colorIndex === 1) {
4583
+ const aucText = `AUC=${auc.toFixed(3)}`;
4584
+ const labelColor = { r: 100, g: 100, b: 100, a: 1 };
4585
+ for (let i = 0;i < aucText.length; i++) {
4586
+ canvas.drawChar(plotRight - aucText.length + i, plotTop + 1, aucText[i], labelColor);
4587
+ }
4588
+ }
4589
+ }
4590
+ }
4591
+ function renderGeomBlandAltman(data, geom, aes, scales, canvas) {
4592
+ const params = geom.params || {};
4593
+ const showLimits = Boolean(params.show_limits ?? true);
4594
+ const showBias = Boolean(params.show_bias ?? true);
4595
+ const limitMultiplier = Number(params.limit_multiplier ?? 1.96);
4596
+ const biasColor = String(params.bias_color ?? "#0000ff");
4597
+ const limitColor = String(params.limit_color ?? "#ff0000");
4598
+ const pointChar = String(params.point_char ?? "●");
4599
+ const precomputed = Boolean(params.precomputed ?? false);
4600
+ if (!Array.isArray(data) || data.length === 0)
4601
+ return;
4602
+ const parseHex = (hex) => {
4603
+ const r = parseInt(hex.slice(1, 3), 16);
4604
+ const g = parseInt(hex.slice(3, 5), 16);
4605
+ const b = parseInt(hex.slice(5, 7), 16);
4606
+ return { r, g, b, a: 1 };
4607
+ };
4608
+ const biasColorParsed = parseHex(biasColor);
4609
+ const limitColorParsed = parseHex(limitColor);
4610
+ const xField = typeof aes.x === "string" ? aes.x : "method1";
4611
+ const yField = typeof aes.y === "string" ? aes.y : "method2";
4612
+ const points = [];
4613
+ if (precomputed) {
4614
+ for (const row of data) {
4615
+ const mean = Number(row[xField] ?? 0);
4616
+ const diff = Number(row[yField] ?? 0);
4617
+ points.push({ mean, diff });
4618
+ }
4619
+ } else {
4620
+ for (const row of data) {
4621
+ const m1 = Number(row[xField] ?? 0);
4622
+ const m2 = Number(row[yField] ?? 0);
4623
+ const mean = (m1 + m2) / 2;
4624
+ const diff = m1 - m2;
4625
+ points.push({ mean, diff });
4626
+ }
4627
+ }
4628
+ if (points.length === 0)
4629
+ return;
4630
+ const diffs = points.map((p) => p.diff);
4631
+ const bias = diffs.reduce((a, b) => a + b, 0) / diffs.length;
4632
+ const variance = diffs.reduce((a, b) => a + Math.pow(b - bias, 2), 0) / (diffs.length - 1);
4633
+ const sd = Math.sqrt(variance);
4634
+ const upperLimit = bias + limitMultiplier * sd;
4635
+ const lowerLimit = bias - limitMultiplier * sd;
4636
+ const plotLeft = Math.round(scales.x.range[0]);
4637
+ const plotRight = Math.round(scales.x.range[1]);
4638
+ const plotTop = Math.round(scales.y.range[1]);
4639
+ const plotBottom = Math.round(scales.y.range[0]);
4640
+ const minMean = Math.min(...points.map((p) => p.mean));
4641
+ const maxMean = Math.max(...points.map((p) => p.mean));
4642
+ const minDiff = Math.min(...points.map((p) => p.diff), lowerLimit);
4643
+ const maxDiff = Math.max(...points.map((p) => p.diff), upperLimit);
4644
+ const mapX = (v) => plotLeft + (v - minMean) / (maxMean - minMean) * (plotRight - plotLeft);
4645
+ const mapY = (v) => plotBottom - (v - minDiff) / (maxDiff - minDiff) * (plotBottom - plotTop);
4646
+ if (showBias) {
4647
+ const biasY = Math.round(mapY(bias));
4648
+ for (let x = plotLeft;x <= plotRight; x++) {
4649
+ canvas.drawChar(x, biasY, "─", biasColorParsed);
4650
+ }
4651
+ }
4652
+ if (showLimits) {
4653
+ const upperY = Math.round(mapY(upperLimit));
4654
+ const lowerY = Math.round(mapY(lowerLimit));
4655
+ for (let x = plotLeft;x <= plotRight; x += 2) {
4656
+ canvas.drawChar(x, upperY, "─", limitColorParsed);
4657
+ canvas.drawChar(x, lowerY, "─", limitColorParsed);
4658
+ }
4659
+ }
4660
+ const pointColor = { r: 31, g: 119, b: 180, a: 1 };
4661
+ for (const p of points) {
4662
+ const x = Math.round(mapX(p.mean));
4663
+ const y = Math.round(mapY(p.diff));
4664
+ canvas.drawChar(x, y, pointChar, pointColor);
4665
+ }
4666
+ }
4667
+ function renderGeomQQ(data, geom, aes, scales, canvas) {
4668
+ const params = geom.params || {};
4669
+ const showLine = params.show_line ?? true;
4670
+ const lineColor = params.line_color ?? "#ff0000";
4671
+ const pointChar = params.point_char ?? "●";
4672
+ const standardize = params.standardize ?? true;
4673
+ const parseHex = (hex) => {
4674
+ const r = parseInt(hex.slice(1, 3), 16);
4675
+ const g = parseInt(hex.slice(3, 5), 16);
4676
+ const b = parseInt(hex.slice(5, 7), 16);
4677
+ return { r, g, b, a: 1 };
4678
+ };
4679
+ const lineColorParsed = parseHex(lineColor);
4680
+ const sampleField = typeof aes.x === "string" ? aes.x : "x";
4681
+ const values = [];
4682
+ for (const row of data) {
4683
+ const v = Number(row[sampleField]);
4684
+ if (!isNaN(v))
4685
+ values.push(v);
4686
+ }
4687
+ if (values.length === 0)
4688
+ return;
4689
+ values.sort((a, b) => a - b);
4690
+ const n = values.length;
4691
+ const mean = values.reduce((a, b) => a + b, 0) / n;
4692
+ const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / (n - 1);
4693
+ const sd = Math.sqrt(variance);
4694
+ const qnorm = (p) => {
4695
+ if (p <= 0)
4696
+ return -Infinity;
4697
+ if (p >= 1)
4698
+ return Infinity;
4699
+ if (p === 0.5)
4700
+ return 0;
4701
+ const a = [
4702
+ -39.69683028665376,
4703
+ 220.9460984245205,
4704
+ -275.9285104469687,
4705
+ 138.357751867269,
4706
+ -30.66479806614716,
4707
+ 2.506628277459239
4708
+ ];
4709
+ const b = [
4710
+ -54.47609879822406,
4711
+ 161.5858368580409,
4712
+ -155.6989798598866,
4713
+ 66.80131188771972,
4714
+ -13.28068155288572
4715
+ ];
4716
+ const c = [
4717
+ -0.007784894002430293,
4718
+ -0.3223964580411365,
4719
+ -2.400758277161838,
4720
+ -2.549732539343734,
4721
+ 4.374664141464968,
4722
+ 2.938163982698783
4723
+ ];
4724
+ const d = [
4725
+ 0.007784695709041462,
4726
+ 0.3224671290700398,
4727
+ 2.445134137142996,
4728
+ 3.754408661907416
4729
+ ];
4730
+ const pLow = 0.02425;
4731
+ const pHigh = 1 - pLow;
4732
+ let q;
4733
+ if (p < pLow) {
4734
+ q = Math.sqrt(-2 * Math.log(p));
4735
+ return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
4736
+ } else if (p <= pHigh) {
4737
+ q = p - 0.5;
4738
+ const r = q * q;
4739
+ return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) * q / (((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1);
4740
+ } else {
4741
+ q = Math.sqrt(-2 * Math.log(1 - p));
4742
+ return -(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
4743
+ }
4744
+ };
4745
+ const points = [];
4746
+ for (let i = 0;i < n; i++) {
4747
+ const p = (i + 0.5) / n;
4748
+ const theoretical = qnorm(p);
4749
+ const sample = standardize ? (values[i] - mean) / sd : values[i];
4750
+ points.push({ theoretical, sample });
4751
+ }
4752
+ const plotLeft = Math.round(scales.x.range[0]);
4753
+ const plotRight = Math.round(scales.x.range[1]);
4754
+ const plotTop = Math.round(scales.y.range[1]);
4755
+ const plotBottom = Math.round(scales.y.range[0]);
4756
+ const minT = Math.min(...points.map((p) => p.theoretical));
4757
+ const maxT = Math.max(...points.map((p) => p.theoretical));
4758
+ const minS = Math.min(...points.map((p) => p.sample));
4759
+ const maxS = Math.max(...points.map((p) => p.sample));
4760
+ const minVal = Math.min(minT, minS);
4761
+ const maxVal = Math.max(maxT, maxS);
4762
+ const mapX = (v) => plotLeft + (v - minVal) / (maxVal - minVal) * (plotRight - plotLeft);
4763
+ const mapY = (v) => plotBottom - (v - minVal) / (maxVal - minVal) * (plotBottom - plotTop);
4764
+ if (showLine) {
4765
+ const steps = plotRight - plotLeft;
4766
+ for (let i = 0;i <= steps; i++) {
4767
+ const v = minVal + i / steps * (maxVal - minVal);
4768
+ const x = Math.round(mapX(v));
4769
+ const y = Math.round(mapY(v));
4770
+ if (y >= plotTop && y <= plotBottom) {
4771
+ canvas.drawChar(x, y, "─", lineColorParsed);
4772
+ }
4773
+ }
4774
+ }
4775
+ const pointColor = { r: 31, g: 119, b: 180, a: 1 };
4776
+ for (const p of points) {
4777
+ const x = Math.round(mapX(p.theoretical));
4778
+ const y = Math.round(mapY(p.sample));
4779
+ canvas.drawChar(x, y, pointChar, pointColor);
4780
+ }
4781
+ }
4782
+ function renderGeomECDF(data, geom, aes, scales, canvas) {
4783
+ const params = geom.params || {};
4784
+ const complement = params.complement ?? false;
4785
+ const showPoints = params.show_points ?? false;
4786
+ const xField = typeof aes.x === "string" ? aes.x : "x";
4787
+ const colorField = typeof aes.color === "string" ? aes.color : null;
4788
+ const groups = new Map;
4789
+ for (const row of data) {
4790
+ const v = Number(row[xField]);
4791
+ if (isNaN(v))
4792
+ continue;
4793
+ const groupKey = colorField ? String(row[colorField] ?? "default") : "default";
4794
+ if (!groups.has(groupKey))
4795
+ groups.set(groupKey, []);
4796
+ groups.get(groupKey).push(v);
4797
+ }
4798
+ if (groups.size === 0)
4799
+ return;
4800
+ const plotLeft = Math.round(scales.x.range[0]);
4801
+ const plotRight = Math.round(scales.x.range[1]);
4802
+ const plotTop = Math.round(scales.y.range[1]);
4803
+ const plotBottom = Math.round(scales.y.range[0]);
4804
+ let globalMin = Infinity;
4805
+ let globalMax = -Infinity;
4806
+ for (const values of groups.values()) {
4807
+ globalMin = Math.min(globalMin, ...values);
4808
+ globalMax = Math.max(globalMax, ...values);
4809
+ }
4810
+ const mapX = (v) => plotLeft + (v - globalMin) / (globalMax - globalMin) * (plotRight - plotLeft);
4811
+ const mapY = (v) => {
4812
+ const ecdf = complement ? 1 - v : v;
4813
+ return plotBottom - ecdf * (plotBottom - plotTop);
4814
+ };
4815
+ const colors = [
4816
+ { r: 31, g: 119, b: 180, a: 1 },
4817
+ { r: 255, g: 127, b: 14, a: 1 },
4818
+ { r: 44, g: 160, b: 44, a: 1 },
4819
+ { r: 214, g: 39, b: 40, a: 1 },
4820
+ { r: 148, g: 103, b: 189, a: 1 }
4821
+ ];
4822
+ let colorIdx = 0;
4823
+ for (const [, values] of groups) {
4824
+ const color = colors[colorIdx % colors.length];
4825
+ colorIdx++;
4826
+ const sorted = [...values].sort((a, b) => a - b);
4827
+ const n = sorted.length;
4828
+ let prevX = plotLeft;
4829
+ let prevY = Math.round(mapY(0));
4830
+ for (let i = 0;i < n; i++) {
4831
+ const ecdfVal = (i + 1) / n;
4832
+ const x = Math.round(mapX(sorted[i]));
4833
+ const y = Math.round(mapY(ecdfVal));
4834
+ for (let px = prevX;px <= x; px++) {
4835
+ canvas.drawChar(px, prevY, "─", color);
4836
+ }
4837
+ const stepDir = y < prevY ? -1 : 1;
4838
+ for (let py = prevY;stepDir > 0 ? py <= y : py >= y; py += stepDir) {
4839
+ canvas.drawChar(x, py, "│", color);
4840
+ }
4841
+ if (showPoints) {
4842
+ canvas.drawChar(x, y, "●", color);
4843
+ }
4844
+ prevX = x;
4845
+ prevY = y;
4846
+ }
4847
+ for (let px = prevX;px <= plotRight; px++) {
4848
+ canvas.drawChar(px, prevY, "─", color);
4849
+ }
4850
+ }
4851
+ }
4852
+ function renderGeomFunnel(data, geom, aes, scales, canvas) {
4853
+ const params = geom.params || {};
4854
+ const showContours = params.show_contours ?? true;
4855
+ const showSummaryLine = params.show_summary_line ?? true;
4856
+ const summaryEffect = params.summary_effect;
4857
+ const pointChar = params.point_char ?? "●";
4858
+ const contourColor = params.contour_color ?? "#888888";
4859
+ const invertY = params.invert_y ?? true;
4860
+ const parseHex = (hex) => {
4861
+ const r = parseInt(hex.slice(1, 3), 16);
4862
+ const g = parseInt(hex.slice(3, 5), 16);
4863
+ const b = parseInt(hex.slice(5, 7), 16);
4864
+ return { r, g, b, a: 1 };
4865
+ };
4866
+ const contourColorParsed = parseHex(contourColor);
4867
+ const xField = typeof aes.x === "string" ? aes.x : "effect";
4868
+ const yField = typeof aes.y === "string" ? aes.y : "se";
4869
+ const points = [];
4870
+ for (const row of data) {
4871
+ const effect = Number(row[xField]);
4872
+ const se = Number(row[yField]);
4873
+ if (!isNaN(effect) && !isNaN(se)) {
4874
+ points.push({ effect, se });
4875
+ }
4876
+ }
4877
+ if (points.length === 0)
4878
+ return;
4879
+ const summary = summaryEffect ?? points.reduce((a, b) => a + b.effect, 0) / points.length;
4880
+ const plotLeft = Math.round(scales.x.range[0]);
4881
+ const plotRight = Math.round(scales.x.range[1]);
4882
+ const plotTop = Math.round(scales.y.range[1]);
4883
+ const plotBottom = Math.round(scales.y.range[0]);
4884
+ const minEffect = Math.min(...points.map((p) => p.effect));
4885
+ const maxEffect = Math.max(...points.map((p) => p.effect));
4886
+ const maxSE = Math.max(...points.map((p) => p.se));
4887
+ const effectPad = (maxEffect - minEffect) * 0.2;
4888
+ const effectMin = minEffect - effectPad;
4889
+ const effectMax = maxEffect + effectPad;
4890
+ const mapX = (v) => plotLeft + (v - effectMin) / (effectMax - effectMin) * (plotRight - plotLeft);
4891
+ const mapY = (v) => {
4892
+ if (invertY) {
4893
+ return plotTop + v / maxSE * (plotBottom - plotTop);
4894
+ }
4895
+ return plotBottom - v / maxSE * (plotBottom - plotTop);
4896
+ };
4897
+ if (showContours) {
4898
+ const z = 1.96;
4899
+ for (let se = 0;se <= maxSE; se += maxSE / 40) {
4900
+ const leftBound = summary - z * se;
4901
+ const rightBound = summary + z * se;
4902
+ const y = Math.round(mapY(se));
4903
+ const leftX = Math.round(mapX(leftBound));
4904
+ const rightX = Math.round(mapX(rightBound));
4905
+ if (leftX >= plotLeft && leftX <= plotRight) {
4906
+ canvas.drawChar(leftX, y, "·", contourColorParsed);
4907
+ }
4908
+ if (rightX >= plotLeft && rightX <= plotRight) {
4909
+ canvas.drawChar(rightX, y, "·", contourColorParsed);
4910
+ }
4911
+ }
4912
+ }
4913
+ if (showSummaryLine) {
4914
+ const summaryX = Math.round(mapX(summary));
4915
+ for (let y = plotTop;y <= plotBottom; y += 2) {
4916
+ canvas.drawChar(summaryX, y, "│", contourColorParsed);
4917
+ }
4918
+ }
4919
+ const pointColor = { r: 31, g: 119, b: 180, a: 1 };
4920
+ for (const p of points) {
4921
+ const x = Math.round(mapX(p.effect));
4922
+ const y = Math.round(mapY(p.se));
4923
+ canvas.drawChar(x, y, pointChar, pointColor);
4924
+ }
4925
+ }
4926
+ function renderGeomControl(data, geom, aes, scales, canvas) {
4927
+ const params = geom.params || {};
4928
+ const sigma = params.sigma ?? 3;
4929
+ const showCenter = params.show_center ?? true;
4930
+ const showUCL = params.show_ucl ?? true;
4931
+ const showLCL = params.show_lcl ?? true;
4932
+ const showWarning = params.show_warning ?? false;
4933
+ const customCenter = params.center;
4934
+ const customUCL = params.ucl;
4935
+ const customLCL = params.lcl;
4936
+ const centerColor = params.center_color ?? "#0000ff";
4937
+ const limitColor = params.limit_color ?? "#ff0000";
4938
+ const warningColor = params.warning_color ?? "#ffa500";
4939
+ const connectPoints = params.connect_points ?? true;
4940
+ const highlightOOC = params.highlight_ooc ?? true;
4941
+ const oocChar = params.ooc_char ?? "◆";
4942
+ const pointChar = params.point_char ?? "●";
4943
+ const parseHex = (hex) => {
4944
+ const r = parseInt(hex.slice(1, 3), 16);
4945
+ const g = parseInt(hex.slice(3, 5), 16);
4946
+ const b = parseInt(hex.slice(5, 7), 16);
4947
+ return { r, g, b, a: 1 };
4948
+ };
4949
+ const centerColorParsed = parseHex(centerColor);
4950
+ const limitColorParsed = parseHex(limitColor);
4951
+ const warningColorParsed = parseHex(warningColor);
4952
+ const xField = typeof aes.x === "string" ? aes.x : "x";
4953
+ const yField = typeof aes.y === "string" ? aes.y : "y";
4954
+ const points = [];
4955
+ for (const row of data) {
4956
+ const x = Number(row[xField]);
4957
+ const y = Number(row[yField]);
4958
+ if (!isNaN(x) && !isNaN(y)) {
4959
+ points.push({ x, y });
4960
+ }
4961
+ }
4962
+ if (points.length === 0)
4963
+ return;
4964
+ points.sort((a, b) => a.x - b.x);
4965
+ const yValues = points.map((p) => p.y);
4966
+ const mean = customCenter ?? yValues.reduce((a, b) => a + b, 0) / yValues.length;
4967
+ let sigmaEst;
4968
+ if (points.length > 1) {
4969
+ const movingRanges = [];
4970
+ for (let i = 1;i < points.length; i++) {
4971
+ movingRanges.push(Math.abs(points[i].y - points[i - 1].y));
4972
+ }
4973
+ const avgMR = movingRanges.reduce((a, b) => a + b, 0) / movingRanges.length;
4974
+ sigmaEst = avgMR / 1.128;
4975
+ } else {
4976
+ const variance = yValues.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / (yValues.length - 1);
4977
+ sigmaEst = Math.sqrt(variance);
4978
+ }
4979
+ const ucl = customUCL ?? mean + sigma * sigmaEst;
4980
+ const lcl = customLCL ?? mean - sigma * sigmaEst;
4981
+ const uwl = mean + 2 * sigmaEst;
4982
+ const lwl = mean - 2 * sigmaEst;
4983
+ const plotLeft = Math.round(scales.x.range[0]);
4984
+ const plotRight = Math.round(scales.x.range[1]);
4985
+ const plotTop = Math.round(scales.y.range[1]);
4986
+ const plotBottom = Math.round(scales.y.range[0]);
4987
+ const minX = Math.min(...points.map((p) => p.x));
4988
+ const maxX = Math.max(...points.map((p) => p.x));
4989
+ const minY = Math.min(...points.map((p) => p.y), lcl);
4990
+ const maxY = Math.max(...points.map((p) => p.y), ucl);
4991
+ const mapX = (v) => plotLeft + (v - minX) / (maxX - minX) * (plotRight - plotLeft);
4992
+ const mapY = (v) => plotBottom - (v - minY) / (maxY - minY) * (plotBottom - plotTop);
4993
+ if (showCenter) {
4994
+ const centerY = Math.round(mapY(mean));
4995
+ for (let x = plotLeft;x <= plotRight; x++) {
4996
+ canvas.drawChar(x, centerY, "─", centerColorParsed);
4997
+ }
4998
+ }
4999
+ if (showUCL) {
5000
+ const uclY = Math.round(mapY(ucl));
5001
+ for (let x = plotLeft;x <= plotRight; x += 2) {
5002
+ canvas.drawChar(x, uclY, "─", limitColorParsed);
5003
+ }
5004
+ }
5005
+ if (showLCL) {
5006
+ const lclY = Math.round(mapY(lcl));
5007
+ for (let x = plotLeft;x <= plotRight; x += 2) {
5008
+ canvas.drawChar(x, lclY, "─", limitColorParsed);
5009
+ }
5010
+ }
5011
+ if (showWarning) {
5012
+ const uwlY = Math.round(mapY(uwl));
5013
+ const lwlY = Math.round(mapY(lwl));
5014
+ for (let x = plotLeft;x <= plotRight; x += 3) {
5015
+ canvas.drawChar(x, uwlY, "·", warningColorParsed);
5016
+ canvas.drawChar(x, lwlY, "·", warningColorParsed);
5017
+ }
5018
+ }
5019
+ if (connectPoints && points.length > 1) {
5020
+ const lineColor = { r: 100, g: 100, b: 100, a: 1 };
5021
+ for (let i = 1;i < points.length; i++) {
5022
+ const x1 = Math.round(mapX(points[i - 1].x));
5023
+ const y1 = Math.round(mapY(points[i - 1].y));
5024
+ const x2 = Math.round(mapX(points[i].x));
5025
+ const y2 = Math.round(mapY(points[i].y));
5026
+ const dx = Math.abs(x2 - x1);
5027
+ const dy = Math.abs(y2 - y1);
5028
+ const sx = x1 < x2 ? 1 : -1;
5029
+ const sy = y1 < y2 ? 1 : -1;
5030
+ let err = dx - dy;
5031
+ let x = x1;
5032
+ let y = y1;
5033
+ while (true) {
5034
+ canvas.drawChar(x, y, "·", lineColor);
5035
+ if (x === x2 && y === y2)
5036
+ break;
5037
+ const e2 = 2 * err;
5038
+ if (e2 > -dy) {
5039
+ err -= dy;
5040
+ x += sx;
5041
+ }
5042
+ if (e2 < dx) {
5043
+ err += dx;
5044
+ y += sy;
5045
+ }
5046
+ }
5047
+ }
5048
+ }
5049
+ const inControlColor = { r: 31, g: 119, b: 180, a: 1 };
5050
+ const oocColor = { r: 214, g: 39, b: 40, a: 1 };
5051
+ for (const p of points) {
5052
+ const x = Math.round(mapX(p.x));
5053
+ const y = Math.round(mapY(p.y));
5054
+ const isOOC = p.y > ucl || p.y < lcl;
5055
+ if (highlightOOC && isOOC) {
5056
+ canvas.drawChar(x, y, oocChar, oocColor);
5057
+ } else {
5058
+ canvas.drawChar(x, y, pointChar, inControlColor);
5059
+ }
5060
+ }
5061
+ }
5062
+ function renderGeomScree(data, geom, aes, scales, canvas) {
5063
+ const params = geom.params || {};
5064
+ const showCumulative = params.show_cumulative ?? false;
5065
+ const showKaiser = params.show_kaiser ?? false;
5066
+ const connectPoints = params.connect_points ?? true;
5067
+ const showBars = params.show_bars ?? false;
5068
+ const pointChar = params.point_char ?? "●";
5069
+ const cumulativeColor = params.cumulative_color ?? "#ff0000";
5070
+ const kaiserColor = params.kaiser_color ?? "#888888";
5071
+ const threshold = params.threshold;
5072
+ const thresholdColor = params.threshold_color ?? "#00aa00";
5073
+ const parseHex = (hex) => {
5074
+ const r = parseInt(hex.slice(1, 3), 16);
5075
+ const g = parseInt(hex.slice(3, 5), 16);
5076
+ const b = parseInt(hex.slice(5, 7), 16);
5077
+ return { r, g, b, a: 1 };
5078
+ };
5079
+ const cumulativeColorParsed = parseHex(cumulativeColor);
5080
+ const kaiserColorParsed = parseHex(kaiserColor);
5081
+ const thresholdColorParsed = parseHex(thresholdColor);
5082
+ const xField = typeof aes.x === "string" ? aes.x : "component";
5083
+ const yField = typeof aes.y === "string" ? aes.y : "variance";
5084
+ const points = [];
5085
+ for (const row of data) {
5086
+ const component = Number(row[xField]);
5087
+ const variance = Number(row[yField]);
5088
+ if (!isNaN(component) && !isNaN(variance)) {
5089
+ points.push({ component, variance });
5090
+ }
5091
+ }
5092
+ if (points.length === 0)
5093
+ return;
5094
+ points.sort((a, b) => a.component - b.component);
5095
+ const total = points.reduce((a, b) => a + b.variance, 0);
5096
+ let cumSum = 0;
5097
+ const cumulativePoints = points.map((p) => {
5098
+ cumSum += p.variance;
5099
+ return { component: p.component, cumulative: cumSum / total };
5100
+ });
5101
+ const plotLeft = Math.round(scales.x.range[0]);
5102
+ const plotRight = Math.round(scales.x.range[1]);
5103
+ const plotTop = Math.round(scales.y.range[1]);
5104
+ const plotBottom = Math.round(scales.y.range[0]);
5105
+ const minX = Math.min(...points.map((p) => p.component));
5106
+ const maxX = Math.max(...points.map((p) => p.component));
5107
+ const maxY = Math.max(...points.map((p) => p.variance));
5108
+ const yMax = showCumulative ? Math.max(maxY, total) : maxY;
5109
+ const mapX = (v) => plotLeft + (v - minX) / (maxX - minX) * (plotRight - plotLeft);
5110
+ const mapY = (v) => plotBottom - v / yMax * (plotBottom - plotTop);
5111
+ const mapYCumulative = (v) => plotBottom - v * (plotBottom - plotTop);
5112
+ if (showKaiser) {
5113
+ const kaiserY = Math.round(mapY(1));
5114
+ if (kaiserY >= plotTop && kaiserY <= plotBottom) {
5115
+ for (let x = plotLeft;x <= plotRight; x += 2) {
5116
+ canvas.drawChar(x, kaiserY, "─", kaiserColorParsed);
5117
+ }
5118
+ }
5119
+ }
5120
+ if (threshold !== undefined) {
5121
+ const thresholdY = Math.round(mapYCumulative(threshold));
5122
+ for (let x = plotLeft;x <= plotRight; x += 2) {
5123
+ canvas.drawChar(x, thresholdY, "─", thresholdColorParsed);
5124
+ }
5125
+ }
5126
+ if (showBars) {
5127
+ const barColor = { r: 180, g: 180, b: 180, a: 1 };
5128
+ const barWidth = Math.max(1, Math.floor((plotRight - plotLeft) / points.length / 2));
5129
+ for (const p of points) {
5130
+ const x = Math.round(mapX(p.component));
5131
+ const y = Math.round(mapY(p.variance));
5132
+ for (let bx = x - barWidth;bx <= x + barWidth; bx++) {
5133
+ for (let by = y;by <= plotBottom; by++) {
5134
+ canvas.drawChar(bx, by, "░", barColor);
5135
+ }
5136
+ }
5137
+ }
5138
+ }
5139
+ if (connectPoints && points.length > 1) {
5140
+ const lineColor = { r: 31, g: 119, b: 180, a: 1 };
5141
+ for (let i = 1;i < points.length; i++) {
5142
+ const x1 = Math.round(mapX(points[i - 1].component));
5143
+ const y1 = Math.round(mapY(points[i - 1].variance));
5144
+ const x2 = Math.round(mapX(points[i].component));
5145
+ const y2 = Math.round(mapY(points[i].variance));
5146
+ const steps = Math.max(Math.abs(x2 - x1), 1);
5147
+ for (let s = 0;s <= steps; s++) {
5148
+ const t = s / steps;
5149
+ const x = Math.round(x1 + t * (x2 - x1));
5150
+ const y = Math.round(y1 + t * (y2 - y1));
5151
+ canvas.drawChar(x, y, "─", lineColor);
5152
+ }
5153
+ }
5154
+ }
5155
+ if (showCumulative && cumulativePoints.length > 1) {
5156
+ for (let i = 1;i < cumulativePoints.length; i++) {
5157
+ const x1 = Math.round(mapX(cumulativePoints[i - 1].component));
5158
+ const y1 = Math.round(mapYCumulative(cumulativePoints[i - 1].cumulative));
5159
+ const x2 = Math.round(mapX(cumulativePoints[i].component));
5160
+ const y2 = Math.round(mapYCumulative(cumulativePoints[i].cumulative));
5161
+ const steps = Math.max(Math.abs(x2 - x1), 1);
5162
+ for (let s = 0;s <= steps; s++) {
5163
+ const t = s / steps;
5164
+ const x = Math.round(x1 + t * (x2 - x1));
5165
+ const y = Math.round(y1 + t * (y2 - y1));
5166
+ canvas.drawChar(x, y, "─", cumulativeColorParsed);
5167
+ }
5168
+ }
5169
+ for (const p of cumulativePoints) {
5170
+ const x = Math.round(mapX(p.component));
5171
+ const y = Math.round(mapYCumulative(p.cumulative));
5172
+ canvas.drawChar(x, y, "○", cumulativeColorParsed);
5173
+ }
5174
+ }
5175
+ const pointColor = { r: 31, g: 119, b: 180, a: 1 };
5176
+ for (const p of points) {
5177
+ const x = Math.round(mapX(p.component));
5178
+ const y = Math.round(mapY(p.variance));
5179
+ canvas.drawChar(x, y, pointChar, pointColor);
5180
+ }
5181
+ }
3638
5182
  function renderGeom(data, geom, aes, scales, canvas, coordType) {
3639
5183
  switch (geom.type) {
3640
5184
  case "point":
@@ -3754,16 +5298,464 @@ function renderGeom(data, geom, aes, scales, canvas, coordType) {
3754
5298
  case "corrmat":
3755
5299
  renderGeomCorrmat(data, geom, aes, scales, canvas);
3756
5300
  break;
3757
- case "sankey":
3758
- renderGeomSankey(data, geom, aes, scales, canvas);
5301
+ case "sankey":
5302
+ renderGeomSankey(data, geom, aes, scales, canvas);
5303
+ break;
5304
+ case "treemap":
5305
+ renderGeomTreemap(data, geom, aes, scales, canvas);
5306
+ break;
5307
+ case "volcano":
5308
+ renderGeomVolcano(data, geom, aes, scales, canvas);
5309
+ break;
5310
+ case "ma":
5311
+ renderGeomMA(data, geom, aes, scales, canvas);
5312
+ break;
5313
+ case "manhattan":
5314
+ renderGeomManhattan(data, geom, aes, scales, canvas);
5315
+ break;
5316
+ case "heatmap":
5317
+ renderGeomHeatmap(data, geom, aes, scales, canvas);
5318
+ break;
5319
+ case "biplot":
5320
+ renderGeomBiplot(data, geom, aes, scales, canvas);
5321
+ break;
5322
+ case "kaplan_meier":
5323
+ renderGeomKaplanMeier(data, geom, aes, scales, canvas);
5324
+ break;
5325
+ case "forest":
5326
+ renderGeomForest(data, geom, aes, scales, canvas);
5327
+ break;
5328
+ case "roc":
5329
+ renderGeomRoc(data, geom, aes, scales, canvas);
5330
+ break;
5331
+ case "bland_altman":
5332
+ renderGeomBlandAltman(data, geom, aes, scales, canvas);
5333
+ break;
5334
+ case "qq":
5335
+ renderGeomQQ(data, geom, aes, scales, canvas);
5336
+ break;
5337
+ case "ecdf":
5338
+ renderGeomECDF(data, geom, aes, scales, canvas);
5339
+ break;
5340
+ case "funnel":
5341
+ renderGeomFunnel(data, geom, aes, scales, canvas);
5342
+ break;
5343
+ case "control":
5344
+ renderGeomControl(data, geom, aes, scales, canvas);
5345
+ break;
5346
+ case "scree":
5347
+ renderGeomScree(data, geom, aes, scales, canvas);
5348
+ break;
5349
+ case "upset":
5350
+ renderGeomUpset(data, geom, aes, scales, canvas);
3759
5351
  break;
3760
- case "treemap":
3761
- renderGeomTreemap(data, geom, aes, scales, canvas);
5352
+ case "dendrogram":
5353
+ renderGeomDendrogram(data, geom, aes, scales, canvas);
3762
5354
  break;
3763
5355
  default:
3764
5356
  break;
3765
5357
  }
3766
5358
  }
5359
+ function renderGeomUpset(data, geom, aes, scales, canvas) {
5360
+ const params = geom.params || {};
5361
+ const sets = params.sets;
5362
+ const minSize = params.min_size ?? 1;
5363
+ const maxIntersections = params.max_intersections ?? 20;
5364
+ const sortBy = params.sort_by ?? "size";
5365
+ const sortOrder = params.sort_order ?? "desc";
5366
+ const showSetSizes = params.show_set_sizes ?? true;
5367
+ const dotChar = params.dot_char ?? "●";
5368
+ const emptyChar = params.empty_char ?? "○";
5369
+ const lineChar = params.line_char ?? "│";
5370
+ const barChar = params.bar_char ?? "█";
5371
+ let setNames = [];
5372
+ if (sets && sets.length > 0) {
5373
+ setNames = sets;
5374
+ } else if (data.length > 0) {
5375
+ const firstRow = data[0];
5376
+ for (const key of Object.keys(firstRow)) {
5377
+ const values = data.map((row) => row[key]);
5378
+ const isBinary = values.every((v) => v === 0 || v === 1 || v === "0" || v === "1");
5379
+ if (isBinary && key !== "id" && key !== "name" && key !== "element") {
5380
+ setNames.push(key);
5381
+ }
5382
+ }
5383
+ if (setNames.length === 0) {
5384
+ const setsField2 = typeof aes.x === "string" ? aes.x : "sets";
5385
+ const allSets = new Set;
5386
+ for (const row of data) {
5387
+ const val = row[setsField2];
5388
+ if (typeof val === "string") {
5389
+ val.split(",").forEach((s) => allSets.add(s.trim()));
5390
+ }
5391
+ }
5392
+ setNames = Array.from(allSets).sort();
5393
+ }
5394
+ }
5395
+ if (setNames.length === 0)
5396
+ return;
5397
+ const intersectionMap = new Map;
5398
+ const setsField = typeof aes.x === "string" ? aes.x : "sets";
5399
+ const hasListFormat = data.length > 0 && typeof data[0][setsField] === "string";
5400
+ for (const row of data) {
5401
+ let memberSets;
5402
+ if (hasListFormat) {
5403
+ const val = row[setsField];
5404
+ memberSets = typeof val === "string" ? val.split(",").map((s) => s.trim()).filter((s) => setNames.includes(s)) : [];
5405
+ } else {
5406
+ memberSets = setNames.filter((s) => {
5407
+ const v = row[s];
5408
+ return v === 1 || v === "1";
5409
+ });
5410
+ }
5411
+ if (memberSets.length > 0) {
5412
+ const key = memberSets.sort().join("|");
5413
+ intersectionMap.set(key, (intersectionMap.get(key) || 0) + 1);
5414
+ }
5415
+ }
5416
+ let intersections = Array.from(intersectionMap.entries()).map(([key, count]) => ({
5417
+ sets: new Set(key.split("|")),
5418
+ count,
5419
+ key
5420
+ })).filter((i) => i.count >= minSize);
5421
+ if (sortBy === "size") {
5422
+ intersections.sort((a, b) => sortOrder === "desc" ? b.count - a.count : a.count - b.count);
5423
+ } else if (sortBy === "degree") {
5424
+ intersections.sort((a, b) => sortOrder === "desc" ? b.sets.size - a.sets.size : a.sets.size - b.sets.size);
5425
+ }
5426
+ intersections = intersections.slice(0, maxIntersections);
5427
+ if (intersections.length === 0)
5428
+ return;
5429
+ const plotLeft = Math.round(scales.x.range[0]);
5430
+ const plotRight = Math.round(scales.x.range[1]);
5431
+ const plotTop = Math.round(scales.y.range[1]);
5432
+ const plotBottom = Math.round(scales.y.range[0]);
5433
+ const plotWidth = plotRight - plotLeft;
5434
+ const plotHeight = plotBottom - plotTop;
5435
+ const matrixHeight = Math.min(setNames.length * 2 + 2, Math.floor(plotHeight * 0.4));
5436
+ const barHeight = plotHeight - matrixHeight - 2;
5437
+ const barTop = plotTop;
5438
+ const barBottom = plotTop + barHeight;
5439
+ const matrixTop = barBottom + 2;
5440
+ const setLabelWidth = showSetSizes ? Math.max(...setNames.map((s) => s.length)) + 8 : 0;
5441
+ const colWidth = Math.max(2, Math.floor((plotWidth - setLabelWidth) / intersections.length));
5442
+ const maxCount = Math.max(...intersections.map((i) => i.count));
5443
+ const barColor = { r: 31, g: 119, b: 180, a: 1 };
5444
+ const dotColor = { r: 50, g: 50, b: 50, a: 1 };
5445
+ const lineColor = { r: 100, g: 100, b: 100, a: 1 };
5446
+ const labelColor = { r: 150, g: 150, b: 150, a: 1 };
5447
+ for (let i = 0;i < intersections.length; i++) {
5448
+ const inter = intersections[i];
5449
+ const x = plotLeft + setLabelWidth + i * colWidth + Math.floor(colWidth / 2);
5450
+ const barHeightPx = Math.round(inter.count / maxCount * barHeight);
5451
+ for (let y = barBottom - barHeightPx;y <= barBottom; y++) {
5452
+ canvas.drawChar(x, y, barChar, barColor);
5453
+ }
5454
+ const countStr = inter.count.toString();
5455
+ const labelY = barBottom - barHeightPx - 1;
5456
+ if (labelY >= barTop) {
5457
+ for (let ci = 0;ci < countStr.length; ci++) {
5458
+ canvas.drawChar(x - Math.floor(countStr.length / 2) + ci, labelY, countStr[ci], labelColor);
5459
+ }
5460
+ }
5461
+ }
5462
+ const rowSpacing = Math.max(1, Math.floor(matrixHeight / setNames.length));
5463
+ if (showSetSizes) {
5464
+ for (let si = 0;si < setNames.length; si++) {
5465
+ const setName = setNames[si];
5466
+ const y = matrixTop + si * rowSpacing + 1;
5467
+ let setSize = 0;
5468
+ for (const row of data) {
5469
+ if (hasListFormat) {
5470
+ const val = row[setsField];
5471
+ if (typeof val === "string" && val.split(",").map((s) => s.trim()).includes(setName)) {
5472
+ setSize++;
5473
+ }
5474
+ } else {
5475
+ const v = row[setName];
5476
+ if (v === 1 || v === "1")
5477
+ setSize++;
5478
+ }
5479
+ }
5480
+ const label = `${setName.substring(0, 6)}`;
5481
+ for (let ci = 0;ci < label.length; ci++) {
5482
+ canvas.drawChar(plotLeft + ci, y, label[ci], labelColor);
5483
+ }
5484
+ const sizeBarLen = Math.max(1, Math.round(setSize / data.length * 5));
5485
+ for (let bi = 0;bi < sizeBarLen; bi++) {
5486
+ canvas.drawChar(plotLeft + label.length + 1 + bi, y, "▪", barColor);
5487
+ }
5488
+ }
5489
+ }
5490
+ for (let i = 0;i < intersections.length; i++) {
5491
+ const inter = intersections[i];
5492
+ const x = plotLeft + setLabelWidth + i * colWidth + Math.floor(colWidth / 2);
5493
+ const activeRows = [];
5494
+ for (let si = 0;si < setNames.length; si++) {
5495
+ const setName = setNames[si];
5496
+ const y = matrixTop + si * rowSpacing + 1;
5497
+ const isActive = inter.sets.has(setName);
5498
+ if (isActive) {
5499
+ canvas.drawChar(x, y, dotChar, dotColor);
5500
+ activeRows.push(y);
5501
+ } else {
5502
+ canvas.drawChar(x, y, emptyChar, { r: 200, g: 200, b: 200, a: 1 });
5503
+ }
5504
+ }
5505
+ if (activeRows.length > 1) {
5506
+ const minY = Math.min(...activeRows);
5507
+ const maxY = Math.max(...activeRows);
5508
+ for (let y = minY + 1;y < maxY; y++) {
5509
+ if (!activeRows.includes(y)) {
5510
+ canvas.drawChar(x, y, lineChar, lineColor);
5511
+ }
5512
+ }
5513
+ }
5514
+ }
5515
+ }
5516
+ function renderGeomDendrogram(data, geom, _aes, scales, canvas) {
5517
+ const params = geom.params || {};
5518
+ const orientation = params.orientation ?? "vertical";
5519
+ const labels = params.labels;
5520
+ const showLabels = params.show_labels ?? true;
5521
+ const hang = params.hang ?? false;
5522
+ const hConnector = params.h_connector ?? "─";
5523
+ const vConnector = params.v_connector ?? "│";
5524
+ const cornerTR = params.corner_tr ?? "┐";
5525
+ const cornerBL = params.corner_bl ?? "└";
5526
+ const cornerBR = params.corner_br ?? "┘";
5527
+ const leafChar = params.leaf_char ?? "○";
5528
+ const parentCol = params.parent_col ?? "parent";
5529
+ const heightCol = params.height_col ?? "height";
5530
+ const idCol = params.id_col ?? "id";
5531
+ const plotLeft = Math.round(scales.x.range[0]);
5532
+ const plotRight = Math.round(scales.x.range[1]);
5533
+ const plotTop = Math.round(scales.y.range[1]);
5534
+ const plotBottom = Math.round(scales.y.range[0]);
5535
+ const plotWidth = plotRight - plotLeft;
5536
+ const plotHeight = plotBottom - plotTop;
5537
+ const lineColor = { r: 50, g: 50, b: 50, a: 1 };
5538
+ const leafColor = { r: 31, g: 119, b: 180, a: 1 };
5539
+ const labelColor = { r: 100, g: 100, b: 100, a: 1 };
5540
+ const hasLinkageFormat = data.length > 0 && (("merge1" in data[0]) || ("merge_1" in data[0]));
5541
+ if (hasLinkageFormat) {
5542
+ const linkage = data.map((row) => ({
5543
+ merge1: Number(row["merge1"] ?? row["merge_1"]),
5544
+ merge2: Number(row["merge2"] ?? row["merge_2"]),
5545
+ height: Number(row[heightCol] ?? row["height"]),
5546
+ size: Number(row["size"] ?? 2)
5547
+ }));
5548
+ if (linkage.length === 0)
5549
+ return;
5550
+ const n = linkage.length + 1;
5551
+ const nodes = new Map;
5552
+ for (let i = 0;i < n; i++) {
5553
+ nodes.set(i, {
5554
+ id: i,
5555
+ height: 0,
5556
+ label: labels?.[i] ?? `${i}`
5557
+ });
5558
+ }
5559
+ for (let i = 0;i < linkage.length; i++) {
5560
+ const row = linkage[i];
5561
+ const newId = n + i;
5562
+ const leftNode = nodes.get(row.merge1 < n ? row.merge1 : row.merge1);
5563
+ const rightNode = nodes.get(row.merge2 < n ? row.merge2 : row.merge2);
5564
+ nodes.set(newId, {
5565
+ id: newId,
5566
+ left: leftNode,
5567
+ right: rightNode,
5568
+ height: row.height
5569
+ });
5570
+ }
5571
+ const root = nodes.get(n + linkage.length - 1);
5572
+ if (!root)
5573
+ return;
5574
+ let xPos = 0;
5575
+ const assignX = (node) => {
5576
+ if (!node.left && !node.right) {
5577
+ node.x = xPos++;
5578
+ } else {
5579
+ if (node.left)
5580
+ assignX(node.left);
5581
+ if (node.right)
5582
+ assignX(node.right);
5583
+ const leftX = node.left?.x ?? 0;
5584
+ const rightX = node.right?.x ?? 0;
5585
+ node.x = (leftX + rightX) / 2;
5586
+ }
5587
+ };
5588
+ assignX(root);
5589
+ const maxHeight = root.height;
5590
+ const leafCount = xPos;
5591
+ const mapX = (x) => {
5592
+ if (orientation === "vertical") {
5593
+ return plotLeft + x / (leafCount - 1 || 1) * plotWidth;
5594
+ } else {
5595
+ return plotBottom - x / (leafCount - 1 || 1) * plotHeight;
5596
+ }
5597
+ };
5598
+ const mapY = (h) => {
5599
+ if (orientation === "vertical") {
5600
+ return plotTop + (1 - h / maxHeight) * (plotHeight - 3);
5601
+ } else {
5602
+ return plotLeft + h / maxHeight * plotWidth;
5603
+ }
5604
+ };
5605
+ const drawNode = (node) => {
5606
+ if (node.x === undefined)
5607
+ return;
5608
+ if (node.left && node.right) {
5609
+ const nodeY = mapY(node.height);
5610
+ const leftX = mapX(node.left.x);
5611
+ const leftY = mapY(node.left.height);
5612
+ const rightX = mapX(node.right.x);
5613
+ const rightY = mapY(node.right.height);
5614
+ if (orientation === "vertical") {
5615
+ const hLineY = Math.round(nodeY);
5616
+ const leftXRound = Math.round(leftX);
5617
+ const rightXRound = Math.round(rightX);
5618
+ for (let x = Math.min(leftXRound, rightXRound);x <= Math.max(leftXRound, rightXRound); x++) {
5619
+ canvas.drawChar(x, hLineY, hConnector, lineColor);
5620
+ }
5621
+ canvas.drawChar(leftXRound, hLineY, cornerBL, lineColor);
5622
+ canvas.drawChar(rightXRound, hLineY, cornerBR, lineColor);
5623
+ const leftYRound = Math.round(leftY);
5624
+ const rightYRound = Math.round(rightY);
5625
+ for (let y = hLineY + 1;y < leftYRound; y++) {
5626
+ canvas.drawChar(leftXRound, y, vConnector, lineColor);
5627
+ }
5628
+ for (let y = hLineY + 1;y < rightYRound; y++) {
5629
+ canvas.drawChar(rightXRound, y, vConnector, lineColor);
5630
+ }
5631
+ } else {
5632
+ const hLineX = Math.round(nodeY);
5633
+ const leftYRound = Math.round(leftX);
5634
+ const rightYRound = Math.round(rightX);
5635
+ for (let y = Math.min(leftYRound, rightYRound);y <= Math.max(leftYRound, rightYRound); y++) {
5636
+ canvas.drawChar(hLineX, y, vConnector, lineColor);
5637
+ }
5638
+ canvas.drawChar(hLineX, leftYRound, cornerTR, lineColor);
5639
+ canvas.drawChar(hLineX, rightYRound, cornerBR, lineColor);
5640
+ const leftXRound = Math.round(mapY(node.left.height));
5641
+ const rightXRound = Math.round(mapY(node.right.height));
5642
+ for (let x = hLineX + 1;x < leftXRound; x++) {
5643
+ canvas.drawChar(x, leftYRound, hConnector, lineColor);
5644
+ }
5645
+ for (let x = hLineX + 1;x < rightXRound; x++) {
5646
+ canvas.drawChar(x, rightYRound, hConnector, lineColor);
5647
+ }
5648
+ }
5649
+ drawNode(node.left);
5650
+ drawNode(node.right);
5651
+ } else {
5652
+ if (orientation === "vertical") {
5653
+ const x = Math.round(mapX(node.x));
5654
+ const y = hang ? plotBottom - 2 : Math.round(mapY(0));
5655
+ canvas.drawChar(x, y, leafChar, leafColor);
5656
+ if (showLabels && node.label) {
5657
+ const label = node.label.substring(0, 4);
5658
+ for (let ci = 0;ci < label.length; ci++) {
5659
+ canvas.drawChar(x - Math.floor(label.length / 2) + ci, y + 1, label[ci], labelColor);
5660
+ }
5661
+ }
5662
+ } else {
5663
+ const y = Math.round(mapX(node.x));
5664
+ const x = Math.round(mapY(0));
5665
+ canvas.drawChar(x, y, leafChar, leafColor);
5666
+ if (showLabels && node.label) {
5667
+ const label = node.label.substring(0, 6);
5668
+ for (let ci = 0;ci < label.length; ci++) {
5669
+ canvas.drawChar(x + 2 + ci, y, label[ci], labelColor);
5670
+ }
5671
+ }
5672
+ }
5673
+ }
5674
+ };
5675
+ drawNode(root);
5676
+ } else {
5677
+ const nodeMap = new Map;
5678
+ for (const row of data) {
5679
+ const id = String(row[idCol] ?? "");
5680
+ const parent = row[parentCol];
5681
+ const height = Number(row[heightCol] ?? 0);
5682
+ nodeMap.set(id, {
5683
+ id,
5684
+ parent: parent === null || parent === "" || parent === "null" ? null : String(parent),
5685
+ height,
5686
+ children: []
5687
+ });
5688
+ }
5689
+ let root = null;
5690
+ for (const node of nodeMap.values()) {
5691
+ if (node.parent === null) {
5692
+ root = node;
5693
+ } else {
5694
+ const parentNode = nodeMap.get(node.parent);
5695
+ if (parentNode) {
5696
+ parentNode.children.push(node);
5697
+ }
5698
+ }
5699
+ }
5700
+ if (!root)
5701
+ return;
5702
+ let xPos = 0;
5703
+ const assignX = (node) => {
5704
+ if (node.children.length === 0) {
5705
+ node.x = xPos++;
5706
+ } else {
5707
+ for (const child of node.children) {
5708
+ assignX(child);
5709
+ }
5710
+ const childXs = node.children.map((c) => c.x ?? 0);
5711
+ node.x = childXs.reduce((a, b) => a + b, 0) / childXs.length;
5712
+ }
5713
+ };
5714
+ assignX(root);
5715
+ const findMaxHeight = (node) => {
5716
+ if (node.children.length === 0)
5717
+ return node.height;
5718
+ return Math.max(node.height, ...node.children.map(findMaxHeight));
5719
+ };
5720
+ const maxHeight = findMaxHeight(root) || 1;
5721
+ const leafCount = xPos || 1;
5722
+ const mapX = (x) => plotLeft + x / (leafCount - 1 || 1) * plotWidth;
5723
+ const mapY = (h) => plotTop + (1 - h / maxHeight) * (plotHeight - 3);
5724
+ const drawNode = (node) => {
5725
+ if (node.x === undefined)
5726
+ return;
5727
+ if (node.children.length > 0) {
5728
+ const nodeY = Math.round(mapY(node.height));
5729
+ const childXs = node.children.map((c) => Math.round(mapX(c.x ?? 0)));
5730
+ const minX = Math.min(...childXs);
5731
+ const maxX = Math.max(...childXs);
5732
+ for (let x = minX;x <= maxX; x++) {
5733
+ canvas.drawChar(x, nodeY, hConnector, lineColor);
5734
+ }
5735
+ for (const child of node.children) {
5736
+ const childX = Math.round(mapX(child.x ?? 0));
5737
+ const childY = Math.round(mapY(child.height));
5738
+ canvas.drawChar(childX, nodeY, child === node.children[0] ? cornerBL : child === node.children[node.children.length - 1] ? cornerBR : "┴", lineColor);
5739
+ for (let y = nodeY + 1;y < childY; y++) {
5740
+ canvas.drawChar(childX, y, vConnector, lineColor);
5741
+ }
5742
+ drawNode(child);
5743
+ }
5744
+ } else {
5745
+ const x = Math.round(mapX(node.x));
5746
+ const y = hang ? plotBottom - 2 : Math.round(mapY(node.height));
5747
+ canvas.drawChar(x, y, leafChar, leafColor);
5748
+ if (showLabels) {
5749
+ const label = node.id.substring(0, 4);
5750
+ for (let ci = 0;ci < label.length; ci++) {
5751
+ canvas.drawChar(x - Math.floor(label.length / 2) + ci, y + 1, label[ci], labelColor);
5752
+ }
5753
+ }
5754
+ }
5755
+ };
5756
+ drawNode(root);
5757
+ }
5758
+ }
3767
5759
  var POINT_SHAPES, SIZE_CHARS;
3768
5760
  var init_render_geoms = __esm(() => {
3769
5761
  init_scales();
@@ -7081,28 +9073,17 @@ function geom_abline(options = {}) {
7081
9073
  // src/geoms/qq.ts
7082
9074
  function geom_qq(options = {}) {
7083
9075
  return {
7084
- type: "point",
7085
- stat: "qq",
7086
- params: {
7087
- distribution: options.distribution ?? "norm",
7088
- dparams: options.dparams,
7089
- size: options.size ?? 1,
7090
- shape: options.shape ?? "●",
7091
- color: options.color,
7092
- alpha: options.alpha ?? 1
7093
- }
7094
- };
7095
- }
7096
- function geom_qq_line(options = {}) {
7097
- return {
7098
- type: "segment",
7099
- stat: "qq_line",
9076
+ type: "qq",
9077
+ stat: "identity",
9078
+ position: "identity",
7100
9079
  params: {
7101
- distribution: options.distribution ?? "norm",
7102
- dparams: options.dparams,
7103
- color: options.color ?? "gray",
7104
- linetype: options.linetype ?? "dashed",
7105
- alpha: options.alpha ?? 1
9080
+ distribution: options.distribution ?? "normal",
9081
+ show_line: options.show_line ?? true,
9082
+ show_ci: options.show_ci ?? false,
9083
+ conf_level: options.conf_level ?? 0.95,
9084
+ line_color: options.line_color ?? "#ff0000",
9085
+ point_char: options.point_char ?? "●",
9086
+ standardize: options.standardize ?? true
7106
9087
  }
7107
9088
  };
7108
9089
  }
@@ -7381,11 +9362,383 @@ function geom_treemap(options = {}) {
7381
9362
  };
7382
9363
  }
7383
9364
 
9365
+ // src/geoms/volcano.ts
9366
+ function geom_volcano(options = {}) {
9367
+ return {
9368
+ type: "volcano",
9369
+ stat: "identity",
9370
+ position: "identity",
9371
+ params: {
9372
+ fc_threshold: options.fc_threshold ?? 1,
9373
+ p_threshold: options.p_threshold ?? 0.05,
9374
+ y_is_neglog10: options.y_is_neglog10 ?? false,
9375
+ up_color: options.up_color ?? "#e41a1c",
9376
+ down_color: options.down_color ?? "#377eb8",
9377
+ ns_color: options.ns_color ?? "#999999",
9378
+ show_thresholds: options.show_thresholds ?? true,
9379
+ threshold_linetype: options.threshold_linetype ?? "dashed",
9380
+ n_labels: options.n_labels ?? 0,
9381
+ size: options.size ?? 1,
9382
+ alpha: options.alpha ?? 0.6,
9383
+ point_char: options.point_char ?? "●",
9384
+ show_legend: options.show_legend ?? true,
9385
+ classify: options.classify
9386
+ }
9387
+ };
9388
+ }
9389
+
9390
+ // src/geoms/ma.ts
9391
+ function geom_ma(options = {}) {
9392
+ return {
9393
+ type: "ma",
9394
+ stat: "identity",
9395
+ position: "identity",
9396
+ params: {
9397
+ fc_threshold: options.fc_threshold ?? 1,
9398
+ p_threshold: options.p_threshold ?? 0.05,
9399
+ p_col: options.p_col,
9400
+ x_is_log2: options.x_is_log2 ?? false,
9401
+ up_color: options.up_color ?? "#e41a1c",
9402
+ down_color: options.down_color ?? "#377eb8",
9403
+ ns_color: options.ns_color ?? "#999999",
9404
+ show_baseline: options.show_baseline ?? true,
9405
+ show_thresholds: options.show_thresholds ?? true,
9406
+ linetype: options.linetype ?? "dashed",
9407
+ n_labels: options.n_labels ?? 0,
9408
+ size: options.size ?? 1,
9409
+ alpha: options.alpha ?? 0.6,
9410
+ point_char: options.point_char ?? "●",
9411
+ show_smooth: options.show_smooth ?? false
9412
+ }
9413
+ };
9414
+ }
9415
+
9416
+ // src/geoms/manhattan.ts
9417
+ function geom_manhattan(options = {}) {
9418
+ return {
9419
+ type: "manhattan",
9420
+ stat: "identity",
9421
+ position: "identity",
9422
+ params: {
9423
+ suggestive_threshold: options.suggestive_threshold ?? 0.00001,
9424
+ genome_wide_threshold: options.genome_wide_threshold ?? 0.00000005,
9425
+ chr_col: options.chr_col,
9426
+ pos_col: options.pos_col,
9427
+ p_col: options.p_col,
9428
+ y_is_neglog10: options.y_is_neglog10 ?? false,
9429
+ chr_colors: options.chr_colors ?? DEFAULT_CHR_COLORS,
9430
+ highlight_color: options.highlight_color ?? "#e41a1c",
9431
+ suggestive_color: options.suggestive_color ?? "#ff7f00",
9432
+ show_thresholds: options.show_thresholds ?? true,
9433
+ threshold_linetype: options.threshold_linetype ?? "dashed",
9434
+ n_labels: options.n_labels ?? 0,
9435
+ label_col: options.label_col,
9436
+ size: options.size ?? 1,
9437
+ alpha: options.alpha ?? 0.6,
9438
+ point_char: options.point_char ?? "●",
9439
+ chr_gap: options.chr_gap ?? 0.02
9440
+ }
9441
+ };
9442
+ }
9443
+ var DEFAULT_CHR_COLORS;
9444
+ var init_manhattan = __esm(() => {
9445
+ DEFAULT_CHR_COLORS = ["#1f78b4", "#a6cee3"];
9446
+ });
9447
+
9448
+ // src/geoms/heatmap.ts
9449
+ function geom_heatmap(options = {}) {
9450
+ return {
9451
+ type: "heatmap",
9452
+ stat: "identity",
9453
+ position: "identity",
9454
+ params: {
9455
+ x_col: options.x_col,
9456
+ y_col: options.y_col,
9457
+ value_col: options.value_col ?? "value",
9458
+ low_color: options.low_color ?? "#313695",
9459
+ mid_color: options.mid_color ?? "#ffffbf",
9460
+ high_color: options.high_color ?? "#a50026",
9461
+ na_color: options.na_color ?? "#808080",
9462
+ midpoint: options.midpoint,
9463
+ cluster_rows: options.cluster_rows ?? false,
9464
+ cluster_cols: options.cluster_cols ?? false,
9465
+ clustering_method: options.clustering_method ?? "complete",
9466
+ clustering_distance: options.clustering_distance ?? "euclidean",
9467
+ show_row_dendrogram: options.show_row_dendrogram ?? true,
9468
+ show_col_dendrogram: options.show_col_dendrogram ?? true,
9469
+ dendrogram_ratio: options.dendrogram_ratio ?? 0.15,
9470
+ show_row_labels: options.show_row_labels ?? true,
9471
+ show_col_labels: options.show_col_labels ?? true,
9472
+ show_values: options.show_values ?? false,
9473
+ value_format: options.value_format ?? ".2f",
9474
+ cell_char: options.cell_char ?? "█",
9475
+ border: options.border ?? false,
9476
+ scale: options.scale ?? "none"
9477
+ }
9478
+ };
9479
+ }
9480
+
9481
+ // src/geoms/biplot.ts
9482
+ function geom_biplot(options = {}) {
9483
+ return {
9484
+ type: "biplot",
9485
+ stat: "identity",
9486
+ position: "identity",
9487
+ params: {
9488
+ pc1_col: options.pc1_col ?? "PC1",
9489
+ pc2_col: options.pc2_col ?? "PC2",
9490
+ loadings: options.loadings,
9491
+ var_explained: options.var_explained,
9492
+ show_scores: options.show_scores ?? true,
9493
+ score_color: options.score_color,
9494
+ score_size: options.score_size ?? 1,
9495
+ score_alpha: options.score_alpha ?? 0.8,
9496
+ score_char: options.score_char ?? "●",
9497
+ show_score_labels: options.show_score_labels ?? false,
9498
+ show_loadings: options.show_loadings ?? true,
9499
+ loading_color: options.loading_color ?? "#e41a1c",
9500
+ loading_scale: options.loading_scale,
9501
+ arrow_char: options.arrow_char ?? "→",
9502
+ show_loading_labels: options.show_loading_labels ?? true,
9503
+ show_origin: options.show_origin ?? true,
9504
+ origin_color: options.origin_color ?? "#999999",
9505
+ show_circle: options.show_circle ?? false,
9506
+ circle_color: options.circle_color ?? "#cccccc"
9507
+ }
9508
+ };
9509
+ }
9510
+
9511
+ // src/geoms/kaplan-meier.ts
9512
+ function geom_kaplan_meier(options = {}) {
9513
+ return {
9514
+ type: "kaplan_meier",
9515
+ stat: "identity",
9516
+ position: "identity",
9517
+ params: {
9518
+ show_ci: options.show_ci ?? false,
9519
+ conf_level: options.conf_level ?? 0.95,
9520
+ show_censored: options.show_censored ?? true,
9521
+ censor_char: options.censor_char ?? "+",
9522
+ show_risk_table: options.show_risk_table ?? false,
9523
+ linetype: options.linetype ?? "solid",
9524
+ show_median: options.show_median ?? false,
9525
+ step_type: options.step_type ?? "post"
9526
+ }
9527
+ };
9528
+ }
9529
+
9530
+ // src/geoms/forest.ts
9531
+ function geom_forest(options = {}) {
9532
+ return {
9533
+ type: "forest",
9534
+ stat: "identity",
9535
+ position: "identity",
9536
+ params: {
9537
+ null_line: options.null_line ?? 1,
9538
+ log_scale: options.log_scale ?? false,
9539
+ show_summary: options.show_summary ?? false,
9540
+ summary_row: options.summary_row,
9541
+ null_line_color: options.null_line_color ?? "#888888",
9542
+ null_line_type: options.null_line_type ?? "dashed",
9543
+ point_char: options.point_char ?? "■",
9544
+ show_weights: options.show_weights ?? false,
9545
+ min_size: options.min_size ?? 1,
9546
+ max_size: options.max_size ?? 3
9547
+ }
9548
+ };
9549
+ }
9550
+
9551
+ // src/geoms/roc.ts
9552
+ function geom_roc(options = {}) {
9553
+ return {
9554
+ type: "roc",
9555
+ stat: "identity",
9556
+ position: "identity",
9557
+ params: {
9558
+ show_diagonal: options.show_diagonal ?? true,
9559
+ diagonal_color: options.diagonal_color ?? "#888888",
9560
+ diagonal_type: options.diagonal_type ?? "dashed",
9561
+ show_auc: options.show_auc ?? true,
9562
+ show_optimal: options.show_optimal ?? false,
9563
+ optimal_char: options.optimal_char ?? "●",
9564
+ show_ci: options.show_ci ?? false,
9565
+ conf_level: options.conf_level ?? 0.95,
9566
+ fill_auc: options.fill_auc ?? false,
9567
+ fill_alpha: options.fill_alpha ?? 0.3
9568
+ }
9569
+ };
9570
+ }
9571
+
9572
+ // src/geoms/bland-altman.ts
9573
+ function geom_bland_altman(options = {}) {
9574
+ return {
9575
+ type: "bland_altman",
9576
+ stat: "identity",
9577
+ position: "identity",
9578
+ params: {
9579
+ show_limits: options.show_limits ?? true,
9580
+ show_bias: options.show_bias ?? true,
9581
+ limit_multiplier: options.limit_multiplier ?? 1.96,
9582
+ bias_color: options.bias_color ?? "#0000ff",
9583
+ limit_color: options.limit_color ?? "#ff0000",
9584
+ linetype: options.linetype ?? "dashed",
9585
+ show_ci: options.show_ci ?? false,
9586
+ conf_level: options.conf_level ?? 0.95,
9587
+ point_char: options.point_char ?? "●",
9588
+ percent_diff: options.percent_diff ?? false,
9589
+ precomputed: options.precomputed ?? false
9590
+ }
9591
+ };
9592
+ }
9593
+
9594
+ // src/geoms/ecdf.ts
9595
+ function geom_ecdf(options = {}) {
9596
+ return {
9597
+ type: "ecdf",
9598
+ stat: "identity",
9599
+ position: "identity",
9600
+ params: {
9601
+ pad: options.pad ?? true,
9602
+ show_ci: options.show_ci ?? false,
9603
+ conf_level: options.conf_level ?? 0.95,
9604
+ step_type: options.step_type ?? "post",
9605
+ show_points: options.show_points ?? false,
9606
+ line_char: options.line_char ?? "─",
9607
+ complement: options.complement ?? false
9608
+ }
9609
+ };
9610
+ }
9611
+
9612
+ // src/geoms/funnel.ts
9613
+ function geom_funnel(options = {}) {
9614
+ return {
9615
+ type: "funnel",
9616
+ stat: "identity",
9617
+ position: "identity",
9618
+ params: {
9619
+ show_contours: options.show_contours ?? true,
9620
+ contour_levels: options.contour_levels ?? [0.95],
9621
+ show_significance: options.show_significance ?? false,
9622
+ summary_effect: options.summary_effect,
9623
+ show_summary_line: options.show_summary_line ?? true,
9624
+ y_is_se: options.y_is_se ?? true,
9625
+ invert_y: options.invert_y ?? true,
9626
+ point_char: options.point_char ?? "●",
9627
+ contour_color: options.contour_color ?? "#888888"
9628
+ }
9629
+ };
9630
+ }
9631
+
9632
+ // src/geoms/control.ts
9633
+ function geom_control(options = {}) {
9634
+ return {
9635
+ type: "control",
9636
+ stat: "identity",
9637
+ position: "identity",
9638
+ params: {
9639
+ chart_type: options.chart_type ?? "i",
9640
+ sigma: options.sigma ?? 3,
9641
+ show_center: options.show_center ?? true,
9642
+ show_ucl: options.show_ucl ?? true,
9643
+ show_lcl: options.show_lcl ?? true,
9644
+ show_warning: options.show_warning ?? false,
9645
+ center: options.center,
9646
+ ucl: options.ucl,
9647
+ lcl: options.lcl,
9648
+ center_color: options.center_color ?? "#0000ff",
9649
+ limit_color: options.limit_color ?? "#ff0000",
9650
+ warning_color: options.warning_color ?? "#ffa500",
9651
+ connect_points: options.connect_points ?? true,
9652
+ highlight_ooc: options.highlight_ooc ?? true,
9653
+ ooc_char: options.ooc_char ?? "◆",
9654
+ point_char: options.point_char ?? "●"
9655
+ }
9656
+ };
9657
+ }
9658
+
9659
+ // src/geoms/scree.ts
9660
+ function geom_scree(options = {}) {
9661
+ return {
9662
+ type: "scree",
9663
+ stat: "identity",
9664
+ position: "identity",
9665
+ params: {
9666
+ show_cumulative: options.show_cumulative ?? false,
9667
+ show_kaiser: options.show_kaiser ?? false,
9668
+ show_elbow: options.show_elbow ?? false,
9669
+ show_broken_stick: options.show_broken_stick ?? false,
9670
+ connect_points: options.connect_points ?? true,
9671
+ show_bars: options.show_bars ?? false,
9672
+ point_char: options.point_char ?? "●",
9673
+ color: options.color,
9674
+ cumulative_color: options.cumulative_color ?? "#ff0000",
9675
+ kaiser_color: options.kaiser_color ?? "#888888",
9676
+ y_format: options.y_format ?? "percentage",
9677
+ threshold: options.threshold,
9678
+ threshold_color: options.threshold_color ?? "#00aa00"
9679
+ }
9680
+ };
9681
+ }
9682
+
9683
+ // src/geoms/upset.ts
9684
+ function geom_upset(options = {}) {
9685
+ return {
9686
+ type: "upset",
9687
+ stat: "identity",
9688
+ position: "identity",
9689
+ params: {
9690
+ sets: options.sets,
9691
+ min_size: options.min_size ?? 1,
9692
+ max_intersections: options.max_intersections ?? 20,
9693
+ sort_by: options.sort_by ?? "size",
9694
+ sort_order: options.sort_order ?? "desc",
9695
+ show_set_sizes: options.show_set_sizes ?? true,
9696
+ dot_char: options.dot_char ?? "●",
9697
+ empty_char: options.empty_char ?? "○",
9698
+ line_char: options.line_char ?? "│",
9699
+ bar_char: options.bar_char ?? "█",
9700
+ color: options.color,
9701
+ show_degree: options.show_degree ?? false
9702
+ }
9703
+ };
9704
+ }
9705
+
9706
+ // src/geoms/dendrogram.ts
9707
+ function geom_dendrogram(options = {}) {
9708
+ return {
9709
+ type: "dendrogram",
9710
+ stat: "identity",
9711
+ position: "identity",
9712
+ params: {
9713
+ orientation: options.orientation ?? "vertical",
9714
+ labels: options.labels,
9715
+ show_labels: options.show_labels ?? true,
9716
+ hang: options.hang ?? false,
9717
+ cut_height: options.cut_height,
9718
+ k: options.k,
9719
+ branch_char: options.branch_char ?? "│",
9720
+ h_connector: options.h_connector ?? "─",
9721
+ v_connector: options.v_connector ?? "│",
9722
+ corner_tl: options.corner_tl ?? "┌",
9723
+ corner_tr: options.corner_tr ?? "┐",
9724
+ corner_bl: options.corner_bl ?? "└",
9725
+ corner_br: options.corner_br ?? "┘",
9726
+ leaf_char: options.leaf_char ?? "○",
9727
+ cluster_colors: options.cluster_colors,
9728
+ line_style: options.line_style ?? "square",
9729
+ parent_col: options.parent_col ?? "parent",
9730
+ height_col: options.height_col ?? "height",
9731
+ id_col: options.id_col ?? "id"
9732
+ }
9733
+ };
9734
+ }
9735
+
7384
9736
  // src/geoms/index.ts
7385
9737
  var init_geoms = __esm(() => {
7386
9738
  init_ridgeline();
7387
9739
  init_sparkline();
7388
9740
  init_braille();
9741
+ init_manhattan();
7389
9742
  });
7390
9743
 
7391
9744
  // src/stats/index.ts
@@ -11889,8 +14242,10 @@ __export(exports_src, {
11889
14242
  getCapabilities: () => getCapabilities,
11890
14243
  getAvailablePalettes: () => getAvailablePalettes,
11891
14244
  geom_waffle: () => geom_waffle,
14245
+ geom_volcano: () => geom_volcano,
11892
14246
  geom_vline: () => geom_vline,
11893
14247
  geom_violin: () => geom_violin,
14248
+ geom_upset: () => geom_upset,
11894
14249
  geom_treemap: () => geom_treemap,
11895
14250
  geom_tile: () => geom_tile,
11896
14251
  geom_text: () => geom_text,
@@ -11898,36 +14253,46 @@ __export(exports_src, {
11898
14253
  geom_sparkline: () => geom_sparkline,
11899
14254
  geom_smooth: () => geom_smooth,
11900
14255
  geom_segment: () => geom_segment,
14256
+ geom_scree: () => geom_scree,
11901
14257
  geom_sankey: () => geom_sankey,
11902
14258
  geom_rug: () => geom_rug,
14259
+ geom_roc: () => geom_roc,
11903
14260
  geom_ridgeline: () => geom_ridgeline,
11904
14261
  geom_ribbon: () => geom_ribbon,
11905
14262
  geom_rect: () => geom_rect,
11906
14263
  geom_raster: () => geom_raster,
11907
14264
  geom_quasirandom: () => geom_quasirandom,
11908
- geom_qq_line: () => geom_qq_line,
11909
14265
  geom_qq: () => geom_qq,
11910
14266
  geom_pointrange: () => geom_pointrange,
11911
14267
  geom_point: () => geom_point,
11912
14268
  geom_path: () => geom_path,
14269
+ geom_manhattan: () => geom_manhattan,
14270
+ geom_ma: () => geom_ma,
11913
14271
  geom_lollipop: () => geom_lollipop,
11914
14272
  geom_linerange: () => geom_linerange,
11915
14273
  geom_line: () => geom_line,
11916
14274
  geom_label: () => geom_label,
14275
+ geom_kaplan_meier: () => geom_kaplan_meier,
11917
14276
  geom_joy: () => geom_joy,
11918
14277
  geom_icicle: () => geom_icicle,
11919
14278
  geom_hline: () => geom_hline,
11920
14279
  geom_histogram: () => geom_histogram,
14280
+ geom_heatmap: () => geom_heatmap,
14281
+ geom_funnel: () => geom_funnel,
11921
14282
  geom_freqpoly: () => geom_freqpoly,
14283
+ geom_forest: () => geom_forest,
11922
14284
  geom_flame: () => geom_flame,
11923
14285
  geom_errorbarh: () => geom_errorbarh,
11924
14286
  geom_errorbar: () => geom_errorbar,
14287
+ geom_ecdf: () => geom_ecdf,
11925
14288
  geom_dumbbell: () => geom_dumbbell,
11926
14289
  geom_density_2d: () => geom_density_2d,
11927
14290
  geom_density: () => geom_density,
14291
+ geom_dendrogram: () => geom_dendrogram,
11928
14292
  geom_curve: () => geom_curve,
11929
14293
  geom_crossbar: () => geom_crossbar,
11930
14294
  geom_corrmat: () => geom_corrmat,
14295
+ geom_control: () => geom_control,
11931
14296
  geom_contour_filled: () => geom_contour_filled,
11932
14297
  geom_contour: () => geom_contour,
11933
14298
  geom_col: () => geom_col,
@@ -11935,6 +14300,8 @@ __export(exports_src, {
11935
14300
  geom_bullet: () => geom_bullet,
11936
14301
  geom_braille: () => geom_braille,
11937
14302
  geom_boxplot: () => geom_boxplot,
14303
+ geom_bland_altman: () => geom_bland_altman,
14304
+ geom_biplot: () => geom_biplot,
11938
14305
  geom_bin2d: () => geom_bin2d,
11939
14306
  geom_beeswarm: () => geom_beeswarm,
11940
14307
  geom_bar: () => geom_bar,
@@ -12158,8 +14525,10 @@ export {
12158
14525
  getCapabilities,
12159
14526
  getAvailablePalettes,
12160
14527
  geom_waffle,
14528
+ geom_volcano,
12161
14529
  geom_vline,
12162
14530
  geom_violin,
14531
+ geom_upset,
12163
14532
  geom_treemap,
12164
14533
  geom_tile,
12165
14534
  geom_text,
@@ -12167,36 +14536,46 @@ export {
12167
14536
  geom_sparkline,
12168
14537
  geom_smooth,
12169
14538
  geom_segment,
14539
+ geom_scree,
12170
14540
  geom_sankey,
12171
14541
  geom_rug,
14542
+ geom_roc,
12172
14543
  geom_ridgeline,
12173
14544
  geom_ribbon,
12174
14545
  geom_rect,
12175
14546
  geom_raster,
12176
14547
  geom_quasirandom,
12177
- geom_qq_line,
12178
14548
  geom_qq,
12179
14549
  geom_pointrange,
12180
14550
  geom_point,
12181
14551
  geom_path,
14552
+ geom_manhattan,
14553
+ geom_ma,
12182
14554
  geom_lollipop,
12183
14555
  geom_linerange,
12184
14556
  geom_line,
12185
14557
  geom_label,
14558
+ geom_kaplan_meier,
12186
14559
  geom_joy,
12187
14560
  geom_icicle,
12188
14561
  geom_hline,
12189
14562
  geom_histogram,
14563
+ geom_heatmap,
14564
+ geom_funnel,
12190
14565
  geom_freqpoly,
14566
+ geom_forest,
12191
14567
  geom_flame,
12192
14568
  geom_errorbarh,
12193
14569
  geom_errorbar,
14570
+ geom_ecdf,
12194
14571
  geom_dumbbell,
12195
14572
  geom_density_2d,
12196
14573
  geom_density,
14574
+ geom_dendrogram,
12197
14575
  geom_curve,
12198
14576
  geom_crossbar,
12199
14577
  geom_corrmat,
14578
+ geom_control,
12200
14579
  geom_contour_filled,
12201
14580
  geom_contour,
12202
14581
  geom_col,
@@ -12204,6 +14583,8 @@ export {
12204
14583
  geom_bullet,
12205
14584
  geom_braille,
12206
14585
  geom_boxplot,
14586
+ geom_bland_altman,
14587
+ geom_biplot,
12207
14588
  geom_bin2d,
12208
14589
  geom_beeswarm,
12209
14590
  geom_bar,