@rtemis/draw 0.1.0 → 0.2.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/README.md +10 -1
- package/dist/charts/a3/config.d.ts +23 -2
- package/dist/charts/a3/config.d.ts.map +1 -1
- package/dist/charts/a3/config.js +24 -3
- package/dist/charts/a3/config.js.map +1 -1
- package/dist/charts/a3/index.d.ts +2 -2
- package/dist/charts/a3/index.d.ts.map +1 -1
- package/dist/charts/a3/index.js +1 -1
- package/dist/charts/a3/index.js.map +1 -1
- package/dist/charts/bar/config.d.ts +59 -0
- package/dist/charts/bar/config.d.ts.map +1 -0
- package/dist/charts/bar/config.js +151 -0
- package/dist/charts/bar/config.js.map +1 -0
- package/dist/charts/bar/index.d.ts +3 -0
- package/dist/charts/bar/index.d.ts.map +1 -0
- package/dist/charts/bar/index.js +2 -0
- package/dist/charts/bar/index.js.map +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/rtemis-draw-builders.cjs +419 -5
- package/dist/shared/layout.d.ts +29 -0
- package/dist/shared/layout.d.ts.map +1 -0
- package/dist/shared/layout.js +59 -0
- package/dist/shared/layout.js.map +1 -0
- package/dist/shared/legend.d.ts +14 -0
- package/dist/shared/legend.d.ts.map +1 -0
- package/dist/shared/legend.js +2 -0
- package/dist/shared/legend.js.map +1 -0
- package/dist/shared/source.d.ts +32 -0
- package/dist/shared/source.d.ts.map +1 -0
- package/dist/shared/source.js +32 -0
- package/dist/shared/source.js.map +1 -0
- package/dist/theme/tokens.d.ts +76 -0
- package/dist/theme/tokens.d.ts.map +1 -0
- package/dist/theme/tokens.js +205 -0
- package/dist/theme/tokens.js.map +1 -0
- package/package.json +1 -1
|
@@ -21,8 +21,22 @@ var RtemisDraw = (() => {
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
A3_CHART_CONFIG_MEMBERS: () => A3_CHART_CONFIG_MEMBERS,
|
|
25
|
+
BAR_CHART_CONFIG_MEMBERS: () => BAR_CHART_CONFIG_MEMBERS,
|
|
26
|
+
DEFAULT_FONT_FAMILY: () => DEFAULT_FONT_FAMILY,
|
|
27
|
+
DEFAULT_MARGIN: () => DEFAULT_MARGIN,
|
|
28
|
+
RTEMIS_PALETTE: () => RTEMIS_PALETTE,
|
|
29
|
+
SIGN_COLORS: () => SIGN_COLORS,
|
|
30
|
+
ZOOM_SLIDER_ID: () => ZOOM_SLIDER_ID,
|
|
31
|
+
a3SurfaceHints: () => a3SurfaceHints,
|
|
24
32
|
buildA3Option: () => buildA3Option,
|
|
25
|
-
|
|
33
|
+
buildBarOption: () => buildBarOption,
|
|
34
|
+
builders: () => builders,
|
|
35
|
+
darkThemeTokens: () => darkThemeTokens,
|
|
36
|
+
fontStack: () => fontStack,
|
|
37
|
+
lightThemeTokens: () => lightThemeTokens,
|
|
38
|
+
themeFontSizes: () => themeFontSizes,
|
|
39
|
+
themeOption: () => themeOption
|
|
26
40
|
});
|
|
27
41
|
|
|
28
42
|
// src/charts/a3/layout.ts
|
|
@@ -52,9 +66,11 @@ var RtemisDraw = (() => {
|
|
|
52
66
|
X: "(Any)",
|
|
53
67
|
"*": "Termination codon"
|
|
54
68
|
});
|
|
69
|
+
var DEFAULT_MARKER_SIZE = 28;
|
|
55
70
|
var DEFAULT_FONT_SIZE = 18;
|
|
56
71
|
var DEFAULT_MARGIN_TOP = 24;
|
|
57
72
|
var DEFAULT_MARGIN_TOP_WITH_TITLE = 64;
|
|
73
|
+
var DEFAULT_MARGIN_BOTTOM = 24;
|
|
58
74
|
var DEFAULT_TITLE_TOP = 32;
|
|
59
75
|
var DEFAULT_TITLE_BOTTOM_GAP = 14;
|
|
60
76
|
var DEFAULT_N_PER_ROW = 21;
|
|
@@ -81,6 +97,10 @@ var RtemisDraw = (() => {
|
|
|
81
97
|
bounds: computeBounds(residues)
|
|
82
98
|
});
|
|
83
99
|
}
|
|
100
|
+
function resolveA3VisualizationHeight(input, options = {}) {
|
|
101
|
+
const model = createA3LayoutModel(input, options);
|
|
102
|
+
return resolveA3VisualizationHeightFromModel(model, options);
|
|
103
|
+
}
|
|
84
104
|
function resolveA3TitleTop(options = {}) {
|
|
85
105
|
return options.titleTop ?? DEFAULT_TITLE_TOP;
|
|
86
106
|
}
|
|
@@ -141,6 +161,17 @@ var RtemisDraw = (() => {
|
|
|
141
161
|
}
|
|
142
162
|
return 1 + (x - 1) * residueSpacing;
|
|
143
163
|
}
|
|
164
|
+
function resolveA3VisualizationHeightFromModel(model, options = {}) {
|
|
165
|
+
if (options.height !== void 0) {
|
|
166
|
+
return options.height;
|
|
167
|
+
}
|
|
168
|
+
const markerSize = options.markerSize ?? DEFAULT_MARKER_SIZE;
|
|
169
|
+
const topMargin = resolveA3TitleMarginTop(options);
|
|
170
|
+
const bottomMargin = DEFAULT_MARGIN_BOTTOM;
|
|
171
|
+
const verticalSpan = model.bounds.maxY - model.bounds.minY;
|
|
172
|
+
const bodyHeight = markerSize * (2 * verticalSpan + 1);
|
|
173
|
+
return Math.ceil(topMargin + bottomMargin + bodyHeight);
|
|
174
|
+
}
|
|
144
175
|
function computeBounds(residues) {
|
|
145
176
|
const xs = residues.map((residue) => residue.x);
|
|
146
177
|
const ys = residues.map((residue) => residue.y);
|
|
@@ -838,6 +869,23 @@ var RtemisDraw = (() => {
|
|
|
838
869
|
"title"
|
|
839
870
|
]);
|
|
840
871
|
function buildA3Option(document, config = {}, appearance = {}) {
|
|
872
|
+
const option = createA3EChartsOption(document, visualizationOptions(config, appearance));
|
|
873
|
+
return config.zoom === false ? option : Object.freeze({ ...option, dataZoom: A3_ZOOM });
|
|
874
|
+
}
|
|
875
|
+
function a3SurfaceHints(document, config = {}, appearance = {}) {
|
|
876
|
+
const options = visualizationOptions(config, appearance);
|
|
877
|
+
const model = createA3LayoutModel(document, options);
|
|
878
|
+
const markerSize = options.markerSize ?? 28;
|
|
879
|
+
return Object.freeze({
|
|
880
|
+
height: resolveA3VisualizationHeight(document, options),
|
|
881
|
+
bodyHeight: markerSize * (2 * (model.bounds.maxY - model.bounds.minY) + 1),
|
|
882
|
+
markerSize,
|
|
883
|
+
fontSize: options.fontSize ?? 18,
|
|
884
|
+
residueSpacing: options.residueSpacing ?? 0.3,
|
|
885
|
+
legendGap: options.legendGap ?? 90
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
function visualizationOptions(config, appearance) {
|
|
841
889
|
const dark = appearance.dark ?? false;
|
|
842
890
|
const base = dark ? DARK_A3_VISUALIZATION_THEME : {};
|
|
843
891
|
const theme = {
|
|
@@ -852,7 +900,7 @@ var RtemisDraw = (() => {
|
|
|
852
900
|
...colorOverride("variantColor", config.variant_color),
|
|
853
901
|
...colorOverride("diseaseVariantColor", config.disease_variant_color)
|
|
854
902
|
};
|
|
855
|
-
|
|
903
|
+
return {
|
|
856
904
|
nPerRow: config.n_per_row ?? 21,
|
|
857
905
|
residueSpacing: config.residue_spacing ?? 0.3,
|
|
858
906
|
showMarkers: config.show_markers ?? true,
|
|
@@ -872,8 +920,6 @@ var RtemisDraw = (() => {
|
|
|
872
920
|
...config.title ? { title: config.title } : {},
|
|
873
921
|
...appearance.titleTop === void 0 ? {} : { titleTop: appearance.titleTop }
|
|
874
922
|
};
|
|
875
|
-
const option = createA3EChartsOption(document, options);
|
|
876
|
-
return config.zoom === false ? option : Object.freeze({ ...option, dataZoom: A3_ZOOM });
|
|
877
923
|
}
|
|
878
924
|
var A3_ZOOM = Object.freeze([
|
|
879
925
|
{
|
|
@@ -896,9 +942,377 @@ var RtemisDraw = (() => {
|
|
|
896
942
|
return value ? { [key]: value } : {};
|
|
897
943
|
}
|
|
898
944
|
|
|
945
|
+
// src/shared/layout.ts
|
|
946
|
+
var DEFAULT_MARGIN = 36;
|
|
947
|
+
var SIDES = ["top", "right", "bottom", "left"];
|
|
948
|
+
function cartesianGrid(config, axisNames) {
|
|
949
|
+
const set = SIDES.filter((side) => typeof config[`margin_${side}`] === "number");
|
|
950
|
+
const grid = {};
|
|
951
|
+
for (const side of SIDES) {
|
|
952
|
+
const value = config[`margin_${side}`];
|
|
953
|
+
if (set.length === 0) grid[side] = DEFAULT_MARGIN;
|
|
954
|
+
else if (typeof value === "number") grid[side] = value;
|
|
955
|
+
}
|
|
956
|
+
grid.outerBoundsMode = "same";
|
|
957
|
+
grid.outerBoundsContain = axisNames ? "all" : "axisLabel";
|
|
958
|
+
return grid;
|
|
959
|
+
}
|
|
960
|
+
var ZOOM_SLIDER_ID = "rtemis-zoom-slider";
|
|
961
|
+
var SLIDER_SIZE = 30;
|
|
962
|
+
var SLIDER_HANDLE = 7;
|
|
963
|
+
var SLIDER_GAP = 8;
|
|
964
|
+
function axisZoom(axis, grid) {
|
|
965
|
+
const side = axis === "x" ? "bottom" : "right";
|
|
966
|
+
const current = grid[side];
|
|
967
|
+
const margin = typeof current === "number" ? current : axis === "x" ? 80 : 15;
|
|
968
|
+
const index = axis === "x" ? { xAxisIndex: 0 } : { yAxisIndex: 0 };
|
|
969
|
+
grid[side] = margin + SLIDER_HANDLE + SLIDER_SIZE + SLIDER_GAP;
|
|
970
|
+
return [
|
|
971
|
+
{
|
|
972
|
+
type: "slider",
|
|
973
|
+
id: ZOOM_SLIDER_ID,
|
|
974
|
+
start: 0,
|
|
975
|
+
end: 100,
|
|
976
|
+
...index,
|
|
977
|
+
[side]: margin + SLIDER_HANDLE,
|
|
978
|
+
...axis === "x" ? { height: SLIDER_SIZE } : { width: SLIDER_SIZE }
|
|
979
|
+
},
|
|
980
|
+
{ type: "inside", ...index, zoomOnMouseWheel: "shift", moveOnMouseMove: true }
|
|
981
|
+
];
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/shared/source.ts
|
|
985
|
+
function distinct(values, levels) {
|
|
986
|
+
const seen = new Set(values);
|
|
987
|
+
const ordered = (levels ?? []).filter((level) => seen.has(level));
|
|
988
|
+
const known = new Set(ordered);
|
|
989
|
+
return [...ordered, ...[...seen].filter((v) => !known.has(v))];
|
|
990
|
+
}
|
|
991
|
+
function column(source, name, member) {
|
|
992
|
+
const values = source[name];
|
|
993
|
+
if (values === void 0) {
|
|
994
|
+
throw new Error(`Column '${name}' (config member '${member}') is not in the data.`);
|
|
995
|
+
}
|
|
996
|
+
return Array.isArray(values) ? values : Array.from(values);
|
|
997
|
+
}
|
|
998
|
+
function asArray(value) {
|
|
999
|
+
if (value === null || value === void 0) return [];
|
|
1000
|
+
return Array.isArray(value) ? value : [value];
|
|
1001
|
+
}
|
|
1002
|
+
function numberOrNull(value) {
|
|
1003
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// src/charts/bar/config.ts
|
|
1007
|
+
var BAR_CHART_CONFIG_MEMBERS = Object.freeze([
|
|
1008
|
+
"type",
|
|
1009
|
+
"x",
|
|
1010
|
+
"y",
|
|
1011
|
+
"group",
|
|
1012
|
+
"aggregate",
|
|
1013
|
+
"order",
|
|
1014
|
+
"stack",
|
|
1015
|
+
"horizontal",
|
|
1016
|
+
"zoom",
|
|
1017
|
+
"bar_width",
|
|
1018
|
+
"palette",
|
|
1019
|
+
"ylim",
|
|
1020
|
+
"xlab",
|
|
1021
|
+
"ylab",
|
|
1022
|
+
"title",
|
|
1023
|
+
"margin_top",
|
|
1024
|
+
"margin_right",
|
|
1025
|
+
"margin_bottom",
|
|
1026
|
+
"margin_left",
|
|
1027
|
+
"legend_position",
|
|
1028
|
+
"legend_placement",
|
|
1029
|
+
"legend_title"
|
|
1030
|
+
]);
|
|
1031
|
+
function buildBarOption(data, config, appearance = {}) {
|
|
1032
|
+
const source = data.columns;
|
|
1033
|
+
const yColumns = asArray(config.y);
|
|
1034
|
+
if (!config.x || yColumns.length === 0) {
|
|
1035
|
+
throw new Error("A bar chart needs both `x` and `y` set to draw.");
|
|
1036
|
+
}
|
|
1037
|
+
const xs = column(source, config.x, "x").map((v) => String(v));
|
|
1038
|
+
const aggregate = config.aggregate ?? "none";
|
|
1039
|
+
let categories;
|
|
1040
|
+
let series;
|
|
1041
|
+
if (config.group) {
|
|
1042
|
+
const groupValues = column(source, config.group, "group").map((v) => String(v));
|
|
1043
|
+
requireOneRowPer(xs, groupValues);
|
|
1044
|
+
categories = distinct(xs, data.levels?.[config.x]);
|
|
1045
|
+
const groups = distinct(groupValues, data.levels?.[config.group]);
|
|
1046
|
+
const at = new Map(categories.map((c, i) => [c, i]));
|
|
1047
|
+
series = groups.flatMap(
|
|
1048
|
+
(g) => yColumns.map((y) => {
|
|
1049
|
+
const values = column(source, y, "y");
|
|
1050
|
+
const data2 = categories.map(() => null);
|
|
1051
|
+
xs.forEach((x, row) => {
|
|
1052
|
+
const i = at.get(x);
|
|
1053
|
+
if (groupValues[row] === g && i !== void 0) data2[i] = numberOrNull(values[row]);
|
|
1054
|
+
});
|
|
1055
|
+
const name = groups.length > 1 ? yColumns.length > 1 ? `${y} / ${g}` : g : y;
|
|
1056
|
+
return { name, data: data2 };
|
|
1057
|
+
})
|
|
1058
|
+
);
|
|
1059
|
+
} else {
|
|
1060
|
+
if (aggregate !== "none") requireOneRowPer(xs);
|
|
1061
|
+
categories = xs;
|
|
1062
|
+
series = yColumns.map((y) => ({ name: y, data: column(source, y, "y").map(numberOrNull) }));
|
|
1063
|
+
}
|
|
1064
|
+
const permutation = order(categories, series, config.order ?? "input");
|
|
1065
|
+
categories = permutation.map((i) => categories[i]);
|
|
1066
|
+
series = series.map((s) => ({ ...s, data: permutation.map((i) => s.data[i] ?? null) }));
|
|
1067
|
+
const palette = asArray(config.palette);
|
|
1068
|
+
const stack = config.stack ? "total" : void 0;
|
|
1069
|
+
const barWidth = typeof config.bar_width === "number" ? config.bar_width : void 0;
|
|
1070
|
+
const builtSeries = series.map((s, i) => {
|
|
1071
|
+
const single = series.length === 1;
|
|
1072
|
+
const perBar = single && palette.length > 1;
|
|
1073
|
+
const color = perBar ? void 0 : palette.length > 0 ? palette[i % palette.length] : void 0;
|
|
1074
|
+
return {
|
|
1075
|
+
type: "bar",
|
|
1076
|
+
...single ? {} : { name: s.name },
|
|
1077
|
+
data: perBar ? s.data.map((value2, j) => ({
|
|
1078
|
+
value: value2,
|
|
1079
|
+
itemStyle: { color: palette[(permutation[j] ?? j) % palette.length] }
|
|
1080
|
+
})) : s.data,
|
|
1081
|
+
...stack ? { stack } : {},
|
|
1082
|
+
...barWidth === void 0 ? {} : { barWidth },
|
|
1083
|
+
...color === void 0 ? {} : { itemStyle: { color } }
|
|
1084
|
+
};
|
|
1085
|
+
});
|
|
1086
|
+
const horizontal = config.horizontal ?? false;
|
|
1087
|
+
const category = {
|
|
1088
|
+
type: "category",
|
|
1089
|
+
data: categories,
|
|
1090
|
+
axisPointer: { type: "none" },
|
|
1091
|
+
axisTick: { show: false }
|
|
1092
|
+
};
|
|
1093
|
+
const value = {
|
|
1094
|
+
type: "value",
|
|
1095
|
+
axisTick: { show: false },
|
|
1096
|
+
...config.ylim ? { min: config.ylim[0], max: config.ylim[1] } : {}
|
|
1097
|
+
};
|
|
1098
|
+
const xAxis = horizontal ? value : category;
|
|
1099
|
+
const yAxis = horizontal ? category : value;
|
|
1100
|
+
if (config.xlab) Object.assign(xAxis, { name: config.xlab, nameLocation: "middle" });
|
|
1101
|
+
if (config.ylab) Object.assign(yAxis, { name: config.ylab, nameLocation: "middle" });
|
|
1102
|
+
const grid = cartesianGrid(config, Boolean(config.xlab || config.ylab));
|
|
1103
|
+
const dataZoom = config.zoom ? axisZoom(horizontal ? "y" : "x", grid) : void 0;
|
|
1104
|
+
return {
|
|
1105
|
+
...config.title ? { title: { text: config.title } } : {},
|
|
1106
|
+
tooltip: { trigger: "axis" },
|
|
1107
|
+
...series.length > 1 ? { legend: { data: series.map((s) => s.name) } } : {},
|
|
1108
|
+
xAxis,
|
|
1109
|
+
yAxis,
|
|
1110
|
+
grid,
|
|
1111
|
+
...dataZoom ? { dataZoom } : {},
|
|
1112
|
+
series: builtSeries,
|
|
1113
|
+
...appearance.animation === void 0 ? {} : { animation: appearance.animation }
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
function order(categories, series, how) {
|
|
1117
|
+
const index = categories.map((_, i) => i);
|
|
1118
|
+
if (how === "input") return index;
|
|
1119
|
+
const total = (i) => series.reduce((sum, s) => sum + (s.data[i] ?? 0), 0);
|
|
1120
|
+
const sign = how === "increasing" ? 1 : -1;
|
|
1121
|
+
return index.sort((a, b) => sign * (total(a) - total(b)) || a - b);
|
|
1122
|
+
}
|
|
1123
|
+
function requireOneRowPer(xs, groups) {
|
|
1124
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1125
|
+
xs.forEach((x, row) => {
|
|
1126
|
+
const key = groups ? `${x}\0${groups[row]}` : x;
|
|
1127
|
+
if (seen.has(key)) {
|
|
1128
|
+
const where = groups ? `category '${x}' in group '${groups[row]}'` : `category '${x}'`;
|
|
1129
|
+
throw new Error(
|
|
1130
|
+
`Several rows hold ${where}. Combine them before building, as the \`aggregate\` member says (sum, mean, median, or count).`
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
seen.add(key);
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// src/theme/tokens.ts
|
|
1138
|
+
var RTEMIS_PALETTE = Object.freeze([
|
|
1139
|
+
"#6CA3A0",
|
|
1140
|
+
"#F08904",
|
|
1141
|
+
"#BE2E5F",
|
|
1142
|
+
"#B3CFE8",
|
|
1143
|
+
"#0F6A66",
|
|
1144
|
+
"#FDB808",
|
|
1145
|
+
"#EA384A",
|
|
1146
|
+
"#466D96",
|
|
1147
|
+
"#526551",
|
|
1148
|
+
"#F384FF",
|
|
1149
|
+
"#7D0830",
|
|
1150
|
+
"#375D86",
|
|
1151
|
+
"#B1A7B3",
|
|
1152
|
+
"#7364F2",
|
|
1153
|
+
"#895140",
|
|
1154
|
+
"#C5A267"
|
|
1155
|
+
]);
|
|
1156
|
+
var SIGN_COLORS = Object.freeze({
|
|
1157
|
+
negative: "#2D83D3",
|
|
1158
|
+
neutral: "#808080",
|
|
1159
|
+
positive: "#C55E28"
|
|
1160
|
+
});
|
|
1161
|
+
function lightThemeTokens(overrides = {}) {
|
|
1162
|
+
return Object.freeze({
|
|
1163
|
+
scheme: "light",
|
|
1164
|
+
base_font_size: 12,
|
|
1165
|
+
palette: RTEMIS_PALETTE,
|
|
1166
|
+
bg_color: "#ffffff",
|
|
1167
|
+
fg_color: "rgba(0, 0, 0, 0.7)",
|
|
1168
|
+
negative_color: SIGN_COLORS.negative,
|
|
1169
|
+
neutral_color: SIGN_COLORS.neutral,
|
|
1170
|
+
positive_color: SIGN_COLORS.positive,
|
|
1171
|
+
...overrides
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
function darkThemeTokens(overrides = {}) {
|
|
1175
|
+
return Object.freeze({
|
|
1176
|
+
scheme: "dark",
|
|
1177
|
+
base_font_size: 12,
|
|
1178
|
+
palette: RTEMIS_PALETTE,
|
|
1179
|
+
bg_color: "#181818",
|
|
1180
|
+
fg_color: "rgba(255, 255, 255, 0.7)",
|
|
1181
|
+
title_color: "rgba(255, 255, 255, 0.9)",
|
|
1182
|
+
subtitle_color: "rgba(255, 255, 255, 0.5)",
|
|
1183
|
+
axis_color: "rgba(255, 255, 255, 0.3)",
|
|
1184
|
+
grid_color: "rgba(255, 255, 255, 0.1)",
|
|
1185
|
+
tooltip_bg: "rgba(20, 20, 20, 0.9)",
|
|
1186
|
+
tooltip_border_color: "rgba(255, 255, 255, 0.1)",
|
|
1187
|
+
negative_color: SIGN_COLORS.negative,
|
|
1188
|
+
neutral_color: SIGN_COLORS.neutral,
|
|
1189
|
+
positive_color: SIGN_COLORS.positive,
|
|
1190
|
+
...overrides
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
var DEFAULT_FONT_FAMILY = "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
|
|
1194
|
+
var GENERIC_FONT_FAMILIES = /* @__PURE__ */ new Set([
|
|
1195
|
+
"serif",
|
|
1196
|
+
"sans-serif",
|
|
1197
|
+
"monospace",
|
|
1198
|
+
"cursive",
|
|
1199
|
+
"fantasy",
|
|
1200
|
+
"math",
|
|
1201
|
+
"emoji",
|
|
1202
|
+
"fangsong",
|
|
1203
|
+
"system-ui",
|
|
1204
|
+
"ui-serif",
|
|
1205
|
+
"ui-sans-serif",
|
|
1206
|
+
"ui-monospace",
|
|
1207
|
+
"ui-rounded",
|
|
1208
|
+
"-apple-system",
|
|
1209
|
+
"blinkmacsystemfont"
|
|
1210
|
+
]);
|
|
1211
|
+
function fontStack(fontFamily) {
|
|
1212
|
+
if (fontFamily === void 0 || fontFamily === null) return DEFAULT_FONT_FAMILY;
|
|
1213
|
+
const entries = fontFamily.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
|
|
1214
|
+
if (entries.length === 0) throw new Error("`font_family` must be a nonempty font family.");
|
|
1215
|
+
const ident = /^-?[A-Za-z_][A-Za-z0-9_-]*( +-?[A-Za-z_][A-Za-z0-9_-]*)*$/;
|
|
1216
|
+
const quoted = /^(['"]).*\1$/;
|
|
1217
|
+
const out = entries.map((e) => {
|
|
1218
|
+
const generic = GENERIC_FONT_FAMILIES.has(e.toLowerCase());
|
|
1219
|
+
return quoted.test(e) || generic || ident.test(e) ? e : `'${e.replaceAll("'", "\\'")}'`;
|
|
1220
|
+
});
|
|
1221
|
+
const last = entries[entries.length - 1] ?? "";
|
|
1222
|
+
if (!GENERIC_FONT_FAMILIES.has(last.toLowerCase())) out.push(DEFAULT_FONT_FAMILY);
|
|
1223
|
+
return out.join(", ");
|
|
1224
|
+
}
|
|
1225
|
+
function roundHalfEven(x) {
|
|
1226
|
+
const floor = Math.floor(x);
|
|
1227
|
+
const diff = x - floor;
|
|
1228
|
+
if (Math.abs(diff - 0.5) > 1e-9) return Math.round(x);
|
|
1229
|
+
return floor % 2 === 0 ? floor : floor + 1;
|
|
1230
|
+
}
|
|
1231
|
+
function themeFontSizes(tokens) {
|
|
1232
|
+
const base = tokens.base_font_size;
|
|
1233
|
+
return {
|
|
1234
|
+
base,
|
|
1235
|
+
title: tokens.title_font_size ?? roundHalfEven(base * 1.2),
|
|
1236
|
+
subtitle: tokens.subtitle_font_size ?? base,
|
|
1237
|
+
axisLabel: tokens.axis_label_font_size ?? base,
|
|
1238
|
+
legend: tokens.legend_font_size ?? base,
|
|
1239
|
+
tooltip: tokens.tooltip_font_size ?? base
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function present(entries) {
|
|
1243
|
+
return Object.fromEntries(
|
|
1244
|
+
Object.entries(entries).filter(([, v]) => v !== void 0 && v !== null)
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
function themeOption(tokens) {
|
|
1248
|
+
const sizes = themeFontSizes(tokens);
|
|
1249
|
+
const dark = tokens.scheme === "dark";
|
|
1250
|
+
const fg = tokens.fg_color;
|
|
1251
|
+
const textStyle = { color: fg, fontFamily: fontStack(tokens.font_family), fontSize: sizes.base };
|
|
1252
|
+
const withText = (style) => ({ ...textStyle, ...style });
|
|
1253
|
+
const axisLabel = { fontSize: sizes.axisLabel, color: fg };
|
|
1254
|
+
const axisLine = tokens.axis_color ? { lineStyle: { color: tokens.axis_color } } : void 0;
|
|
1255
|
+
const valueAxis = present({
|
|
1256
|
+
axisLabel,
|
|
1257
|
+
axisLine,
|
|
1258
|
+
splitLine: tokens.grid_color ? { lineStyle: { color: tokens.grid_color } } : void 0
|
|
1259
|
+
});
|
|
1260
|
+
return {
|
|
1261
|
+
color: [...tokens.palette],
|
|
1262
|
+
backgroundColor: tokens.bg_color,
|
|
1263
|
+
textStyle,
|
|
1264
|
+
title: {
|
|
1265
|
+
textStyle: withText(present({ color: tokens.title_color, fontSize: sizes.title })),
|
|
1266
|
+
subtextStyle: withText(present({ color: tokens.subtitle_color, fontSize: sizes.subtitle }))
|
|
1267
|
+
},
|
|
1268
|
+
legend: {
|
|
1269
|
+
textStyle: withText({ color: tokens.legend_color ?? fg, fontSize: sizes.legend })
|
|
1270
|
+
},
|
|
1271
|
+
tooltip: present({
|
|
1272
|
+
backgroundColor: tokens.tooltip_bg,
|
|
1273
|
+
borderColor: tokens.tooltip_border_color,
|
|
1274
|
+
textStyle: withText({ color: tokens.tooltip_color ?? fg, fontSize: sizes.tooltip })
|
|
1275
|
+
}),
|
|
1276
|
+
visualMap: { textStyle },
|
|
1277
|
+
// Neutral controls leave the palette to encode data; every accent-bearing
|
|
1278
|
+
// slider state is set so ECharts' blue defaults cannot show.
|
|
1279
|
+
// spec: draw/visual-qa-docs#neutral-data-zoom-sliders
|
|
1280
|
+
dataZoom: {
|
|
1281
|
+
backgroundColor: "rgba(128,128,128,0.06)",
|
|
1282
|
+
borderColor: dark ? "#606060" : "#b0b0b0",
|
|
1283
|
+
fillerColor: "rgba(128,128,128,0.18)",
|
|
1284
|
+
dataBackground: {
|
|
1285
|
+
lineStyle: { color: "#808080" },
|
|
1286
|
+
areaStyle: { color: "#808080", opacity: 0.12 }
|
|
1287
|
+
},
|
|
1288
|
+
selectedDataBackground: {
|
|
1289
|
+
lineStyle: { color: dark ? "#b0b0b0" : "#707070" },
|
|
1290
|
+
areaStyle: { color: "#808080", opacity: 0.25 }
|
|
1291
|
+
},
|
|
1292
|
+
handleStyle: {
|
|
1293
|
+
color: dark ? "#303030" : "#ffffff",
|
|
1294
|
+
borderColor: dark ? "#909090" : "#808080"
|
|
1295
|
+
},
|
|
1296
|
+
moveHandleStyle: { color: "#909090", opacity: 0.6 },
|
|
1297
|
+
brushStyle: { color: "#808080", opacity: 0.3 },
|
|
1298
|
+
textStyle: axisLabel,
|
|
1299
|
+
emphasis: {
|
|
1300
|
+
handleStyle: { borderColor: dark ? "#cccccc" : "#505050" },
|
|
1301
|
+
moveHandleStyle: { color: dark ? "#b0b0b0" : "#707070" }
|
|
1302
|
+
}
|
|
1303
|
+
},
|
|
1304
|
+
line: { symbol: "circle" },
|
|
1305
|
+
categoryAxis: present({ axisLabel, axisLine, splitLine: { show: false } }),
|
|
1306
|
+
valueAxis,
|
|
1307
|
+
logAxis: valueAxis,
|
|
1308
|
+
timeAxis: valueAxis
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
|
|
899
1312
|
// src/index.ts
|
|
900
1313
|
var builders = Object.freeze({
|
|
901
|
-
a3: buildA3Option
|
|
1314
|
+
a3: buildA3Option,
|
|
1315
|
+
bar: buildBarOption
|
|
902
1316
|
});
|
|
903
1317
|
return __toCommonJS(index_exports);
|
|
904
1318
|
})();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grid margins and zoom presets shared by the cartesian builders.
|
|
3
|
+
* spec: draw/shared-builders#appearance
|
|
4
|
+
*/
|
|
5
|
+
/** The four plot-margin members of a config. */
|
|
6
|
+
export interface MarginMembers {
|
|
7
|
+
readonly margin_top?: number | null;
|
|
8
|
+
readonly margin_right?: number | null;
|
|
9
|
+
readonly margin_bottom?: number | null;
|
|
10
|
+
readonly margin_left?: number | null;
|
|
11
|
+
}
|
|
12
|
+
/** Margin in pixels on every side when a config sets none. */
|
|
13
|
+
export declare const DEFAULT_MARGIN = 36;
|
|
14
|
+
/**
|
|
15
|
+
* The grid of a cartesian chart. With no margin member set, every side takes
|
|
16
|
+
* {@link DEFAULT_MARGIN}; otherwise only the sides set are fixed. The grid's
|
|
17
|
+
* outer bounds hold the axis labels, and the axis names when an axis has one.
|
|
18
|
+
*/
|
|
19
|
+
export declare function cartesianGrid(config: MarginMembers, axisNames: boolean): Record<string, unknown>;
|
|
20
|
+
/** Identifies the slider of a zoom preset, so static export can return its band. */
|
|
21
|
+
export declare const ZOOM_SLIDER_ID = "rtemis-zoom-slider";
|
|
22
|
+
/**
|
|
23
|
+
* The zoom preset on one axis: a slider placed in a band the grid reserves on
|
|
24
|
+
* the axis side, and an inside zoom on Shift+wheel with drag panning, so the
|
|
25
|
+
* plain wheel scrolls the host page. Mutates `grid` to reserve the band.
|
|
26
|
+
* spec: draw/zoom-controls#design
|
|
27
|
+
*/
|
|
28
|
+
export declare function axisZoom(axis: "x" | "y", grid: Record<string, unknown>): Record<string, unknown>[];
|
|
29
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/shared/layout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,8DAA8D;AAC9D,eAAO,MAAM,cAAc,KAAK,CAAC;AAKjC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWhG;AAED,oFAAoF;AACpF,eAAO,MAAM,cAAc,uBAAuB,CAAC;AAQnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,GAAG,GAAG,GAAG,EACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAkB3B"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grid margins and zoom presets shared by the cartesian builders.
|
|
3
|
+
* spec: draw/shared-builders#appearance
|
|
4
|
+
*/
|
|
5
|
+
/** Margin in pixels on every side when a config sets none. */
|
|
6
|
+
export const DEFAULT_MARGIN = 36;
|
|
7
|
+
const SIDES = ["top", "right", "bottom", "left"];
|
|
8
|
+
/**
|
|
9
|
+
* The grid of a cartesian chart. With no margin member set, every side takes
|
|
10
|
+
* {@link DEFAULT_MARGIN}; otherwise only the sides set are fixed. The grid's
|
|
11
|
+
* outer bounds hold the axis labels, and the axis names when an axis has one.
|
|
12
|
+
*/
|
|
13
|
+
export function cartesianGrid(config, axisNames) {
|
|
14
|
+
const set = SIDES.filter((side) => typeof config[`margin_${side}`] === "number");
|
|
15
|
+
const grid = {};
|
|
16
|
+
for (const side of SIDES) {
|
|
17
|
+
const value = config[`margin_${side}`];
|
|
18
|
+
if (set.length === 0)
|
|
19
|
+
grid[side] = DEFAULT_MARGIN;
|
|
20
|
+
else if (typeof value === "number")
|
|
21
|
+
grid[side] = value;
|
|
22
|
+
}
|
|
23
|
+
grid.outerBoundsMode = "same";
|
|
24
|
+
grid.outerBoundsContain = axisNames ? "all" : "axisLabel";
|
|
25
|
+
return grid;
|
|
26
|
+
}
|
|
27
|
+
/** Identifies the slider of a zoom preset, so static export can return its band. */
|
|
28
|
+
export const ZOOM_SLIDER_ID = "rtemis-zoom-slider";
|
|
29
|
+
// ECharts' slider filler size, the brush handle drawn outside it, the gap to
|
|
30
|
+
// the plot, and its default grid margin on each side (SliderZoomView.ts).
|
|
31
|
+
const SLIDER_SIZE = 30;
|
|
32
|
+
const SLIDER_HANDLE = 7;
|
|
33
|
+
const SLIDER_GAP = 8;
|
|
34
|
+
/**
|
|
35
|
+
* The zoom preset on one axis: a slider placed in a band the grid reserves on
|
|
36
|
+
* the axis side, and an inside zoom on Shift+wheel with drag panning, so the
|
|
37
|
+
* plain wheel scrolls the host page. Mutates `grid` to reserve the band.
|
|
38
|
+
* spec: draw/zoom-controls#design
|
|
39
|
+
*/
|
|
40
|
+
export function axisZoom(axis, grid) {
|
|
41
|
+
const side = axis === "x" ? "bottom" : "right";
|
|
42
|
+
const current = grid[side];
|
|
43
|
+
const margin = typeof current === "number" ? current : axis === "x" ? 80 : 15;
|
|
44
|
+
const index = axis === "x" ? { xAxisIndex: 0 } : { yAxisIndex: 0 };
|
|
45
|
+
grid[side] = margin + SLIDER_HANDLE + SLIDER_SIZE + SLIDER_GAP;
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
type: "slider",
|
|
49
|
+
id: ZOOM_SLIDER_ID,
|
|
50
|
+
start: 0,
|
|
51
|
+
end: 100,
|
|
52
|
+
...index,
|
|
53
|
+
[side]: margin + SLIDER_HANDLE,
|
|
54
|
+
...(axis === "x" ? { height: SLIDER_SIZE } : { width: SLIDER_SIZE }),
|
|
55
|
+
},
|
|
56
|
+
{ type: "inside", ...index, zoomOnMouseWheel: "shift", moveOnMouseMove: true },
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/shared/layout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAG1D;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAqB,EAAE,SAAkB;IACrE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC;IACjF,MAAM,IAAI,GAA4B,EAAE,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QACvC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;aAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;IAC9B,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,oFAAoF;AACpF,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAEnD,6EAA6E;AAC7E,0EAA0E;AAC1E,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAe,EACf,IAA6B;IAE7B,MAAM,IAAI,GAAS,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9E,MAAM,KAAK,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACnE,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;IAC/D,OAAO;QACL;YACE,IAAI,EAAE,QAAQ;YACd,EAAE,EAAE,cAAc;YAClB,KAAK,EAAE,CAAC;YACR,GAAG,EAAE,GAAG;YACR,GAAG,KAAK;YACR,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa;YAC9B,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;SACrE;QACD,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE;KAC/E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The legend members of a config. rtemis.draw's widget and SVG export place
|
|
3
|
+
* the legend from them after the option is built.
|
|
4
|
+
* spec: draw/shared-builders#appearance
|
|
5
|
+
*/
|
|
6
|
+
export interface LegendMembers {
|
|
7
|
+
/** Edge or corner of the plotting area the legend anchors to. Default `"top"`. */
|
|
8
|
+
readonly legend_position?: "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
9
|
+
/** Outside or inside the plotting area. Default `"outside"`. */
|
|
10
|
+
readonly legend_placement?: "outside" | "inside";
|
|
11
|
+
/** Legend title; unset draws none. */
|
|
12
|
+
readonly legend_title?: string | null;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/shared/legend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,eAAe,CAAC,EACrB,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,UAAU,GACV,WAAW,GACX,aAAa,GACb,cAAc,CAAC;IACnB,gEAAgE;IAChE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjD,sCAAsC;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.js","sourceRoot":"","sources":["../../src/shared/legend.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Columns by name: an object from column name to the column's values, as an
|
|
3
|
+
* array or a typed array (rtemislive reads numeric columns from Arrow as
|
|
4
|
+
* `Float64Array`, with missing values as `NaN`).
|
|
5
|
+
*/
|
|
6
|
+
export type ColumnarSource = Readonly<Record<string, ArrayLike<unknown>>>;
|
|
7
|
+
/**
|
|
8
|
+
* A tabular chart's data: the columns the config binds, and the level order of
|
|
9
|
+
* any categorical column among them. spec: draw/shared-builders#tabular-data
|
|
10
|
+
*/
|
|
11
|
+
export interface TabularData {
|
|
12
|
+
readonly columns: ColumnarSource;
|
|
13
|
+
/** Level order of categorical columns, by column name. */
|
|
14
|
+
readonly levels?: Readonly<Record<string, readonly string[]>>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The distinct values of a column in level order: the levels that occur, then
|
|
18
|
+
* values not among the levels in order of appearance.
|
|
19
|
+
*/
|
|
20
|
+
export declare function distinct(values: readonly string[], levels?: readonly string[]): string[];
|
|
21
|
+
/** A config member that names one or more columns, as JSON may carry it. */
|
|
22
|
+
export type ColumnNames = string | readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* The values of a column as an array, or an error naming the column and the
|
|
25
|
+
* member. A typed array is copied, so mapping it to text keeps the text.
|
|
26
|
+
*/
|
|
27
|
+
export declare function column(source: ColumnarSource, name: string, member: string): readonly unknown[];
|
|
28
|
+
/** A one-or-many member as an array; a JSON scalar is one element. */
|
|
29
|
+
export declare function asArray<T>(value: T | readonly T[] | null | undefined): readonly T[];
|
|
30
|
+
/** A numeric cell, or `null` for a missing or non-finite one. */
|
|
31
|
+
export declare function numberOrNull(value: unknown): number | null;
|
|
32
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/shared/source.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC/D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAKxF;AAED,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAM/F;AAED,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC,EAAE,CAGnF;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAE1D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The distinct values of a column in level order: the levels that occur, then
|
|
3
|
+
* values not among the levels in order of appearance.
|
|
4
|
+
*/
|
|
5
|
+
export function distinct(values, levels) {
|
|
6
|
+
const seen = new Set(values);
|
|
7
|
+
const ordered = (levels ?? []).filter((level) => seen.has(level));
|
|
8
|
+
const known = new Set(ordered);
|
|
9
|
+
return [...ordered, ...[...seen].filter((v) => !known.has(v))];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The values of a column as an array, or an error naming the column and the
|
|
13
|
+
* member. A typed array is copied, so mapping it to text keeps the text.
|
|
14
|
+
*/
|
|
15
|
+
export function column(source, name, member) {
|
|
16
|
+
const values = source[name];
|
|
17
|
+
if (values === undefined) {
|
|
18
|
+
throw new Error(`Column '${name}' (config member '${member}') is not in the data.`);
|
|
19
|
+
}
|
|
20
|
+
return Array.isArray(values) ? values : Array.from(values);
|
|
21
|
+
}
|
|
22
|
+
/** A one-or-many member as an array; a JSON scalar is one element. */
|
|
23
|
+
export function asArray(value) {
|
|
24
|
+
if (value === null || value === undefined)
|
|
25
|
+
return [];
|
|
26
|
+
return Array.isArray(value) ? value : [value];
|
|
27
|
+
}
|
|
28
|
+
/** A numeric cell, or `null` for a missing or non-finite one. */
|
|
29
|
+
export function numberOrNull(value) {
|
|
30
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=source.js.map
|