@ggterm/core 0.2.17 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-plot.js +3128 -118
- package/dist/cli.js +2287 -23
- package/dist/geoms/biplot.d.ts +35 -0
- package/dist/geoms/biplot.d.ts.map +1 -0
- package/dist/geoms/bland-altman.d.ts +50 -0
- package/dist/geoms/bland-altman.d.ts.map +1 -0
- package/dist/geoms/control.d.ts +118 -0
- package/dist/geoms/control.d.ts.map +1 -0
- package/dist/geoms/dendrogram.d.ts +74 -0
- package/dist/geoms/dendrogram.d.ts.map +1 -0
- package/dist/geoms/ecdf.d.ts +66 -0
- package/dist/geoms/ecdf.d.ts.map +1 -0
- package/dist/geoms/forest.d.ts +45 -0
- package/dist/geoms/forest.d.ts.map +1 -0
- package/dist/geoms/funnel.d.ts +78 -0
- package/dist/geoms/funnel.d.ts.map +1 -0
- package/dist/geoms/heatmap.d.ts +34 -0
- package/dist/geoms/heatmap.d.ts.map +1 -0
- package/dist/geoms/index.d.ts +15 -1
- package/dist/geoms/index.d.ts.map +1 -1
- package/dist/geoms/kaplan-meier.d.ts +39 -0
- package/dist/geoms/kaplan-meier.d.ts.map +1 -0
- package/dist/geoms/ma.d.ts +77 -0
- package/dist/geoms/ma.d.ts.map +1 -0
- package/dist/geoms/manhattan.d.ts +29 -0
- package/dist/geoms/manhattan.d.ts.map +1 -0
- package/dist/geoms/qq.d.ts +51 -59
- package/dist/geoms/qq.d.ts.map +1 -1
- package/dist/geoms/roc.d.ts +44 -0
- package/dist/geoms/roc.d.ts.map +1 -0
- package/dist/geoms/scree.d.ts +97 -0
- package/dist/geoms/scree.d.ts.map +1 -0
- package/dist/geoms/upset.d.ts +63 -0
- package/dist/geoms/upset.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2315 -25
- package/dist/pipeline/pipeline.d.ts.map +1 -1
- package/dist/pipeline/render-geoms.d.ts +4 -0
- package/dist/pipeline/render-geoms.d.ts.map +1 -1
- package/dist/serve.d.ts +8 -0
- package/dist/serve.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3707,6 +3707,96 @@ function renderGeomVolcano(data, geom, aes, scales, canvas) {
|
|
|
3707
3707
|
}
|
|
3708
3708
|
if (nLabels > 0 && aes.label) {
|
|
3709
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: 255, g: 255, b: 255, 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);
|
|
3710
3800
|
const labelColor = { r: 50, g: 50, b: 50, a: 1 };
|
|
3711
3801
|
for (const point of significantPoints) {
|
|
3712
3802
|
const cx = Math.round(scales.x.map(point.x));
|
|
@@ -3720,6 +3810,1385 @@ function renderGeomVolcano(data, geom, aes, scales, canvas) {
|
|
|
3720
3810
|
}
|
|
3721
3811
|
}
|
|
3722
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
|
+
const label = row.study;
|
|
4489
|
+
const labelColor = { r: 200, g: 200, b: 200, a: 1 };
|
|
4490
|
+
const labelEnd = plotLeft - 1;
|
|
4491
|
+
const labelStart = labelEnd - label.length;
|
|
4492
|
+
for (let c = 0;c < label.length; c++) {
|
|
4493
|
+
const charX = labelStart + c;
|
|
4494
|
+
if (charX >= 0) {
|
|
4495
|
+
canvas.drawChar(charX, y, label[c], labelColor);
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
4498
|
+
}
|
|
4499
|
+
}
|
|
4500
|
+
function renderGeomRoc(data, geom, aes, scales, canvas) {
|
|
4501
|
+
const params = geom.params || {};
|
|
4502
|
+
const showDiagonal = Boolean(params.show_diagonal ?? true);
|
|
4503
|
+
const diagonalColor = String(params.diagonal_color ?? "#888888");
|
|
4504
|
+
const showAuc = Boolean(params.show_auc ?? true);
|
|
4505
|
+
const showOptimal = Boolean(params.show_optimal ?? false);
|
|
4506
|
+
const optimalChar = String(params.optimal_char ?? "●");
|
|
4507
|
+
if (!Array.isArray(data) || data.length === 0)
|
|
4508
|
+
return;
|
|
4509
|
+
const parseHex = (hex) => {
|
|
4510
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
4511
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
4512
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
4513
|
+
return { r, g, b, a: 1 };
|
|
4514
|
+
};
|
|
4515
|
+
const diagColor = parseHex(diagonalColor);
|
|
4516
|
+
const xField = typeof aes.x === "string" ? aes.x : "fpr";
|
|
4517
|
+
const yField = typeof aes.y === "string" ? aes.y : "tpr";
|
|
4518
|
+
const colorField = typeof aes.color === "string" ? aes.color : undefined;
|
|
4519
|
+
const groups = new Map;
|
|
4520
|
+
for (const row of data) {
|
|
4521
|
+
const fpr = Number(row[xField] ?? 0);
|
|
4522
|
+
const tpr = Number(row[yField] ?? 0);
|
|
4523
|
+
const group = colorField ? String(row[colorField] ?? "default") : "default";
|
|
4524
|
+
if (!groups.has(group))
|
|
4525
|
+
groups.set(group, []);
|
|
4526
|
+
groups.get(group).push({ fpr, tpr });
|
|
4527
|
+
}
|
|
4528
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
4529
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
4530
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
4531
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
4532
|
+
const mapX = (v) => plotLeft + v * (plotRight - plotLeft);
|
|
4533
|
+
const mapY = (v) => plotBottom - v * (plotBottom - plotTop);
|
|
4534
|
+
if (showDiagonal) {
|
|
4535
|
+
const steps = plotRight - plotLeft;
|
|
4536
|
+
for (let i = 0;i <= steps; i += 2) {
|
|
4537
|
+
const t = i / steps;
|
|
4538
|
+
const x = Math.round(mapX(t));
|
|
4539
|
+
const y = Math.round(mapY(t));
|
|
4540
|
+
canvas.drawChar(x, y, "·", diagColor);
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
const colors = [
|
|
4544
|
+
{ r: 31, g: 119, b: 180, a: 1 },
|
|
4545
|
+
{ r: 255, g: 127, b: 14, a: 1 },
|
|
4546
|
+
{ r: 44, g: 160, b: 44, a: 1 },
|
|
4547
|
+
{ r: 214, g: 39, b: 40, a: 1 }
|
|
4548
|
+
];
|
|
4549
|
+
let colorIndex = 0;
|
|
4550
|
+
for (const [, points] of groups) {
|
|
4551
|
+
const color = colors[colorIndex % colors.length];
|
|
4552
|
+
colorIndex++;
|
|
4553
|
+
points.sort((a, b) => a.fpr - b.fpr);
|
|
4554
|
+
let auc = 0;
|
|
4555
|
+
for (let i = 1;i < points.length; i++) {
|
|
4556
|
+
const dx = points[i].fpr - points[i - 1].fpr;
|
|
4557
|
+
const avgY = (points[i].tpr + points[i - 1].tpr) / 2;
|
|
4558
|
+
auc += dx * avgY;
|
|
4559
|
+
}
|
|
4560
|
+
let optimalPoint = points[0];
|
|
4561
|
+
let maxJ = -Infinity;
|
|
4562
|
+
for (const p of points) {
|
|
4563
|
+
const j = p.tpr - p.fpr;
|
|
4564
|
+
if (j > maxJ) {
|
|
4565
|
+
maxJ = j;
|
|
4566
|
+
optimalPoint = p;
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
for (let i = 0;i < points.length; i++) {
|
|
4570
|
+
const p = points[i];
|
|
4571
|
+
const x = Math.round(mapX(p.fpr));
|
|
4572
|
+
const y = Math.round(mapY(p.tpr));
|
|
4573
|
+
if (i > 0) {
|
|
4574
|
+
const prev = points[i - 1];
|
|
4575
|
+
const px = Math.round(mapX(prev.fpr));
|
|
4576
|
+
const py = Math.round(mapY(prev.tpr));
|
|
4577
|
+
const steps = Math.max(Math.abs(x - px), Math.abs(y - py));
|
|
4578
|
+
for (let s = 0;s <= steps; s++) {
|
|
4579
|
+
const t = steps > 0 ? s / steps : 0;
|
|
4580
|
+
const lx = Math.round(px + (x - px) * t);
|
|
4581
|
+
const ly = Math.round(py + (y - py) * t);
|
|
4582
|
+
canvas.drawChar(lx, ly, "─", color);
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
canvas.drawChar(x, y, "●", color);
|
|
4586
|
+
}
|
|
4587
|
+
if (showOptimal) {
|
|
4588
|
+
const ox = Math.round(mapX(optimalPoint.fpr));
|
|
4589
|
+
const oy = Math.round(mapY(optimalPoint.tpr));
|
|
4590
|
+
canvas.drawChar(ox, oy, optimalChar, { r: 255, g: 0, b: 0, a: 1 });
|
|
4591
|
+
}
|
|
4592
|
+
if (showAuc && colorIndex === 1) {
|
|
4593
|
+
const aucText = `AUC=${auc.toFixed(3)}`;
|
|
4594
|
+
const labelColor = { r: 100, g: 100, b: 100, a: 1 };
|
|
4595
|
+
for (let i = 0;i < aucText.length; i++) {
|
|
4596
|
+
canvas.drawChar(plotRight - aucText.length + i, plotTop + 1, aucText[i], labelColor);
|
|
4597
|
+
}
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4601
|
+
function renderGeomBlandAltman(data, geom, aes, scales, canvas) {
|
|
4602
|
+
const params = geom.params || {};
|
|
4603
|
+
const showLimits = Boolean(params.show_limits ?? true);
|
|
4604
|
+
const showBias = Boolean(params.show_bias ?? true);
|
|
4605
|
+
const limitMultiplier = Number(params.limit_multiplier ?? 1.96);
|
|
4606
|
+
const biasColor = String(params.bias_color ?? "#0000ff");
|
|
4607
|
+
const limitColor = String(params.limit_color ?? "#ff0000");
|
|
4608
|
+
const pointChar = String(params.point_char ?? "●");
|
|
4609
|
+
const precomputed = Boolean(params.precomputed ?? false);
|
|
4610
|
+
if (!Array.isArray(data) || data.length === 0)
|
|
4611
|
+
return;
|
|
4612
|
+
const parseHex = (hex) => {
|
|
4613
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
4614
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
4615
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
4616
|
+
return { r, g, b, a: 1 };
|
|
4617
|
+
};
|
|
4618
|
+
const biasColorParsed = parseHex(biasColor);
|
|
4619
|
+
const limitColorParsed = parseHex(limitColor);
|
|
4620
|
+
const xField = typeof aes.x === "string" ? aes.x : "method1";
|
|
4621
|
+
const yField = typeof aes.y === "string" ? aes.y : "method2";
|
|
4622
|
+
const points = [];
|
|
4623
|
+
if (precomputed) {
|
|
4624
|
+
for (const row of data) {
|
|
4625
|
+
const mean = Number(row[xField] ?? 0);
|
|
4626
|
+
const diff = Number(row[yField] ?? 0);
|
|
4627
|
+
points.push({ mean, diff });
|
|
4628
|
+
}
|
|
4629
|
+
} else {
|
|
4630
|
+
for (const row of data) {
|
|
4631
|
+
const m1 = Number(row[xField] ?? 0);
|
|
4632
|
+
const m2 = Number(row[yField] ?? 0);
|
|
4633
|
+
const mean = (m1 + m2) / 2;
|
|
4634
|
+
const diff = m1 - m2;
|
|
4635
|
+
points.push({ mean, diff });
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
if (points.length === 0)
|
|
4639
|
+
return;
|
|
4640
|
+
const diffs = points.map((p) => p.diff);
|
|
4641
|
+
const bias = diffs.reduce((a, b) => a + b, 0) / diffs.length;
|
|
4642
|
+
const variance = diffs.reduce((a, b) => a + Math.pow(b - bias, 2), 0) / (diffs.length - 1);
|
|
4643
|
+
const sd = Math.sqrt(variance);
|
|
4644
|
+
const upperLimit = bias + limitMultiplier * sd;
|
|
4645
|
+
const lowerLimit = bias - limitMultiplier * sd;
|
|
4646
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
4647
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
4648
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
4649
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
4650
|
+
const minMean = Math.min(...points.map((p) => p.mean));
|
|
4651
|
+
const maxMean = Math.max(...points.map((p) => p.mean));
|
|
4652
|
+
const minDiff = Math.min(...points.map((p) => p.diff), lowerLimit);
|
|
4653
|
+
const maxDiff = Math.max(...points.map((p) => p.diff), upperLimit);
|
|
4654
|
+
const mapX = (v) => plotLeft + (v - minMean) / (maxMean - minMean) * (plotRight - plotLeft);
|
|
4655
|
+
const mapY = (v) => plotBottom - (v - minDiff) / (maxDiff - minDiff) * (plotBottom - plotTop);
|
|
4656
|
+
if (showBias) {
|
|
4657
|
+
const biasY = Math.round(mapY(bias));
|
|
4658
|
+
for (let x = plotLeft;x <= plotRight; x++) {
|
|
4659
|
+
canvas.drawChar(x, biasY, "─", biasColorParsed);
|
|
4660
|
+
}
|
|
4661
|
+
}
|
|
4662
|
+
if (showLimits) {
|
|
4663
|
+
const upperY = Math.round(mapY(upperLimit));
|
|
4664
|
+
const lowerY = Math.round(mapY(lowerLimit));
|
|
4665
|
+
for (let x = plotLeft;x <= plotRight; x += 2) {
|
|
4666
|
+
canvas.drawChar(x, upperY, "─", limitColorParsed);
|
|
4667
|
+
canvas.drawChar(x, lowerY, "─", limitColorParsed);
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
const pointColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
4671
|
+
for (const p of points) {
|
|
4672
|
+
const x = Math.round(mapX(p.mean));
|
|
4673
|
+
const y = Math.round(mapY(p.diff));
|
|
4674
|
+
canvas.drawChar(x, y, pointChar, pointColor);
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
function renderGeomQQ(data, geom, aes, scales, canvas) {
|
|
4678
|
+
const params = geom.params || {};
|
|
4679
|
+
const showLine = params.show_line ?? true;
|
|
4680
|
+
const lineColor = params.line_color ?? "#ff0000";
|
|
4681
|
+
const pointChar = params.point_char ?? "●";
|
|
4682
|
+
const standardize = params.standardize ?? true;
|
|
4683
|
+
const parseHex = (hex) => {
|
|
4684
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
4685
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
4686
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
4687
|
+
return { r, g, b, a: 1 };
|
|
4688
|
+
};
|
|
4689
|
+
const lineColorParsed = parseHex(lineColor);
|
|
4690
|
+
const sampleField = typeof aes.x === "string" ? aes.x : "x";
|
|
4691
|
+
const values = [];
|
|
4692
|
+
for (const row of data) {
|
|
4693
|
+
const v = Number(row[sampleField]);
|
|
4694
|
+
if (!isNaN(v))
|
|
4695
|
+
values.push(v);
|
|
4696
|
+
}
|
|
4697
|
+
if (values.length === 0)
|
|
4698
|
+
return;
|
|
4699
|
+
values.sort((a, b) => a - b);
|
|
4700
|
+
const n = values.length;
|
|
4701
|
+
const mean = values.reduce((a, b) => a + b, 0) / n;
|
|
4702
|
+
const variance = values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / (n - 1);
|
|
4703
|
+
const sd = Math.sqrt(variance);
|
|
4704
|
+
const qnorm = (p) => {
|
|
4705
|
+
if (p <= 0)
|
|
4706
|
+
return -Infinity;
|
|
4707
|
+
if (p >= 1)
|
|
4708
|
+
return Infinity;
|
|
4709
|
+
if (p === 0.5)
|
|
4710
|
+
return 0;
|
|
4711
|
+
const a = [
|
|
4712
|
+
-39.69683028665376,
|
|
4713
|
+
220.9460984245205,
|
|
4714
|
+
-275.9285104469687,
|
|
4715
|
+
138.357751867269,
|
|
4716
|
+
-30.66479806614716,
|
|
4717
|
+
2.506628277459239
|
|
4718
|
+
];
|
|
4719
|
+
const b = [
|
|
4720
|
+
-54.47609879822406,
|
|
4721
|
+
161.5858368580409,
|
|
4722
|
+
-155.6989798598866,
|
|
4723
|
+
66.80131188771972,
|
|
4724
|
+
-13.28068155288572
|
|
4725
|
+
];
|
|
4726
|
+
const c = [
|
|
4727
|
+
-0.007784894002430293,
|
|
4728
|
+
-0.3223964580411365,
|
|
4729
|
+
-2.400758277161838,
|
|
4730
|
+
-2.549732539343734,
|
|
4731
|
+
4.374664141464968,
|
|
4732
|
+
2.938163982698783
|
|
4733
|
+
];
|
|
4734
|
+
const d = [
|
|
4735
|
+
0.007784695709041462,
|
|
4736
|
+
0.3224671290700398,
|
|
4737
|
+
2.445134137142996,
|
|
4738
|
+
3.754408661907416
|
|
4739
|
+
];
|
|
4740
|
+
const pLow = 0.02425;
|
|
4741
|
+
const pHigh = 1 - pLow;
|
|
4742
|
+
let q;
|
|
4743
|
+
if (p < pLow) {
|
|
4744
|
+
q = Math.sqrt(-2 * Math.log(p));
|
|
4745
|
+
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);
|
|
4746
|
+
} else if (p <= pHigh) {
|
|
4747
|
+
q = p - 0.5;
|
|
4748
|
+
const r = q * q;
|
|
4749
|
+
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);
|
|
4750
|
+
} else {
|
|
4751
|
+
q = Math.sqrt(-2 * Math.log(1 - p));
|
|
4752
|
+
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);
|
|
4753
|
+
}
|
|
4754
|
+
};
|
|
4755
|
+
const points = [];
|
|
4756
|
+
for (let i = 0;i < n; i++) {
|
|
4757
|
+
const p = (i + 0.5) / n;
|
|
4758
|
+
const theoretical = qnorm(p);
|
|
4759
|
+
const sample = standardize ? (values[i] - mean) / sd : values[i];
|
|
4760
|
+
points.push({ theoretical, sample });
|
|
4761
|
+
}
|
|
4762
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
4763
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
4764
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
4765
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
4766
|
+
const minT = Math.min(...points.map((p) => p.theoretical));
|
|
4767
|
+
const maxT = Math.max(...points.map((p) => p.theoretical));
|
|
4768
|
+
const minS = Math.min(...points.map((p) => p.sample));
|
|
4769
|
+
const maxS = Math.max(...points.map((p) => p.sample));
|
|
4770
|
+
const minVal = Math.min(minT, minS);
|
|
4771
|
+
const maxVal = Math.max(maxT, maxS);
|
|
4772
|
+
const mapX = (v) => plotLeft + (v - minVal) / (maxVal - minVal) * (plotRight - plotLeft);
|
|
4773
|
+
const mapY = (v) => plotBottom - (v - minVal) / (maxVal - minVal) * (plotBottom - plotTop);
|
|
4774
|
+
if (showLine) {
|
|
4775
|
+
const steps = plotRight - plotLeft;
|
|
4776
|
+
for (let i = 0;i <= steps; i++) {
|
|
4777
|
+
const v = minVal + i / steps * (maxVal - minVal);
|
|
4778
|
+
const x = Math.round(mapX(v));
|
|
4779
|
+
const y = Math.round(mapY(v));
|
|
4780
|
+
if (y >= plotTop && y <= plotBottom) {
|
|
4781
|
+
canvas.drawChar(x, y, "─", lineColorParsed);
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
const pointColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
4786
|
+
for (const p of points) {
|
|
4787
|
+
const x = Math.round(mapX(p.theoretical));
|
|
4788
|
+
const y = Math.round(mapY(p.sample));
|
|
4789
|
+
canvas.drawChar(x, y, pointChar, pointColor);
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
function renderGeomECDF(data, geom, aes, scales, canvas) {
|
|
4793
|
+
const params = geom.params || {};
|
|
4794
|
+
const complement = params.complement ?? false;
|
|
4795
|
+
const showPoints = params.show_points ?? false;
|
|
4796
|
+
const xField = typeof aes.x === "string" ? aes.x : "x";
|
|
4797
|
+
const colorField = typeof aes.color === "string" ? aes.color : null;
|
|
4798
|
+
const groups = new Map;
|
|
4799
|
+
for (const row of data) {
|
|
4800
|
+
const v = Number(row[xField]);
|
|
4801
|
+
if (isNaN(v))
|
|
4802
|
+
continue;
|
|
4803
|
+
const groupKey = colorField ? String(row[colorField] ?? "default") : "default";
|
|
4804
|
+
if (!groups.has(groupKey))
|
|
4805
|
+
groups.set(groupKey, []);
|
|
4806
|
+
groups.get(groupKey).push(v);
|
|
4807
|
+
}
|
|
4808
|
+
if (groups.size === 0)
|
|
4809
|
+
return;
|
|
4810
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
4811
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
4812
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
4813
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
4814
|
+
let globalMin = Infinity;
|
|
4815
|
+
let globalMax = -Infinity;
|
|
4816
|
+
for (const values of groups.values()) {
|
|
4817
|
+
globalMin = Math.min(globalMin, ...values);
|
|
4818
|
+
globalMax = Math.max(globalMax, ...values);
|
|
4819
|
+
}
|
|
4820
|
+
const mapX = (v) => plotLeft + (v - globalMin) / (globalMax - globalMin) * (plotRight - plotLeft);
|
|
4821
|
+
const mapY = (v) => {
|
|
4822
|
+
const ecdf = complement ? 1 - v : v;
|
|
4823
|
+
return plotBottom - ecdf * (plotBottom - plotTop);
|
|
4824
|
+
};
|
|
4825
|
+
const colors = [
|
|
4826
|
+
{ r: 31, g: 119, b: 180, a: 1 },
|
|
4827
|
+
{ r: 255, g: 127, b: 14, a: 1 },
|
|
4828
|
+
{ r: 44, g: 160, b: 44, a: 1 },
|
|
4829
|
+
{ r: 214, g: 39, b: 40, a: 1 },
|
|
4830
|
+
{ r: 148, g: 103, b: 189, a: 1 }
|
|
4831
|
+
];
|
|
4832
|
+
let colorIdx = 0;
|
|
4833
|
+
for (const [, values] of groups) {
|
|
4834
|
+
const color = colors[colorIdx % colors.length];
|
|
4835
|
+
colorIdx++;
|
|
4836
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
4837
|
+
const n = sorted.length;
|
|
4838
|
+
let prevX = plotLeft;
|
|
4839
|
+
let prevY = Math.round(mapY(0));
|
|
4840
|
+
for (let i = 0;i < n; i++) {
|
|
4841
|
+
const ecdfVal = (i + 1) / n;
|
|
4842
|
+
const x = Math.round(mapX(sorted[i]));
|
|
4843
|
+
const y = Math.round(mapY(ecdfVal));
|
|
4844
|
+
for (let px = prevX;px <= x; px++) {
|
|
4845
|
+
canvas.drawChar(px, prevY, "─", color);
|
|
4846
|
+
}
|
|
4847
|
+
const stepDir = y < prevY ? -1 : 1;
|
|
4848
|
+
for (let py = prevY;stepDir > 0 ? py <= y : py >= y; py += stepDir) {
|
|
4849
|
+
canvas.drawChar(x, py, "│", color);
|
|
4850
|
+
}
|
|
4851
|
+
if (showPoints) {
|
|
4852
|
+
canvas.drawChar(x, y, "●", color);
|
|
4853
|
+
}
|
|
4854
|
+
prevX = x;
|
|
4855
|
+
prevY = y;
|
|
4856
|
+
}
|
|
4857
|
+
for (let px = prevX;px <= plotRight; px++) {
|
|
4858
|
+
canvas.drawChar(px, prevY, "─", color);
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
function renderGeomFunnel(data, geom, aes, scales, canvas) {
|
|
4863
|
+
const params = geom.params || {};
|
|
4864
|
+
const showContours = params.show_contours ?? true;
|
|
4865
|
+
const showSummaryLine = params.show_summary_line ?? true;
|
|
4866
|
+
const summaryEffect = params.summary_effect;
|
|
4867
|
+
const pointChar = params.point_char ?? "●";
|
|
4868
|
+
const contourColor = params.contour_color ?? "#888888";
|
|
4869
|
+
const invertY = params.invert_y ?? true;
|
|
4870
|
+
const parseHex = (hex) => {
|
|
4871
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
4872
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
4873
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
4874
|
+
return { r, g, b, a: 1 };
|
|
4875
|
+
};
|
|
4876
|
+
const contourColorParsed = parseHex(contourColor);
|
|
4877
|
+
const xField = typeof aes.x === "string" ? aes.x : "effect";
|
|
4878
|
+
const yField = typeof aes.y === "string" ? aes.y : "se";
|
|
4879
|
+
const points = [];
|
|
4880
|
+
for (const row of data) {
|
|
4881
|
+
const effect = Number(row[xField]);
|
|
4882
|
+
const se = Number(row[yField]);
|
|
4883
|
+
if (!isNaN(effect) && !isNaN(se)) {
|
|
4884
|
+
points.push({ effect, se });
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
if (points.length === 0)
|
|
4888
|
+
return;
|
|
4889
|
+
const summary = summaryEffect ?? points.reduce((a, b) => a + b.effect, 0) / points.length;
|
|
4890
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
4891
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
4892
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
4893
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
4894
|
+
const minEffect = Math.min(...points.map((p) => p.effect));
|
|
4895
|
+
const maxEffect = Math.max(...points.map((p) => p.effect));
|
|
4896
|
+
const maxSE = Math.max(...points.map((p) => p.se));
|
|
4897
|
+
const effectPad = (maxEffect - minEffect) * 0.2;
|
|
4898
|
+
const effectMin = minEffect - effectPad;
|
|
4899
|
+
const effectMax = maxEffect + effectPad;
|
|
4900
|
+
const mapX = (v) => plotLeft + (v - effectMin) / (effectMax - effectMin) * (plotRight - plotLeft);
|
|
4901
|
+
const mapY = (v) => {
|
|
4902
|
+
if (invertY) {
|
|
4903
|
+
return plotTop + v / maxSE * (plotBottom - plotTop);
|
|
4904
|
+
}
|
|
4905
|
+
return plotBottom - v / maxSE * (plotBottom - plotTop);
|
|
4906
|
+
};
|
|
4907
|
+
if (showContours) {
|
|
4908
|
+
const z = 1.96;
|
|
4909
|
+
for (let se = 0;se <= maxSE; se += maxSE / 40) {
|
|
4910
|
+
const leftBound = summary - z * se;
|
|
4911
|
+
const rightBound = summary + z * se;
|
|
4912
|
+
const y = Math.round(mapY(se));
|
|
4913
|
+
const leftX = Math.round(mapX(leftBound));
|
|
4914
|
+
const rightX = Math.round(mapX(rightBound));
|
|
4915
|
+
if (leftX >= plotLeft && leftX <= plotRight) {
|
|
4916
|
+
canvas.drawChar(leftX, y, "·", contourColorParsed);
|
|
4917
|
+
}
|
|
4918
|
+
if (rightX >= plotLeft && rightX <= plotRight) {
|
|
4919
|
+
canvas.drawChar(rightX, y, "·", contourColorParsed);
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
4923
|
+
if (showSummaryLine) {
|
|
4924
|
+
const summaryX = Math.round(mapX(summary));
|
|
4925
|
+
for (let y = plotTop;y <= plotBottom; y += 2) {
|
|
4926
|
+
canvas.drawChar(summaryX, y, "│", contourColorParsed);
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
const pointColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
4930
|
+
for (const p of points) {
|
|
4931
|
+
const x = Math.round(mapX(p.effect));
|
|
4932
|
+
const y = Math.round(mapY(p.se));
|
|
4933
|
+
canvas.drawChar(x, y, pointChar, pointColor);
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4936
|
+
function renderGeomControl(data, geom, aes, scales, canvas) {
|
|
4937
|
+
const params = geom.params || {};
|
|
4938
|
+
const sigma = params.sigma ?? 3;
|
|
4939
|
+
const showCenter = params.show_center ?? true;
|
|
4940
|
+
const showUCL = params.show_ucl ?? true;
|
|
4941
|
+
const showLCL = params.show_lcl ?? true;
|
|
4942
|
+
const showWarning = params.show_warning ?? false;
|
|
4943
|
+
const customCenter = params.center;
|
|
4944
|
+
const customUCL = params.ucl;
|
|
4945
|
+
const customLCL = params.lcl;
|
|
4946
|
+
const centerColor = params.center_color ?? "#0000ff";
|
|
4947
|
+
const limitColor = params.limit_color ?? "#ff0000";
|
|
4948
|
+
const warningColor = params.warning_color ?? "#ffa500";
|
|
4949
|
+
const connectPoints = params.connect_points ?? true;
|
|
4950
|
+
const highlightOOC = params.highlight_ooc ?? true;
|
|
4951
|
+
const oocChar = params.ooc_char ?? "◆";
|
|
4952
|
+
const pointChar = params.point_char ?? "●";
|
|
4953
|
+
const parseHex = (hex) => {
|
|
4954
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
4955
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
4956
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
4957
|
+
return { r, g, b, a: 1 };
|
|
4958
|
+
};
|
|
4959
|
+
const centerColorParsed = parseHex(centerColor);
|
|
4960
|
+
const limitColorParsed = parseHex(limitColor);
|
|
4961
|
+
const warningColorParsed = parseHex(warningColor);
|
|
4962
|
+
const xField = typeof aes.x === "string" ? aes.x : "x";
|
|
4963
|
+
const yField = typeof aes.y === "string" ? aes.y : "y";
|
|
4964
|
+
const points = [];
|
|
4965
|
+
for (const row of data) {
|
|
4966
|
+
const x = Number(row[xField]);
|
|
4967
|
+
const y = Number(row[yField]);
|
|
4968
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
4969
|
+
points.push({ x, y });
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
if (points.length === 0)
|
|
4973
|
+
return;
|
|
4974
|
+
points.sort((a, b) => a.x - b.x);
|
|
4975
|
+
const yValues = points.map((p) => p.y);
|
|
4976
|
+
const mean = customCenter ?? yValues.reduce((a, b) => a + b, 0) / yValues.length;
|
|
4977
|
+
let sigmaEst;
|
|
4978
|
+
if (points.length > 1) {
|
|
4979
|
+
const movingRanges = [];
|
|
4980
|
+
for (let i = 1;i < points.length; i++) {
|
|
4981
|
+
movingRanges.push(Math.abs(points[i].y - points[i - 1].y));
|
|
4982
|
+
}
|
|
4983
|
+
const avgMR = movingRanges.reduce((a, b) => a + b, 0) / movingRanges.length;
|
|
4984
|
+
sigmaEst = avgMR / 1.128;
|
|
4985
|
+
} else {
|
|
4986
|
+
const variance = yValues.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / (yValues.length - 1);
|
|
4987
|
+
sigmaEst = Math.sqrt(variance);
|
|
4988
|
+
}
|
|
4989
|
+
const ucl = customUCL ?? mean + sigma * sigmaEst;
|
|
4990
|
+
const lcl = customLCL ?? mean - sigma * sigmaEst;
|
|
4991
|
+
const uwl = mean + 2 * sigmaEst;
|
|
4992
|
+
const lwl = mean - 2 * sigmaEst;
|
|
4993
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
4994
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
4995
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
4996
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
4997
|
+
const minX = Math.min(...points.map((p) => p.x));
|
|
4998
|
+
const maxX = Math.max(...points.map((p) => p.x));
|
|
4999
|
+
const minY = Math.min(...points.map((p) => p.y), lcl);
|
|
5000
|
+
const maxY = Math.max(...points.map((p) => p.y), ucl);
|
|
5001
|
+
const mapX = (v) => plotLeft + (v - minX) / (maxX - minX) * (plotRight - plotLeft);
|
|
5002
|
+
const mapY = (v) => plotBottom - (v - minY) / (maxY - minY) * (plotBottom - plotTop);
|
|
5003
|
+
if (showCenter) {
|
|
5004
|
+
const centerY = Math.round(mapY(mean));
|
|
5005
|
+
for (let x = plotLeft;x <= plotRight; x++) {
|
|
5006
|
+
canvas.drawChar(x, centerY, "─", centerColorParsed);
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
if (showUCL) {
|
|
5010
|
+
const uclY = Math.round(mapY(ucl));
|
|
5011
|
+
for (let x = plotLeft;x <= plotRight; x += 2) {
|
|
5012
|
+
canvas.drawChar(x, uclY, "─", limitColorParsed);
|
|
5013
|
+
}
|
|
5014
|
+
}
|
|
5015
|
+
if (showLCL) {
|
|
5016
|
+
const lclY = Math.round(mapY(lcl));
|
|
5017
|
+
for (let x = plotLeft;x <= plotRight; x += 2) {
|
|
5018
|
+
canvas.drawChar(x, lclY, "─", limitColorParsed);
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
if (showWarning) {
|
|
5022
|
+
const uwlY = Math.round(mapY(uwl));
|
|
5023
|
+
const lwlY = Math.round(mapY(lwl));
|
|
5024
|
+
for (let x = plotLeft;x <= plotRight; x += 3) {
|
|
5025
|
+
canvas.drawChar(x, uwlY, "·", warningColorParsed);
|
|
5026
|
+
canvas.drawChar(x, lwlY, "·", warningColorParsed);
|
|
5027
|
+
}
|
|
5028
|
+
}
|
|
5029
|
+
if (connectPoints && points.length > 1) {
|
|
5030
|
+
const lineColor = { r: 100, g: 100, b: 100, a: 1 };
|
|
5031
|
+
for (let i = 1;i < points.length; i++) {
|
|
5032
|
+
const x1 = Math.round(mapX(points[i - 1].x));
|
|
5033
|
+
const y1 = Math.round(mapY(points[i - 1].y));
|
|
5034
|
+
const x2 = Math.round(mapX(points[i].x));
|
|
5035
|
+
const y2 = Math.round(mapY(points[i].y));
|
|
5036
|
+
const dx = Math.abs(x2 - x1);
|
|
5037
|
+
const dy = Math.abs(y2 - y1);
|
|
5038
|
+
const sx = x1 < x2 ? 1 : -1;
|
|
5039
|
+
const sy = y1 < y2 ? 1 : -1;
|
|
5040
|
+
let err = dx - dy;
|
|
5041
|
+
let x = x1;
|
|
5042
|
+
let y = y1;
|
|
5043
|
+
while (true) {
|
|
5044
|
+
canvas.drawChar(x, y, "·", lineColor);
|
|
5045
|
+
if (x === x2 && y === y2)
|
|
5046
|
+
break;
|
|
5047
|
+
const e2 = 2 * err;
|
|
5048
|
+
if (e2 > -dy) {
|
|
5049
|
+
err -= dy;
|
|
5050
|
+
x += sx;
|
|
5051
|
+
}
|
|
5052
|
+
if (e2 < dx) {
|
|
5053
|
+
err += dx;
|
|
5054
|
+
y += sy;
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
const inControlColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
5060
|
+
const oocColor = { r: 214, g: 39, b: 40, a: 1 };
|
|
5061
|
+
for (const p of points) {
|
|
5062
|
+
const x = Math.round(mapX(p.x));
|
|
5063
|
+
const y = Math.round(mapY(p.y));
|
|
5064
|
+
const isOOC = p.y > ucl || p.y < lcl;
|
|
5065
|
+
if (highlightOOC && isOOC) {
|
|
5066
|
+
canvas.drawChar(x, y, oocChar, oocColor);
|
|
5067
|
+
} else {
|
|
5068
|
+
canvas.drawChar(x, y, pointChar, inControlColor);
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
}
|
|
5072
|
+
function renderGeomScree(data, geom, aes, scales, canvas) {
|
|
5073
|
+
const params = geom.params || {};
|
|
5074
|
+
const showCumulative = params.show_cumulative ?? false;
|
|
5075
|
+
const showKaiser = params.show_kaiser ?? false;
|
|
5076
|
+
const connectPoints = params.connect_points ?? true;
|
|
5077
|
+
const showBars = params.show_bars ?? false;
|
|
5078
|
+
const pointChar = params.point_char ?? "●";
|
|
5079
|
+
const cumulativeColor = params.cumulative_color ?? "#ff0000";
|
|
5080
|
+
const kaiserColor = params.kaiser_color ?? "#888888";
|
|
5081
|
+
const threshold = params.threshold;
|
|
5082
|
+
const thresholdColor = params.threshold_color ?? "#00aa00";
|
|
5083
|
+
const parseHex = (hex) => {
|
|
5084
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
5085
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
5086
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
5087
|
+
return { r, g, b, a: 1 };
|
|
5088
|
+
};
|
|
5089
|
+
const cumulativeColorParsed = parseHex(cumulativeColor);
|
|
5090
|
+
const kaiserColorParsed = parseHex(kaiserColor);
|
|
5091
|
+
const thresholdColorParsed = parseHex(thresholdColor);
|
|
5092
|
+
const xField = typeof aes.x === "string" ? aes.x : "component";
|
|
5093
|
+
const yField = typeof aes.y === "string" ? aes.y : "variance";
|
|
5094
|
+
const points = [];
|
|
5095
|
+
for (const row of data) {
|
|
5096
|
+
const component = Number(row[xField]);
|
|
5097
|
+
const variance = Number(row[yField]);
|
|
5098
|
+
if (!isNaN(component) && !isNaN(variance)) {
|
|
5099
|
+
points.push({ component, variance });
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
if (points.length === 0)
|
|
5103
|
+
return;
|
|
5104
|
+
points.sort((a, b) => a.component - b.component);
|
|
5105
|
+
const total = points.reduce((a, b) => a + b.variance, 0);
|
|
5106
|
+
let cumSum = 0;
|
|
5107
|
+
const cumulativePoints = points.map((p) => {
|
|
5108
|
+
cumSum += p.variance;
|
|
5109
|
+
return { component: p.component, cumulative: cumSum / total };
|
|
5110
|
+
});
|
|
5111
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
5112
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
5113
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
5114
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
5115
|
+
const minX = Math.min(...points.map((p) => p.component));
|
|
5116
|
+
const maxX = Math.max(...points.map((p) => p.component));
|
|
5117
|
+
const maxY = Math.max(...points.map((p) => p.variance));
|
|
5118
|
+
const yMax = showCumulative ? Math.max(maxY, total) : maxY;
|
|
5119
|
+
const mapX = (v) => plotLeft + (v - minX) / (maxX - minX) * (plotRight - plotLeft);
|
|
5120
|
+
const mapY = (v) => plotBottom - v / yMax * (plotBottom - plotTop);
|
|
5121
|
+
const mapYCumulative = (v) => plotBottom - v * (plotBottom - plotTop);
|
|
5122
|
+
if (showKaiser) {
|
|
5123
|
+
const kaiserY = Math.round(mapY(1));
|
|
5124
|
+
if (kaiserY >= plotTop && kaiserY <= plotBottom) {
|
|
5125
|
+
for (let x = plotLeft;x <= plotRight; x += 2) {
|
|
5126
|
+
canvas.drawChar(x, kaiserY, "─", kaiserColorParsed);
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
if (threshold !== undefined) {
|
|
5131
|
+
const thresholdY = Math.round(mapYCumulative(threshold));
|
|
5132
|
+
for (let x = plotLeft;x <= plotRight; x += 2) {
|
|
5133
|
+
canvas.drawChar(x, thresholdY, "─", thresholdColorParsed);
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
if (showBars) {
|
|
5137
|
+
const barColor = { r: 180, g: 180, b: 180, a: 1 };
|
|
5138
|
+
const barWidth = Math.max(1, Math.floor((plotRight - plotLeft) / points.length / 2));
|
|
5139
|
+
for (const p of points) {
|
|
5140
|
+
const x = Math.round(mapX(p.component));
|
|
5141
|
+
const y = Math.round(mapY(p.variance));
|
|
5142
|
+
for (let bx = x - barWidth;bx <= x + barWidth; bx++) {
|
|
5143
|
+
for (let by = y;by <= plotBottom; by++) {
|
|
5144
|
+
canvas.drawChar(bx, by, "░", barColor);
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
}
|
|
5149
|
+
if (connectPoints && points.length > 1) {
|
|
5150
|
+
const lineColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
5151
|
+
for (let i = 1;i < points.length; i++) {
|
|
5152
|
+
const x1 = Math.round(mapX(points[i - 1].component));
|
|
5153
|
+
const y1 = Math.round(mapY(points[i - 1].variance));
|
|
5154
|
+
const x2 = Math.round(mapX(points[i].component));
|
|
5155
|
+
const y2 = Math.round(mapY(points[i].variance));
|
|
5156
|
+
const steps = Math.max(Math.abs(x2 - x1), 1);
|
|
5157
|
+
for (let s = 0;s <= steps; s++) {
|
|
5158
|
+
const t = s / steps;
|
|
5159
|
+
const x = Math.round(x1 + t * (x2 - x1));
|
|
5160
|
+
const y = Math.round(y1 + t * (y2 - y1));
|
|
5161
|
+
canvas.drawChar(x, y, "─", lineColor);
|
|
5162
|
+
}
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
if (showCumulative && cumulativePoints.length > 1) {
|
|
5166
|
+
for (let i = 1;i < cumulativePoints.length; i++) {
|
|
5167
|
+
const x1 = Math.round(mapX(cumulativePoints[i - 1].component));
|
|
5168
|
+
const y1 = Math.round(mapYCumulative(cumulativePoints[i - 1].cumulative));
|
|
5169
|
+
const x2 = Math.round(mapX(cumulativePoints[i].component));
|
|
5170
|
+
const y2 = Math.round(mapYCumulative(cumulativePoints[i].cumulative));
|
|
5171
|
+
const steps = Math.max(Math.abs(x2 - x1), 1);
|
|
5172
|
+
for (let s = 0;s <= steps; s++) {
|
|
5173
|
+
const t = s / steps;
|
|
5174
|
+
const x = Math.round(x1 + t * (x2 - x1));
|
|
5175
|
+
const y = Math.round(y1 + t * (y2 - y1));
|
|
5176
|
+
canvas.drawChar(x, y, "─", cumulativeColorParsed);
|
|
5177
|
+
}
|
|
5178
|
+
}
|
|
5179
|
+
for (const p of cumulativePoints) {
|
|
5180
|
+
const x = Math.round(mapX(p.component));
|
|
5181
|
+
const y = Math.round(mapYCumulative(p.cumulative));
|
|
5182
|
+
canvas.drawChar(x, y, "○", cumulativeColorParsed);
|
|
5183
|
+
}
|
|
5184
|
+
}
|
|
5185
|
+
const pointColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
5186
|
+
for (const p of points) {
|
|
5187
|
+
const x = Math.round(mapX(p.component));
|
|
5188
|
+
const y = Math.round(mapY(p.variance));
|
|
5189
|
+
canvas.drawChar(x, y, pointChar, pointColor);
|
|
5190
|
+
}
|
|
5191
|
+
}
|
|
3723
5192
|
function renderGeom(data, geom, aes, scales, canvas, coordType) {
|
|
3724
5193
|
switch (geom.type) {
|
|
3725
5194
|
case "point":
|
|
@@ -3848,10 +5317,455 @@ function renderGeom(data, geom, aes, scales, canvas, coordType) {
|
|
|
3848
5317
|
case "volcano":
|
|
3849
5318
|
renderGeomVolcano(data, geom, aes, scales, canvas);
|
|
3850
5319
|
break;
|
|
5320
|
+
case "ma":
|
|
5321
|
+
renderGeomMA(data, geom, aes, scales, canvas);
|
|
5322
|
+
break;
|
|
5323
|
+
case "manhattan":
|
|
5324
|
+
renderGeomManhattan(data, geom, aes, scales, canvas);
|
|
5325
|
+
break;
|
|
5326
|
+
case "heatmap":
|
|
5327
|
+
renderGeomHeatmap(data, geom, aes, scales, canvas);
|
|
5328
|
+
break;
|
|
5329
|
+
case "biplot":
|
|
5330
|
+
renderGeomBiplot(data, geom, aes, scales, canvas);
|
|
5331
|
+
break;
|
|
5332
|
+
case "kaplan_meier":
|
|
5333
|
+
renderGeomKaplanMeier(data, geom, aes, scales, canvas);
|
|
5334
|
+
break;
|
|
5335
|
+
case "forest":
|
|
5336
|
+
renderGeomForest(data, geom, aes, scales, canvas);
|
|
5337
|
+
break;
|
|
5338
|
+
case "roc":
|
|
5339
|
+
renderGeomRoc(data, geom, aes, scales, canvas);
|
|
5340
|
+
break;
|
|
5341
|
+
case "bland_altman":
|
|
5342
|
+
renderGeomBlandAltman(data, geom, aes, scales, canvas);
|
|
5343
|
+
break;
|
|
5344
|
+
case "qq":
|
|
5345
|
+
renderGeomQQ(data, geom, aes, scales, canvas);
|
|
5346
|
+
break;
|
|
5347
|
+
case "ecdf":
|
|
5348
|
+
renderGeomECDF(data, geom, aes, scales, canvas);
|
|
5349
|
+
break;
|
|
5350
|
+
case "funnel":
|
|
5351
|
+
renderGeomFunnel(data, geom, aes, scales, canvas);
|
|
5352
|
+
break;
|
|
5353
|
+
case "control":
|
|
5354
|
+
renderGeomControl(data, geom, aes, scales, canvas);
|
|
5355
|
+
break;
|
|
5356
|
+
case "scree":
|
|
5357
|
+
renderGeomScree(data, geom, aes, scales, canvas);
|
|
5358
|
+
break;
|
|
5359
|
+
case "upset":
|
|
5360
|
+
renderGeomUpset(data, geom, aes, scales, canvas);
|
|
5361
|
+
break;
|
|
5362
|
+
case "dendrogram":
|
|
5363
|
+
renderGeomDendrogram(data, geom, aes, scales, canvas);
|
|
5364
|
+
break;
|
|
3851
5365
|
default:
|
|
3852
5366
|
break;
|
|
3853
5367
|
}
|
|
3854
5368
|
}
|
|
5369
|
+
function renderGeomUpset(data, geom, aes, scales, canvas) {
|
|
5370
|
+
const params = geom.params || {};
|
|
5371
|
+
const sets = params.sets;
|
|
5372
|
+
const minSize = params.min_size ?? 1;
|
|
5373
|
+
const maxIntersections = params.max_intersections ?? 20;
|
|
5374
|
+
const sortBy = params.sort_by ?? "size";
|
|
5375
|
+
const sortOrder = params.sort_order ?? "desc";
|
|
5376
|
+
const showSetSizes = params.show_set_sizes ?? true;
|
|
5377
|
+
const dotChar = params.dot_char ?? "●";
|
|
5378
|
+
const emptyChar = params.empty_char ?? "○";
|
|
5379
|
+
const lineChar = params.line_char ?? "│";
|
|
5380
|
+
const barChar = params.bar_char ?? "█";
|
|
5381
|
+
let setNames = [];
|
|
5382
|
+
if (sets && sets.length > 0) {
|
|
5383
|
+
setNames = sets;
|
|
5384
|
+
} else if (data.length > 0) {
|
|
5385
|
+
const firstRow = data[0];
|
|
5386
|
+
for (const key of Object.keys(firstRow)) {
|
|
5387
|
+
const values = data.map((row) => row[key]);
|
|
5388
|
+
const isBinary = values.every((v) => v === 0 || v === 1 || v === "0" || v === "1");
|
|
5389
|
+
if (isBinary && key !== "id" && key !== "name" && key !== "element") {
|
|
5390
|
+
setNames.push(key);
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
if (setNames.length === 0) {
|
|
5394
|
+
const setsField2 = typeof aes.x === "string" ? aes.x : "sets";
|
|
5395
|
+
const allSets = new Set;
|
|
5396
|
+
for (const row of data) {
|
|
5397
|
+
const val = row[setsField2];
|
|
5398
|
+
if (typeof val === "string") {
|
|
5399
|
+
val.split(",").forEach((s) => allSets.add(s.trim()));
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
setNames = Array.from(allSets).sort();
|
|
5403
|
+
}
|
|
5404
|
+
}
|
|
5405
|
+
if (setNames.length === 0)
|
|
5406
|
+
return;
|
|
5407
|
+
const intersectionMap = new Map;
|
|
5408
|
+
const setsField = typeof aes.x === "string" ? aes.x : "sets";
|
|
5409
|
+
const hasListFormat = data.length > 0 && typeof data[0][setsField] === "string";
|
|
5410
|
+
for (const row of data) {
|
|
5411
|
+
let memberSets;
|
|
5412
|
+
if (hasListFormat) {
|
|
5413
|
+
const val = row[setsField];
|
|
5414
|
+
memberSets = typeof val === "string" ? val.split(",").map((s) => s.trim()).filter((s) => setNames.includes(s)) : [];
|
|
5415
|
+
} else {
|
|
5416
|
+
memberSets = setNames.filter((s) => {
|
|
5417
|
+
const v = row[s];
|
|
5418
|
+
return v === 1 || v === "1";
|
|
5419
|
+
});
|
|
5420
|
+
}
|
|
5421
|
+
if (memberSets.length > 0) {
|
|
5422
|
+
const key = memberSets.sort().join("|");
|
|
5423
|
+
intersectionMap.set(key, (intersectionMap.get(key) || 0) + 1);
|
|
5424
|
+
}
|
|
5425
|
+
}
|
|
5426
|
+
let intersections = Array.from(intersectionMap.entries()).map(([key, count]) => ({
|
|
5427
|
+
sets: new Set(key.split("|")),
|
|
5428
|
+
count,
|
|
5429
|
+
key
|
|
5430
|
+
})).filter((i) => i.count >= minSize);
|
|
5431
|
+
if (sortBy === "size") {
|
|
5432
|
+
intersections.sort((a, b) => sortOrder === "desc" ? b.count - a.count : a.count - b.count);
|
|
5433
|
+
} else if (sortBy === "degree") {
|
|
5434
|
+
intersections.sort((a, b) => sortOrder === "desc" ? b.sets.size - a.sets.size : a.sets.size - b.sets.size);
|
|
5435
|
+
}
|
|
5436
|
+
intersections = intersections.slice(0, maxIntersections);
|
|
5437
|
+
if (intersections.length === 0)
|
|
5438
|
+
return;
|
|
5439
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
5440
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
5441
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
5442
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
5443
|
+
const plotWidth = plotRight - plotLeft;
|
|
5444
|
+
const plotHeight = plotBottom - plotTop;
|
|
5445
|
+
const matrixHeight = Math.min(setNames.length * 2 + 2, Math.floor(plotHeight * 0.4));
|
|
5446
|
+
const barHeight = plotHeight - matrixHeight - 2;
|
|
5447
|
+
const barTop = plotTop;
|
|
5448
|
+
const barBottom = plotTop + barHeight;
|
|
5449
|
+
const matrixTop = barBottom + 2;
|
|
5450
|
+
const setLabelWidth = showSetSizes ? Math.max(...setNames.map((s) => s.length)) + 8 : 0;
|
|
5451
|
+
const colWidth = Math.max(2, Math.floor((plotWidth - setLabelWidth) / intersections.length));
|
|
5452
|
+
const maxCount = Math.max(...intersections.map((i) => i.count));
|
|
5453
|
+
const barColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
5454
|
+
const dotColor = { r: 50, g: 50, b: 50, a: 1 };
|
|
5455
|
+
const lineColor = { r: 100, g: 100, b: 100, a: 1 };
|
|
5456
|
+
const labelColor = { r: 150, g: 150, b: 150, a: 1 };
|
|
5457
|
+
for (let i = 0;i < intersections.length; i++) {
|
|
5458
|
+
const inter = intersections[i];
|
|
5459
|
+
const x = plotLeft + setLabelWidth + i * colWidth + Math.floor(colWidth / 2);
|
|
5460
|
+
const barHeightPx = Math.round(inter.count / maxCount * barHeight);
|
|
5461
|
+
for (let y = barBottom - barHeightPx;y <= barBottom; y++) {
|
|
5462
|
+
canvas.drawChar(x, y, barChar, barColor);
|
|
5463
|
+
}
|
|
5464
|
+
const countStr = inter.count.toString();
|
|
5465
|
+
const labelY = barBottom - barHeightPx - 1;
|
|
5466
|
+
if (labelY >= barTop) {
|
|
5467
|
+
for (let ci = 0;ci < countStr.length; ci++) {
|
|
5468
|
+
canvas.drawChar(x - Math.floor(countStr.length / 2) + ci, labelY, countStr[ci], labelColor);
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5471
|
+
}
|
|
5472
|
+
const rowSpacing = Math.max(1, Math.floor(matrixHeight / setNames.length));
|
|
5473
|
+
if (showSetSizes) {
|
|
5474
|
+
for (let si = 0;si < setNames.length; si++) {
|
|
5475
|
+
const setName = setNames[si];
|
|
5476
|
+
const y = matrixTop + si * rowSpacing + 1;
|
|
5477
|
+
let setSize = 0;
|
|
5478
|
+
for (const row of data) {
|
|
5479
|
+
if (hasListFormat) {
|
|
5480
|
+
const val = row[setsField];
|
|
5481
|
+
if (typeof val === "string" && val.split(",").map((s) => s.trim()).includes(setName)) {
|
|
5482
|
+
setSize++;
|
|
5483
|
+
}
|
|
5484
|
+
} else {
|
|
5485
|
+
const v = row[setName];
|
|
5486
|
+
if (v === 1 || v === "1")
|
|
5487
|
+
setSize++;
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
const label = `${setName.substring(0, 6)}`;
|
|
5491
|
+
for (let ci = 0;ci < label.length; ci++) {
|
|
5492
|
+
canvas.drawChar(plotLeft + ci, y, label[ci], labelColor);
|
|
5493
|
+
}
|
|
5494
|
+
const sizeBarLen = Math.max(1, Math.round(setSize / data.length * 5));
|
|
5495
|
+
for (let bi = 0;bi < sizeBarLen; bi++) {
|
|
5496
|
+
canvas.drawChar(plotLeft + label.length + 1 + bi, y, "▪", barColor);
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5500
|
+
for (let i = 0;i < intersections.length; i++) {
|
|
5501
|
+
const inter = intersections[i];
|
|
5502
|
+
const x = plotLeft + setLabelWidth + i * colWidth + Math.floor(colWidth / 2);
|
|
5503
|
+
const activeRows = [];
|
|
5504
|
+
for (let si = 0;si < setNames.length; si++) {
|
|
5505
|
+
const setName = setNames[si];
|
|
5506
|
+
const y = matrixTop + si * rowSpacing + 1;
|
|
5507
|
+
const isActive = inter.sets.has(setName);
|
|
5508
|
+
if (isActive) {
|
|
5509
|
+
canvas.drawChar(x, y, dotChar, dotColor);
|
|
5510
|
+
activeRows.push(y);
|
|
5511
|
+
} else {
|
|
5512
|
+
canvas.drawChar(x, y, emptyChar, { r: 200, g: 200, b: 200, a: 1 });
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
if (activeRows.length > 1) {
|
|
5516
|
+
const minY = Math.min(...activeRows);
|
|
5517
|
+
const maxY = Math.max(...activeRows);
|
|
5518
|
+
for (let y = minY + 1;y < maxY; y++) {
|
|
5519
|
+
if (!activeRows.includes(y)) {
|
|
5520
|
+
canvas.drawChar(x, y, lineChar, lineColor);
|
|
5521
|
+
}
|
|
5522
|
+
}
|
|
5523
|
+
}
|
|
5524
|
+
}
|
|
5525
|
+
}
|
|
5526
|
+
function renderGeomDendrogram(data, geom, _aes, scales, canvas) {
|
|
5527
|
+
const params = geom.params || {};
|
|
5528
|
+
const orientation = params.orientation ?? "vertical";
|
|
5529
|
+
const labels = params.labels;
|
|
5530
|
+
const showLabels = params.show_labels ?? true;
|
|
5531
|
+
const hang = params.hang ?? false;
|
|
5532
|
+
const hConnector = params.h_connector ?? "─";
|
|
5533
|
+
const vConnector = params.v_connector ?? "│";
|
|
5534
|
+
const cornerTR = params.corner_tr ?? "┐";
|
|
5535
|
+
const cornerBL = params.corner_bl ?? "└";
|
|
5536
|
+
const cornerBR = params.corner_br ?? "┘";
|
|
5537
|
+
const leafChar = params.leaf_char ?? "○";
|
|
5538
|
+
const parentCol = params.parent_col ?? "parent";
|
|
5539
|
+
const heightCol = params.height_col ?? "height";
|
|
5540
|
+
const idCol = params.id_col ?? "id";
|
|
5541
|
+
const plotLeft = Math.round(scales.x.range[0]);
|
|
5542
|
+
const plotRight = Math.round(scales.x.range[1]);
|
|
5543
|
+
const plotTop = Math.round(scales.y.range[1]);
|
|
5544
|
+
const plotBottom = Math.round(scales.y.range[0]);
|
|
5545
|
+
const plotWidth = plotRight - plotLeft;
|
|
5546
|
+
const plotHeight = plotBottom - plotTop;
|
|
5547
|
+
const lineColor = { r: 50, g: 50, b: 50, a: 1 };
|
|
5548
|
+
const leafColor = { r: 31, g: 119, b: 180, a: 1 };
|
|
5549
|
+
const labelColor = { r: 100, g: 100, b: 100, a: 1 };
|
|
5550
|
+
const hasLinkageFormat = data.length > 0 && (("merge1" in data[0]) || ("merge_1" in data[0]));
|
|
5551
|
+
if (hasLinkageFormat) {
|
|
5552
|
+
const linkage = data.map((row) => ({
|
|
5553
|
+
merge1: Number(row["merge1"] ?? row["merge_1"]),
|
|
5554
|
+
merge2: Number(row["merge2"] ?? row["merge_2"]),
|
|
5555
|
+
height: Number(row[heightCol] ?? row["height"]),
|
|
5556
|
+
size: Number(row["size"] ?? 2)
|
|
5557
|
+
}));
|
|
5558
|
+
if (linkage.length === 0)
|
|
5559
|
+
return;
|
|
5560
|
+
const n = linkage.length + 1;
|
|
5561
|
+
const nodes = new Map;
|
|
5562
|
+
for (let i = 0;i < n; i++) {
|
|
5563
|
+
nodes.set(i, {
|
|
5564
|
+
id: i,
|
|
5565
|
+
height: 0,
|
|
5566
|
+
label: labels?.[i] ?? `${i}`
|
|
5567
|
+
});
|
|
5568
|
+
}
|
|
5569
|
+
for (let i = 0;i < linkage.length; i++) {
|
|
5570
|
+
const row = linkage[i];
|
|
5571
|
+
const newId = n + i;
|
|
5572
|
+
const leftNode = nodes.get(row.merge1 < n ? row.merge1 : row.merge1);
|
|
5573
|
+
const rightNode = nodes.get(row.merge2 < n ? row.merge2 : row.merge2);
|
|
5574
|
+
nodes.set(newId, {
|
|
5575
|
+
id: newId,
|
|
5576
|
+
left: leftNode,
|
|
5577
|
+
right: rightNode,
|
|
5578
|
+
height: row.height
|
|
5579
|
+
});
|
|
5580
|
+
}
|
|
5581
|
+
const root = nodes.get(n + linkage.length - 1);
|
|
5582
|
+
if (!root)
|
|
5583
|
+
return;
|
|
5584
|
+
let xPos = 0;
|
|
5585
|
+
const assignX = (node) => {
|
|
5586
|
+
if (!node.left && !node.right) {
|
|
5587
|
+
node.x = xPos++;
|
|
5588
|
+
} else {
|
|
5589
|
+
if (node.left)
|
|
5590
|
+
assignX(node.left);
|
|
5591
|
+
if (node.right)
|
|
5592
|
+
assignX(node.right);
|
|
5593
|
+
const leftX = node.left?.x ?? 0;
|
|
5594
|
+
const rightX = node.right?.x ?? 0;
|
|
5595
|
+
node.x = (leftX + rightX) / 2;
|
|
5596
|
+
}
|
|
5597
|
+
};
|
|
5598
|
+
assignX(root);
|
|
5599
|
+
const maxHeight = root.height;
|
|
5600
|
+
const leafCount = xPos;
|
|
5601
|
+
const mapX = (x) => {
|
|
5602
|
+
if (orientation === "vertical") {
|
|
5603
|
+
return plotLeft + x / (leafCount - 1 || 1) * plotWidth;
|
|
5604
|
+
} else {
|
|
5605
|
+
return plotBottom - x / (leafCount - 1 || 1) * plotHeight;
|
|
5606
|
+
}
|
|
5607
|
+
};
|
|
5608
|
+
const mapY = (h) => {
|
|
5609
|
+
if (orientation === "vertical") {
|
|
5610
|
+
return plotTop + (1 - h / maxHeight) * (plotHeight - 3);
|
|
5611
|
+
} else {
|
|
5612
|
+
return plotLeft + h / maxHeight * plotWidth;
|
|
5613
|
+
}
|
|
5614
|
+
};
|
|
5615
|
+
const drawNode = (node) => {
|
|
5616
|
+
if (node.x === undefined)
|
|
5617
|
+
return;
|
|
5618
|
+
if (node.left && node.right) {
|
|
5619
|
+
const nodeY = mapY(node.height);
|
|
5620
|
+
const leftX = mapX(node.left.x);
|
|
5621
|
+
const leftY = mapY(node.left.height);
|
|
5622
|
+
const rightX = mapX(node.right.x);
|
|
5623
|
+
const rightY = mapY(node.right.height);
|
|
5624
|
+
if (orientation === "vertical") {
|
|
5625
|
+
const hLineY = Math.round(nodeY);
|
|
5626
|
+
const leftXRound = Math.round(leftX);
|
|
5627
|
+
const rightXRound = Math.round(rightX);
|
|
5628
|
+
for (let x = Math.min(leftXRound, rightXRound);x <= Math.max(leftXRound, rightXRound); x++) {
|
|
5629
|
+
canvas.drawChar(x, hLineY, hConnector, lineColor);
|
|
5630
|
+
}
|
|
5631
|
+
canvas.drawChar(leftXRound, hLineY, cornerBL, lineColor);
|
|
5632
|
+
canvas.drawChar(rightXRound, hLineY, cornerBR, lineColor);
|
|
5633
|
+
const leftYRound = Math.round(leftY);
|
|
5634
|
+
const rightYRound = Math.round(rightY);
|
|
5635
|
+
for (let y = hLineY + 1;y < leftYRound; y++) {
|
|
5636
|
+
canvas.drawChar(leftXRound, y, vConnector, lineColor);
|
|
5637
|
+
}
|
|
5638
|
+
for (let y = hLineY + 1;y < rightYRound; y++) {
|
|
5639
|
+
canvas.drawChar(rightXRound, y, vConnector, lineColor);
|
|
5640
|
+
}
|
|
5641
|
+
} else {
|
|
5642
|
+
const hLineX = Math.round(nodeY);
|
|
5643
|
+
const leftYRound = Math.round(leftX);
|
|
5644
|
+
const rightYRound = Math.round(rightX);
|
|
5645
|
+
for (let y = Math.min(leftYRound, rightYRound);y <= Math.max(leftYRound, rightYRound); y++) {
|
|
5646
|
+
canvas.drawChar(hLineX, y, vConnector, lineColor);
|
|
5647
|
+
}
|
|
5648
|
+
canvas.drawChar(hLineX, leftYRound, cornerTR, lineColor);
|
|
5649
|
+
canvas.drawChar(hLineX, rightYRound, cornerBR, lineColor);
|
|
5650
|
+
const leftXRound = Math.round(mapY(node.left.height));
|
|
5651
|
+
const rightXRound = Math.round(mapY(node.right.height));
|
|
5652
|
+
for (let x = hLineX + 1;x < leftXRound; x++) {
|
|
5653
|
+
canvas.drawChar(x, leftYRound, hConnector, lineColor);
|
|
5654
|
+
}
|
|
5655
|
+
for (let x = hLineX + 1;x < rightXRound; x++) {
|
|
5656
|
+
canvas.drawChar(x, rightYRound, hConnector, lineColor);
|
|
5657
|
+
}
|
|
5658
|
+
}
|
|
5659
|
+
drawNode(node.left);
|
|
5660
|
+
drawNode(node.right);
|
|
5661
|
+
} else {
|
|
5662
|
+
if (orientation === "vertical") {
|
|
5663
|
+
const x = Math.round(mapX(node.x));
|
|
5664
|
+
const y = hang ? plotBottom - 2 : Math.round(mapY(0));
|
|
5665
|
+
canvas.drawChar(x, y, leafChar, leafColor);
|
|
5666
|
+
if (showLabels && node.label) {
|
|
5667
|
+
const label = node.label.substring(0, 4);
|
|
5668
|
+
for (let ci = 0;ci < label.length; ci++) {
|
|
5669
|
+
canvas.drawChar(x - Math.floor(label.length / 2) + ci, y + 1, label[ci], labelColor);
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
} else {
|
|
5673
|
+
const y = Math.round(mapX(node.x));
|
|
5674
|
+
const x = Math.round(mapY(0));
|
|
5675
|
+
canvas.drawChar(x, y, leafChar, leafColor);
|
|
5676
|
+
if (showLabels && node.label) {
|
|
5677
|
+
const label = node.label.substring(0, 6);
|
|
5678
|
+
for (let ci = 0;ci < label.length; ci++) {
|
|
5679
|
+
canvas.drawChar(x + 2 + ci, y, label[ci], labelColor);
|
|
5680
|
+
}
|
|
5681
|
+
}
|
|
5682
|
+
}
|
|
5683
|
+
}
|
|
5684
|
+
};
|
|
5685
|
+
drawNode(root);
|
|
5686
|
+
} else {
|
|
5687
|
+
const nodeMap = new Map;
|
|
5688
|
+
for (const row of data) {
|
|
5689
|
+
const id = String(row[idCol] ?? "");
|
|
5690
|
+
const parent = row[parentCol];
|
|
5691
|
+
const height = Number(row[heightCol] ?? 0);
|
|
5692
|
+
nodeMap.set(id, {
|
|
5693
|
+
id,
|
|
5694
|
+
parent: parent === null || parent === "" || parent === "null" ? null : String(parent),
|
|
5695
|
+
height,
|
|
5696
|
+
children: []
|
|
5697
|
+
});
|
|
5698
|
+
}
|
|
5699
|
+
let root = null;
|
|
5700
|
+
for (const node of nodeMap.values()) {
|
|
5701
|
+
if (node.parent === null) {
|
|
5702
|
+
root = node;
|
|
5703
|
+
} else {
|
|
5704
|
+
const parentNode = nodeMap.get(node.parent);
|
|
5705
|
+
if (parentNode) {
|
|
5706
|
+
parentNode.children.push(node);
|
|
5707
|
+
}
|
|
5708
|
+
}
|
|
5709
|
+
}
|
|
5710
|
+
if (!root)
|
|
5711
|
+
return;
|
|
5712
|
+
let xPos = 0;
|
|
5713
|
+
const assignX = (node) => {
|
|
5714
|
+
if (node.children.length === 0) {
|
|
5715
|
+
node.x = xPos++;
|
|
5716
|
+
} else {
|
|
5717
|
+
for (const child of node.children) {
|
|
5718
|
+
assignX(child);
|
|
5719
|
+
}
|
|
5720
|
+
const childXs = node.children.map((c) => c.x ?? 0);
|
|
5721
|
+
node.x = childXs.reduce((a, b) => a + b, 0) / childXs.length;
|
|
5722
|
+
}
|
|
5723
|
+
};
|
|
5724
|
+
assignX(root);
|
|
5725
|
+
const findMaxHeight = (node) => {
|
|
5726
|
+
if (node.children.length === 0)
|
|
5727
|
+
return node.height;
|
|
5728
|
+
return Math.max(node.height, ...node.children.map(findMaxHeight));
|
|
5729
|
+
};
|
|
5730
|
+
const maxHeight = findMaxHeight(root) || 1;
|
|
5731
|
+
const leafCount = xPos || 1;
|
|
5732
|
+
const mapX = (x) => plotLeft + x / (leafCount - 1 || 1) * plotWidth;
|
|
5733
|
+
const mapY = (h) => plotTop + (1 - h / maxHeight) * (plotHeight - 3);
|
|
5734
|
+
const drawNode = (node) => {
|
|
5735
|
+
if (node.x === undefined)
|
|
5736
|
+
return;
|
|
5737
|
+
if (node.children.length > 0) {
|
|
5738
|
+
const nodeY = Math.round(mapY(node.height));
|
|
5739
|
+
const childXs = node.children.map((c) => Math.round(mapX(c.x ?? 0)));
|
|
5740
|
+
const minX = Math.min(...childXs);
|
|
5741
|
+
const maxX = Math.max(...childXs);
|
|
5742
|
+
for (let x = minX;x <= maxX; x++) {
|
|
5743
|
+
canvas.drawChar(x, nodeY, hConnector, lineColor);
|
|
5744
|
+
}
|
|
5745
|
+
for (const child of node.children) {
|
|
5746
|
+
const childX = Math.round(mapX(child.x ?? 0));
|
|
5747
|
+
const childY = Math.round(mapY(child.height));
|
|
5748
|
+
canvas.drawChar(childX, nodeY, child === node.children[0] ? cornerBL : child === node.children[node.children.length - 1] ? cornerBR : "┴", lineColor);
|
|
5749
|
+
for (let y = nodeY + 1;y < childY; y++) {
|
|
5750
|
+
canvas.drawChar(childX, y, vConnector, lineColor);
|
|
5751
|
+
}
|
|
5752
|
+
drawNode(child);
|
|
5753
|
+
}
|
|
5754
|
+
} else {
|
|
5755
|
+
const x = Math.round(mapX(node.x));
|
|
5756
|
+
const y = hang ? plotBottom - 2 : Math.round(mapY(node.height));
|
|
5757
|
+
canvas.drawChar(x, y, leafChar, leafColor);
|
|
5758
|
+
if (showLabels) {
|
|
5759
|
+
const label = node.id.substring(0, 4);
|
|
5760
|
+
for (let ci = 0;ci < label.length; ci++) {
|
|
5761
|
+
canvas.drawChar(x - Math.floor(label.length / 2) + ci, y + 1, label[ci], labelColor);
|
|
5762
|
+
}
|
|
5763
|
+
}
|
|
5764
|
+
}
|
|
5765
|
+
};
|
|
5766
|
+
drawNode(root);
|
|
5767
|
+
}
|
|
5768
|
+
}
|
|
3855
5769
|
var POINT_SHAPES, SIZE_CHARS;
|
|
3856
5770
|
var init_render_geoms = __esm(() => {
|
|
3857
5771
|
init_scales();
|
|
@@ -6002,11 +7916,23 @@ function calculateLayout(spec, options) {
|
|
|
6002
7916
|
} else if (hasY2) {
|
|
6003
7917
|
rightMargin = 8 + (hasY2Label ? 2 : 0);
|
|
6004
7918
|
}
|
|
7919
|
+
let forestLabelWidth = 0;
|
|
7920
|
+
const isForestPlot = spec.geoms.some((g) => g.type === "forest");
|
|
7921
|
+
if (isForestPlot && Array.isArray(spec.data) && spec.data.length > 0) {
|
|
7922
|
+
const yField = typeof spec.aes.y === "string" ? spec.aes.y : "study";
|
|
7923
|
+
for (const row of spec.data) {
|
|
7924
|
+
const label = String(row[yField] ?? "");
|
|
7925
|
+
if (label.length > forestLabelWidth)
|
|
7926
|
+
forestLabelWidth = label.length;
|
|
7927
|
+
}
|
|
7928
|
+
}
|
|
7929
|
+
const defaultLeft = 8 + (hasYLabel ? 2 : 0);
|
|
7930
|
+
const neededLeft = forestLabelWidth > 0 ? forestLabelWidth + 2 : defaultLeft;
|
|
6005
7931
|
const margins = {
|
|
6006
7932
|
top: hasTitle ? 2 : 1,
|
|
6007
7933
|
right: rightMargin,
|
|
6008
7934
|
bottom: 2 + (hasXLabel ? 1 : 0) + (hasLegend && legendPosition === "bottom" ? 2 : 0),
|
|
6009
|
-
left:
|
|
7935
|
+
left: Math.max(defaultLeft, neededLeft)
|
|
6010
7936
|
};
|
|
6011
7937
|
const plotArea = {
|
|
6012
7938
|
x: margins.left,
|
|
@@ -6220,7 +8146,9 @@ function renderToCanvas(spec, options) {
|
|
|
6220
8146
|
renderTitle(canvas, spec.labels.title, layout.width, spec.theme);
|
|
6221
8147
|
}
|
|
6222
8148
|
renderGridLines(canvas, scales, layout.plotArea, spec.theme);
|
|
6223
|
-
|
|
8149
|
+
const isForest = spec.geoms.some((g) => g.type === "forest");
|
|
8150
|
+
const axisLabels = isForest ? { ...spec.labels, y: undefined } : spec.labels;
|
|
8151
|
+
renderAxes(canvas, scales, layout.plotArea, axisLabels, spec.theme);
|
|
6224
8152
|
for (const geom of spec.geoms) {
|
|
6225
8153
|
let geomData;
|
|
6226
8154
|
let geomAes = spec.aes;
|
|
@@ -7169,28 +9097,17 @@ function geom_abline(options = {}) {
|
|
|
7169
9097
|
// src/geoms/qq.ts
|
|
7170
9098
|
function geom_qq(options = {}) {
|
|
7171
9099
|
return {
|
|
7172
|
-
type: "
|
|
7173
|
-
stat: "
|
|
7174
|
-
|
|
7175
|
-
distribution: options.distribution ?? "norm",
|
|
7176
|
-
dparams: options.dparams,
|
|
7177
|
-
size: options.size ?? 1,
|
|
7178
|
-
shape: options.shape ?? "●",
|
|
7179
|
-
color: options.color,
|
|
7180
|
-
alpha: options.alpha ?? 1
|
|
7181
|
-
}
|
|
7182
|
-
};
|
|
7183
|
-
}
|
|
7184
|
-
function geom_qq_line(options = {}) {
|
|
7185
|
-
return {
|
|
7186
|
-
type: "segment",
|
|
7187
|
-
stat: "qq_line",
|
|
9100
|
+
type: "qq",
|
|
9101
|
+
stat: "identity",
|
|
9102
|
+
position: "identity",
|
|
7188
9103
|
params: {
|
|
7189
|
-
distribution: options.distribution ?? "
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
9104
|
+
distribution: options.distribution ?? "normal",
|
|
9105
|
+
show_line: options.show_line ?? true,
|
|
9106
|
+
show_ci: options.show_ci ?? false,
|
|
9107
|
+
conf_level: options.conf_level ?? 0.95,
|
|
9108
|
+
line_color: options.line_color ?? "#ff0000",
|
|
9109
|
+
point_char: options.point_char ?? "●",
|
|
9110
|
+
standardize: options.standardize ?? true
|
|
7194
9111
|
}
|
|
7195
9112
|
};
|
|
7196
9113
|
}
|
|
@@ -7494,11 +9411,358 @@ function geom_volcano(options = {}) {
|
|
|
7494
9411
|
};
|
|
7495
9412
|
}
|
|
7496
9413
|
|
|
9414
|
+
// src/geoms/ma.ts
|
|
9415
|
+
function geom_ma(options = {}) {
|
|
9416
|
+
return {
|
|
9417
|
+
type: "ma",
|
|
9418
|
+
stat: "identity",
|
|
9419
|
+
position: "identity",
|
|
9420
|
+
params: {
|
|
9421
|
+
fc_threshold: options.fc_threshold ?? 1,
|
|
9422
|
+
p_threshold: options.p_threshold ?? 0.05,
|
|
9423
|
+
p_col: options.p_col,
|
|
9424
|
+
x_is_log2: options.x_is_log2 ?? false,
|
|
9425
|
+
up_color: options.up_color ?? "#e41a1c",
|
|
9426
|
+
down_color: options.down_color ?? "#377eb8",
|
|
9427
|
+
ns_color: options.ns_color ?? "#999999",
|
|
9428
|
+
show_baseline: options.show_baseline ?? true,
|
|
9429
|
+
show_thresholds: options.show_thresholds ?? true,
|
|
9430
|
+
linetype: options.linetype ?? "dashed",
|
|
9431
|
+
n_labels: options.n_labels ?? 0,
|
|
9432
|
+
size: options.size ?? 1,
|
|
9433
|
+
alpha: options.alpha ?? 0.6,
|
|
9434
|
+
point_char: options.point_char ?? "●",
|
|
9435
|
+
show_smooth: options.show_smooth ?? false
|
|
9436
|
+
}
|
|
9437
|
+
};
|
|
9438
|
+
}
|
|
9439
|
+
|
|
9440
|
+
// src/geoms/manhattan.ts
|
|
9441
|
+
function geom_manhattan(options = {}) {
|
|
9442
|
+
return {
|
|
9443
|
+
type: "manhattan",
|
|
9444
|
+
stat: "identity",
|
|
9445
|
+
position: "identity",
|
|
9446
|
+
params: {
|
|
9447
|
+
suggestive_threshold: options.suggestive_threshold ?? 0.00001,
|
|
9448
|
+
genome_wide_threshold: options.genome_wide_threshold ?? 0.00000005,
|
|
9449
|
+
chr_col: options.chr_col,
|
|
9450
|
+
pos_col: options.pos_col,
|
|
9451
|
+
p_col: options.p_col,
|
|
9452
|
+
y_is_neglog10: options.y_is_neglog10 ?? false,
|
|
9453
|
+
chr_colors: options.chr_colors ?? DEFAULT_CHR_COLORS,
|
|
9454
|
+
highlight_color: options.highlight_color ?? "#e41a1c",
|
|
9455
|
+
suggestive_color: options.suggestive_color ?? "#ff7f00",
|
|
9456
|
+
show_thresholds: options.show_thresholds ?? true,
|
|
9457
|
+
threshold_linetype: options.threshold_linetype ?? "dashed",
|
|
9458
|
+
n_labels: options.n_labels ?? 0,
|
|
9459
|
+
label_col: options.label_col,
|
|
9460
|
+
size: options.size ?? 1,
|
|
9461
|
+
alpha: options.alpha ?? 0.6,
|
|
9462
|
+
point_char: options.point_char ?? "●",
|
|
9463
|
+
chr_gap: options.chr_gap ?? 0.02
|
|
9464
|
+
}
|
|
9465
|
+
};
|
|
9466
|
+
}
|
|
9467
|
+
var DEFAULT_CHR_COLORS;
|
|
9468
|
+
var init_manhattan = __esm(() => {
|
|
9469
|
+
DEFAULT_CHR_COLORS = ["#1f78b4", "#a6cee3"];
|
|
9470
|
+
});
|
|
9471
|
+
|
|
9472
|
+
// src/geoms/heatmap.ts
|
|
9473
|
+
function geom_heatmap(options = {}) {
|
|
9474
|
+
return {
|
|
9475
|
+
type: "heatmap",
|
|
9476
|
+
stat: "identity",
|
|
9477
|
+
position: "identity",
|
|
9478
|
+
params: {
|
|
9479
|
+
x_col: options.x_col,
|
|
9480
|
+
y_col: options.y_col,
|
|
9481
|
+
value_col: options.value_col ?? "value",
|
|
9482
|
+
low_color: options.low_color ?? "#313695",
|
|
9483
|
+
mid_color: options.mid_color ?? "#ffffbf",
|
|
9484
|
+
high_color: options.high_color ?? "#a50026",
|
|
9485
|
+
na_color: options.na_color ?? "#808080",
|
|
9486
|
+
midpoint: options.midpoint,
|
|
9487
|
+
cluster_rows: options.cluster_rows ?? false,
|
|
9488
|
+
cluster_cols: options.cluster_cols ?? false,
|
|
9489
|
+
clustering_method: options.clustering_method ?? "complete",
|
|
9490
|
+
clustering_distance: options.clustering_distance ?? "euclidean",
|
|
9491
|
+
show_row_dendrogram: options.show_row_dendrogram ?? true,
|
|
9492
|
+
show_col_dendrogram: options.show_col_dendrogram ?? true,
|
|
9493
|
+
dendrogram_ratio: options.dendrogram_ratio ?? 0.15,
|
|
9494
|
+
show_row_labels: options.show_row_labels ?? true,
|
|
9495
|
+
show_col_labels: options.show_col_labels ?? true,
|
|
9496
|
+
show_values: options.show_values ?? false,
|
|
9497
|
+
value_format: options.value_format ?? ".2f",
|
|
9498
|
+
cell_char: options.cell_char ?? "█",
|
|
9499
|
+
border: options.border ?? false,
|
|
9500
|
+
scale: options.scale ?? "none"
|
|
9501
|
+
}
|
|
9502
|
+
};
|
|
9503
|
+
}
|
|
9504
|
+
|
|
9505
|
+
// src/geoms/biplot.ts
|
|
9506
|
+
function geom_biplot(options = {}) {
|
|
9507
|
+
return {
|
|
9508
|
+
type: "biplot",
|
|
9509
|
+
stat: "identity",
|
|
9510
|
+
position: "identity",
|
|
9511
|
+
params: {
|
|
9512
|
+
pc1_col: options.pc1_col ?? "PC1",
|
|
9513
|
+
pc2_col: options.pc2_col ?? "PC2",
|
|
9514
|
+
loadings: options.loadings,
|
|
9515
|
+
var_explained: options.var_explained,
|
|
9516
|
+
show_scores: options.show_scores ?? true,
|
|
9517
|
+
score_color: options.score_color,
|
|
9518
|
+
score_size: options.score_size ?? 1,
|
|
9519
|
+
score_alpha: options.score_alpha ?? 0.8,
|
|
9520
|
+
score_char: options.score_char ?? "●",
|
|
9521
|
+
show_score_labels: options.show_score_labels ?? false,
|
|
9522
|
+
show_loadings: options.show_loadings ?? true,
|
|
9523
|
+
loading_color: options.loading_color ?? "#e41a1c",
|
|
9524
|
+
loading_scale: options.loading_scale,
|
|
9525
|
+
arrow_char: options.arrow_char ?? "→",
|
|
9526
|
+
show_loading_labels: options.show_loading_labels ?? true,
|
|
9527
|
+
show_origin: options.show_origin ?? true,
|
|
9528
|
+
origin_color: options.origin_color ?? "#999999",
|
|
9529
|
+
show_circle: options.show_circle ?? false,
|
|
9530
|
+
circle_color: options.circle_color ?? "#cccccc"
|
|
9531
|
+
}
|
|
9532
|
+
};
|
|
9533
|
+
}
|
|
9534
|
+
|
|
9535
|
+
// src/geoms/kaplan-meier.ts
|
|
9536
|
+
function geom_kaplan_meier(options = {}) {
|
|
9537
|
+
return {
|
|
9538
|
+
type: "kaplan_meier",
|
|
9539
|
+
stat: "identity",
|
|
9540
|
+
position: "identity",
|
|
9541
|
+
params: {
|
|
9542
|
+
show_ci: options.show_ci ?? false,
|
|
9543
|
+
conf_level: options.conf_level ?? 0.95,
|
|
9544
|
+
show_censored: options.show_censored ?? true,
|
|
9545
|
+
censor_char: options.censor_char ?? "+",
|
|
9546
|
+
show_risk_table: options.show_risk_table ?? false,
|
|
9547
|
+
linetype: options.linetype ?? "solid",
|
|
9548
|
+
show_median: options.show_median ?? false,
|
|
9549
|
+
step_type: options.step_type ?? "post"
|
|
9550
|
+
}
|
|
9551
|
+
};
|
|
9552
|
+
}
|
|
9553
|
+
|
|
9554
|
+
// src/geoms/forest.ts
|
|
9555
|
+
function geom_forest(options = {}) {
|
|
9556
|
+
return {
|
|
9557
|
+
type: "forest",
|
|
9558
|
+
stat: "identity",
|
|
9559
|
+
position: "identity",
|
|
9560
|
+
params: {
|
|
9561
|
+
null_line: options.null_line ?? 1,
|
|
9562
|
+
log_scale: options.log_scale ?? false,
|
|
9563
|
+
show_summary: options.show_summary ?? false,
|
|
9564
|
+
summary_row: options.summary_row,
|
|
9565
|
+
null_line_color: options.null_line_color ?? "#888888",
|
|
9566
|
+
null_line_type: options.null_line_type ?? "dashed",
|
|
9567
|
+
point_char: options.point_char ?? "■",
|
|
9568
|
+
show_weights: options.show_weights ?? false,
|
|
9569
|
+
min_size: options.min_size ?? 1,
|
|
9570
|
+
max_size: options.max_size ?? 3
|
|
9571
|
+
}
|
|
9572
|
+
};
|
|
9573
|
+
}
|
|
9574
|
+
|
|
9575
|
+
// src/geoms/roc.ts
|
|
9576
|
+
function geom_roc(options = {}) {
|
|
9577
|
+
return {
|
|
9578
|
+
type: "roc",
|
|
9579
|
+
stat: "identity",
|
|
9580
|
+
position: "identity",
|
|
9581
|
+
params: {
|
|
9582
|
+
show_diagonal: options.show_diagonal ?? true,
|
|
9583
|
+
diagonal_color: options.diagonal_color ?? "#888888",
|
|
9584
|
+
diagonal_type: options.diagonal_type ?? "dashed",
|
|
9585
|
+
show_auc: options.show_auc ?? true,
|
|
9586
|
+
show_optimal: options.show_optimal ?? false,
|
|
9587
|
+
optimal_char: options.optimal_char ?? "●",
|
|
9588
|
+
show_ci: options.show_ci ?? false,
|
|
9589
|
+
conf_level: options.conf_level ?? 0.95,
|
|
9590
|
+
fill_auc: options.fill_auc ?? false,
|
|
9591
|
+
fill_alpha: options.fill_alpha ?? 0.3
|
|
9592
|
+
}
|
|
9593
|
+
};
|
|
9594
|
+
}
|
|
9595
|
+
|
|
9596
|
+
// src/geoms/bland-altman.ts
|
|
9597
|
+
function geom_bland_altman(options = {}) {
|
|
9598
|
+
return {
|
|
9599
|
+
type: "bland_altman",
|
|
9600
|
+
stat: "identity",
|
|
9601
|
+
position: "identity",
|
|
9602
|
+
params: {
|
|
9603
|
+
show_limits: options.show_limits ?? true,
|
|
9604
|
+
show_bias: options.show_bias ?? true,
|
|
9605
|
+
limit_multiplier: options.limit_multiplier ?? 1.96,
|
|
9606
|
+
bias_color: options.bias_color ?? "#0000ff",
|
|
9607
|
+
limit_color: options.limit_color ?? "#ff0000",
|
|
9608
|
+
linetype: options.linetype ?? "dashed",
|
|
9609
|
+
show_ci: options.show_ci ?? false,
|
|
9610
|
+
conf_level: options.conf_level ?? 0.95,
|
|
9611
|
+
point_char: options.point_char ?? "●",
|
|
9612
|
+
percent_diff: options.percent_diff ?? false,
|
|
9613
|
+
precomputed: options.precomputed ?? false
|
|
9614
|
+
}
|
|
9615
|
+
};
|
|
9616
|
+
}
|
|
9617
|
+
|
|
9618
|
+
// src/geoms/ecdf.ts
|
|
9619
|
+
function geom_ecdf(options = {}) {
|
|
9620
|
+
return {
|
|
9621
|
+
type: "ecdf",
|
|
9622
|
+
stat: "identity",
|
|
9623
|
+
position: "identity",
|
|
9624
|
+
params: {
|
|
9625
|
+
pad: options.pad ?? true,
|
|
9626
|
+
show_ci: options.show_ci ?? false,
|
|
9627
|
+
conf_level: options.conf_level ?? 0.95,
|
|
9628
|
+
step_type: options.step_type ?? "post",
|
|
9629
|
+
show_points: options.show_points ?? false,
|
|
9630
|
+
line_char: options.line_char ?? "─",
|
|
9631
|
+
complement: options.complement ?? false
|
|
9632
|
+
}
|
|
9633
|
+
};
|
|
9634
|
+
}
|
|
9635
|
+
|
|
9636
|
+
// src/geoms/funnel.ts
|
|
9637
|
+
function geom_funnel(options = {}) {
|
|
9638
|
+
return {
|
|
9639
|
+
type: "funnel",
|
|
9640
|
+
stat: "identity",
|
|
9641
|
+
position: "identity",
|
|
9642
|
+
params: {
|
|
9643
|
+
show_contours: options.show_contours ?? true,
|
|
9644
|
+
contour_levels: options.contour_levels ?? [0.95],
|
|
9645
|
+
show_significance: options.show_significance ?? false,
|
|
9646
|
+
summary_effect: options.summary_effect,
|
|
9647
|
+
show_summary_line: options.show_summary_line ?? true,
|
|
9648
|
+
y_is_se: options.y_is_se ?? true,
|
|
9649
|
+
invert_y: options.invert_y ?? true,
|
|
9650
|
+
point_char: options.point_char ?? "●",
|
|
9651
|
+
contour_color: options.contour_color ?? "#888888"
|
|
9652
|
+
}
|
|
9653
|
+
};
|
|
9654
|
+
}
|
|
9655
|
+
|
|
9656
|
+
// src/geoms/control.ts
|
|
9657
|
+
function geom_control(options = {}) {
|
|
9658
|
+
return {
|
|
9659
|
+
type: "control",
|
|
9660
|
+
stat: "identity",
|
|
9661
|
+
position: "identity",
|
|
9662
|
+
params: {
|
|
9663
|
+
chart_type: options.chart_type ?? "i",
|
|
9664
|
+
sigma: options.sigma ?? 3,
|
|
9665
|
+
show_center: options.show_center ?? true,
|
|
9666
|
+
show_ucl: options.show_ucl ?? true,
|
|
9667
|
+
show_lcl: options.show_lcl ?? true,
|
|
9668
|
+
show_warning: options.show_warning ?? false,
|
|
9669
|
+
center: options.center,
|
|
9670
|
+
ucl: options.ucl,
|
|
9671
|
+
lcl: options.lcl,
|
|
9672
|
+
center_color: options.center_color ?? "#0000ff",
|
|
9673
|
+
limit_color: options.limit_color ?? "#ff0000",
|
|
9674
|
+
warning_color: options.warning_color ?? "#ffa500",
|
|
9675
|
+
connect_points: options.connect_points ?? true,
|
|
9676
|
+
highlight_ooc: options.highlight_ooc ?? true,
|
|
9677
|
+
ooc_char: options.ooc_char ?? "◆",
|
|
9678
|
+
point_char: options.point_char ?? "●"
|
|
9679
|
+
}
|
|
9680
|
+
};
|
|
9681
|
+
}
|
|
9682
|
+
|
|
9683
|
+
// src/geoms/scree.ts
|
|
9684
|
+
function geom_scree(options = {}) {
|
|
9685
|
+
return {
|
|
9686
|
+
type: "scree",
|
|
9687
|
+
stat: "identity",
|
|
9688
|
+
position: "identity",
|
|
9689
|
+
params: {
|
|
9690
|
+
show_cumulative: options.show_cumulative ?? false,
|
|
9691
|
+
show_kaiser: options.show_kaiser ?? false,
|
|
9692
|
+
show_elbow: options.show_elbow ?? false,
|
|
9693
|
+
show_broken_stick: options.show_broken_stick ?? false,
|
|
9694
|
+
connect_points: options.connect_points ?? true,
|
|
9695
|
+
show_bars: options.show_bars ?? false,
|
|
9696
|
+
point_char: options.point_char ?? "●",
|
|
9697
|
+
color: options.color,
|
|
9698
|
+
cumulative_color: options.cumulative_color ?? "#ff0000",
|
|
9699
|
+
kaiser_color: options.kaiser_color ?? "#888888",
|
|
9700
|
+
y_format: options.y_format ?? "percentage",
|
|
9701
|
+
threshold: options.threshold,
|
|
9702
|
+
threshold_color: options.threshold_color ?? "#00aa00"
|
|
9703
|
+
}
|
|
9704
|
+
};
|
|
9705
|
+
}
|
|
9706
|
+
|
|
9707
|
+
// src/geoms/upset.ts
|
|
9708
|
+
function geom_upset(options = {}) {
|
|
9709
|
+
return {
|
|
9710
|
+
type: "upset",
|
|
9711
|
+
stat: "identity",
|
|
9712
|
+
position: "identity",
|
|
9713
|
+
params: {
|
|
9714
|
+
sets: options.sets,
|
|
9715
|
+
min_size: options.min_size ?? 1,
|
|
9716
|
+
max_intersections: options.max_intersections ?? 20,
|
|
9717
|
+
sort_by: options.sort_by ?? "size",
|
|
9718
|
+
sort_order: options.sort_order ?? "desc",
|
|
9719
|
+
show_set_sizes: options.show_set_sizes ?? true,
|
|
9720
|
+
dot_char: options.dot_char ?? "●",
|
|
9721
|
+
empty_char: options.empty_char ?? "○",
|
|
9722
|
+
line_char: options.line_char ?? "│",
|
|
9723
|
+
bar_char: options.bar_char ?? "█",
|
|
9724
|
+
color: options.color,
|
|
9725
|
+
show_degree: options.show_degree ?? false
|
|
9726
|
+
}
|
|
9727
|
+
};
|
|
9728
|
+
}
|
|
9729
|
+
|
|
9730
|
+
// src/geoms/dendrogram.ts
|
|
9731
|
+
function geom_dendrogram(options = {}) {
|
|
9732
|
+
return {
|
|
9733
|
+
type: "dendrogram",
|
|
9734
|
+
stat: "identity",
|
|
9735
|
+
position: "identity",
|
|
9736
|
+
params: {
|
|
9737
|
+
orientation: options.orientation ?? "vertical",
|
|
9738
|
+
labels: options.labels,
|
|
9739
|
+
show_labels: options.show_labels ?? true,
|
|
9740
|
+
hang: options.hang ?? false,
|
|
9741
|
+
cut_height: options.cut_height,
|
|
9742
|
+
k: options.k,
|
|
9743
|
+
branch_char: options.branch_char ?? "│",
|
|
9744
|
+
h_connector: options.h_connector ?? "─",
|
|
9745
|
+
v_connector: options.v_connector ?? "│",
|
|
9746
|
+
corner_tl: options.corner_tl ?? "┌",
|
|
9747
|
+
corner_tr: options.corner_tr ?? "┐",
|
|
9748
|
+
corner_bl: options.corner_bl ?? "└",
|
|
9749
|
+
corner_br: options.corner_br ?? "┘",
|
|
9750
|
+
leaf_char: options.leaf_char ?? "○",
|
|
9751
|
+
cluster_colors: options.cluster_colors,
|
|
9752
|
+
line_style: options.line_style ?? "square",
|
|
9753
|
+
parent_col: options.parent_col ?? "parent",
|
|
9754
|
+
height_col: options.height_col ?? "height",
|
|
9755
|
+
id_col: options.id_col ?? "id"
|
|
9756
|
+
}
|
|
9757
|
+
};
|
|
9758
|
+
}
|
|
9759
|
+
|
|
7497
9760
|
// src/geoms/index.ts
|
|
7498
9761
|
var init_geoms = __esm(() => {
|
|
7499
9762
|
init_ridgeline();
|
|
7500
9763
|
init_sparkline();
|
|
7501
9764
|
init_braille();
|
|
9765
|
+
init_manhattan();
|
|
7502
9766
|
});
|
|
7503
9767
|
|
|
7504
9768
|
// src/stats/index.ts
|
|
@@ -12005,6 +14269,7 @@ __export(exports_src, {
|
|
|
12005
14269
|
geom_volcano: () => geom_volcano,
|
|
12006
14270
|
geom_vline: () => geom_vline,
|
|
12007
14271
|
geom_violin: () => geom_violin,
|
|
14272
|
+
geom_upset: () => geom_upset,
|
|
12008
14273
|
geom_treemap: () => geom_treemap,
|
|
12009
14274
|
geom_tile: () => geom_tile,
|
|
12010
14275
|
geom_text: () => geom_text,
|
|
@@ -12012,36 +14277,46 @@ __export(exports_src, {
|
|
|
12012
14277
|
geom_sparkline: () => geom_sparkline,
|
|
12013
14278
|
geom_smooth: () => geom_smooth,
|
|
12014
14279
|
geom_segment: () => geom_segment,
|
|
14280
|
+
geom_scree: () => geom_scree,
|
|
12015
14281
|
geom_sankey: () => geom_sankey,
|
|
12016
14282
|
geom_rug: () => geom_rug,
|
|
14283
|
+
geom_roc: () => geom_roc,
|
|
12017
14284
|
geom_ridgeline: () => geom_ridgeline,
|
|
12018
14285
|
geom_ribbon: () => geom_ribbon,
|
|
12019
14286
|
geom_rect: () => geom_rect,
|
|
12020
14287
|
geom_raster: () => geom_raster,
|
|
12021
14288
|
geom_quasirandom: () => geom_quasirandom,
|
|
12022
|
-
geom_qq_line: () => geom_qq_line,
|
|
12023
14289
|
geom_qq: () => geom_qq,
|
|
12024
14290
|
geom_pointrange: () => geom_pointrange,
|
|
12025
14291
|
geom_point: () => geom_point,
|
|
12026
14292
|
geom_path: () => geom_path,
|
|
14293
|
+
geom_manhattan: () => geom_manhattan,
|
|
14294
|
+
geom_ma: () => geom_ma,
|
|
12027
14295
|
geom_lollipop: () => geom_lollipop,
|
|
12028
14296
|
geom_linerange: () => geom_linerange,
|
|
12029
14297
|
geom_line: () => geom_line,
|
|
12030
14298
|
geom_label: () => geom_label,
|
|
14299
|
+
geom_kaplan_meier: () => geom_kaplan_meier,
|
|
12031
14300
|
geom_joy: () => geom_joy,
|
|
12032
14301
|
geom_icicle: () => geom_icicle,
|
|
12033
14302
|
geom_hline: () => geom_hline,
|
|
12034
14303
|
geom_histogram: () => geom_histogram,
|
|
14304
|
+
geom_heatmap: () => geom_heatmap,
|
|
14305
|
+
geom_funnel: () => geom_funnel,
|
|
12035
14306
|
geom_freqpoly: () => geom_freqpoly,
|
|
14307
|
+
geom_forest: () => geom_forest,
|
|
12036
14308
|
geom_flame: () => geom_flame,
|
|
12037
14309
|
geom_errorbarh: () => geom_errorbarh,
|
|
12038
14310
|
geom_errorbar: () => geom_errorbar,
|
|
14311
|
+
geom_ecdf: () => geom_ecdf,
|
|
12039
14312
|
geom_dumbbell: () => geom_dumbbell,
|
|
12040
14313
|
geom_density_2d: () => geom_density_2d,
|
|
12041
14314
|
geom_density: () => geom_density,
|
|
14315
|
+
geom_dendrogram: () => geom_dendrogram,
|
|
12042
14316
|
geom_curve: () => geom_curve,
|
|
12043
14317
|
geom_crossbar: () => geom_crossbar,
|
|
12044
14318
|
geom_corrmat: () => geom_corrmat,
|
|
14319
|
+
geom_control: () => geom_control,
|
|
12045
14320
|
geom_contour_filled: () => geom_contour_filled,
|
|
12046
14321
|
geom_contour: () => geom_contour,
|
|
12047
14322
|
geom_col: () => geom_col,
|
|
@@ -12049,6 +14324,8 @@ __export(exports_src, {
|
|
|
12049
14324
|
geom_bullet: () => geom_bullet,
|
|
12050
14325
|
geom_braille: () => geom_braille,
|
|
12051
14326
|
geom_boxplot: () => geom_boxplot,
|
|
14327
|
+
geom_bland_altman: () => geom_bland_altman,
|
|
14328
|
+
geom_biplot: () => geom_biplot,
|
|
12052
14329
|
geom_bin2d: () => geom_bin2d,
|
|
12053
14330
|
geom_beeswarm: () => geom_beeswarm,
|
|
12054
14331
|
geom_bar: () => geom_bar,
|
|
@@ -12275,6 +14552,7 @@ export {
|
|
|
12275
14552
|
geom_volcano,
|
|
12276
14553
|
geom_vline,
|
|
12277
14554
|
geom_violin,
|
|
14555
|
+
geom_upset,
|
|
12278
14556
|
geom_treemap,
|
|
12279
14557
|
geom_tile,
|
|
12280
14558
|
geom_text,
|
|
@@ -12282,36 +14560,46 @@ export {
|
|
|
12282
14560
|
geom_sparkline,
|
|
12283
14561
|
geom_smooth,
|
|
12284
14562
|
geom_segment,
|
|
14563
|
+
geom_scree,
|
|
12285
14564
|
geom_sankey,
|
|
12286
14565
|
geom_rug,
|
|
14566
|
+
geom_roc,
|
|
12287
14567
|
geom_ridgeline,
|
|
12288
14568
|
geom_ribbon,
|
|
12289
14569
|
geom_rect,
|
|
12290
14570
|
geom_raster,
|
|
12291
14571
|
geom_quasirandom,
|
|
12292
|
-
geom_qq_line,
|
|
12293
14572
|
geom_qq,
|
|
12294
14573
|
geom_pointrange,
|
|
12295
14574
|
geom_point,
|
|
12296
14575
|
geom_path,
|
|
14576
|
+
geom_manhattan,
|
|
14577
|
+
geom_ma,
|
|
12297
14578
|
geom_lollipop,
|
|
12298
14579
|
geom_linerange,
|
|
12299
14580
|
geom_line,
|
|
12300
14581
|
geom_label,
|
|
14582
|
+
geom_kaplan_meier,
|
|
12301
14583
|
geom_joy,
|
|
12302
14584
|
geom_icicle,
|
|
12303
14585
|
geom_hline,
|
|
12304
14586
|
geom_histogram,
|
|
14587
|
+
geom_heatmap,
|
|
14588
|
+
geom_funnel,
|
|
12305
14589
|
geom_freqpoly,
|
|
14590
|
+
geom_forest,
|
|
12306
14591
|
geom_flame,
|
|
12307
14592
|
geom_errorbarh,
|
|
12308
14593
|
geom_errorbar,
|
|
14594
|
+
geom_ecdf,
|
|
12309
14595
|
geom_dumbbell,
|
|
12310
14596
|
geom_density_2d,
|
|
12311
14597
|
geom_density,
|
|
14598
|
+
geom_dendrogram,
|
|
12312
14599
|
geom_curve,
|
|
12313
14600
|
geom_crossbar,
|
|
12314
14601
|
geom_corrmat,
|
|
14602
|
+
geom_control,
|
|
12315
14603
|
geom_contour_filled,
|
|
12316
14604
|
geom_contour,
|
|
12317
14605
|
geom_col,
|
|
@@ -12319,6 +14607,8 @@ export {
|
|
|
12319
14607
|
geom_bullet,
|
|
12320
14608
|
geom_braille,
|
|
12321
14609
|
geom_boxplot,
|
|
14610
|
+
geom_bland_altman,
|
|
14611
|
+
geom_biplot,
|
|
12322
14612
|
geom_bin2d,
|
|
12323
14613
|
geom_beeswarm,
|
|
12324
14614
|
geom_bar,
|