vvplot 0.4.2 → 0.4.3
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/vvplot.esm.js +89 -40
- package/dist/vvplot.esm.min.js +18 -18
- package/dist/vvplot.global.js +89 -40
- package/dist/vvplot.global.min.js +18 -18
- package/package.json +1 -1
package/dist/vvplot.global.js
CHANGED
|
@@ -1661,7 +1661,44 @@ var VVPlot = (function(exports, vue) {
|
|
|
1661
1661
|
new RegExp(
|
|
1662
1662
|
"\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
|
|
1663
1663
|
);
|
|
1664
|
-
class
|
|
1664
|
+
class AsisString extends String {
|
|
1665
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
1666
|
+
constructor(str) {
|
|
1667
|
+
const s = String(str);
|
|
1668
|
+
if (AsisString.#cache.has(s)) {
|
|
1669
|
+
return AsisString.#cache.get(s);
|
|
1670
|
+
}
|
|
1671
|
+
super(s);
|
|
1672
|
+
AsisString.#cache.set(s, this);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
class AsisNumber extends Number {
|
|
1676
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
1677
|
+
constructor(num2) {
|
|
1678
|
+
const n = Number(num2);
|
|
1679
|
+
if (AsisNumber.#cache.has(n)) {
|
|
1680
|
+
return AsisNumber.#cache.get(n);
|
|
1681
|
+
}
|
|
1682
|
+
super(n);
|
|
1683
|
+
AsisNumber.#cache.set(n, this);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
class Asis extends String {
|
|
1687
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
1688
|
+
constructor(value) {
|
|
1689
|
+
if (typeof value === "string" || value instanceof String) {
|
|
1690
|
+
return new AsisString(value);
|
|
1691
|
+
}
|
|
1692
|
+
if (typeof value === "number" || value instanceof Number) {
|
|
1693
|
+
return new AsisNumber(value);
|
|
1694
|
+
}
|
|
1695
|
+
throw new Error("Unsupported type");
|
|
1696
|
+
}
|
|
1697
|
+
static [Symbol.hasInstance](obj) {
|
|
1698
|
+
return obj instanceof AsisString || obj instanceof AsisNumber;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
class EnumElement {
|
|
1665
1702
|
constructor(label, value, level) {
|
|
1666
1703
|
this.label = label;
|
|
1667
1704
|
this.value = value;
|
|
@@ -1677,20 +1714,20 @@ var VVPlot = (function(exports, vue) {
|
|
|
1677
1714
|
return this.label;
|
|
1678
1715
|
}
|
|
1679
1716
|
}
|
|
1680
|
-
class
|
|
1717
|
+
class EnumLevel extends Array {
|
|
1681
1718
|
/**
|
|
1682
1719
|
* return:
|
|
1683
|
-
* x if x is a
|
|
1684
|
-
* new
|
|
1685
|
-
* new
|
|
1720
|
+
* x if x is a EnumLevel
|
|
1721
|
+
* new EnumLevel from distinct values of x, ordered by natural order, if x is iterable
|
|
1722
|
+
* new EnumLevel from keys of x, orderd by coresponing values, if x is an object
|
|
1686
1723
|
* @param {*} x
|
|
1687
1724
|
* @param {function} [sortkey]
|
|
1688
|
-
* @returns {
|
|
1725
|
+
* @returns {EnumLevel}
|
|
1689
1726
|
*/
|
|
1690
1727
|
static from(x2) {
|
|
1691
1728
|
if (x2 instanceof this) return x2;
|
|
1692
1729
|
if (x2[Symbol.iterator]) {
|
|
1693
|
-
let lvl = unique(Array.from(x2).map((x3) => String(x3))).sort((a, b) => compare(a, b, { numeric: true }));
|
|
1730
|
+
let lvl = unique(Array.from(x2).filter((x3) => !(x3 instanceof Asis)).map((x3) => String(x3))).sort((a, b) => compare(a, b, { numeric: true }));
|
|
1694
1731
|
return new this(...lvl);
|
|
1695
1732
|
} else if (typeof x2 === "object") {
|
|
1696
1733
|
let lvl = Object.keys(x2).map((x3) => String(x3)).sort((a, b) => compare(x2[a], x2[b]));
|
|
@@ -1699,7 +1736,7 @@ var VVPlot = (function(exports, vue) {
|
|
|
1699
1736
|
throw new Error(`Invalid level values: ${x2}`);
|
|
1700
1737
|
}
|
|
1701
1738
|
/**
|
|
1702
|
-
* Check if two
|
|
1739
|
+
* Check if two EnumLevel are equal, i.e. they have the same labels in the same order
|
|
1703
1740
|
* @param {string[]} level
|
|
1704
1741
|
*/
|
|
1705
1742
|
static isEqual(a, b) {
|
|
@@ -1708,20 +1745,20 @@ var VVPlot = (function(exports, vue) {
|
|
|
1708
1745
|
}
|
|
1709
1746
|
}
|
|
1710
1747
|
/**
|
|
1711
|
-
* build a
|
|
1748
|
+
* build a EnumLevel
|
|
1712
1749
|
* @param {string[]} level
|
|
1713
1750
|
*/
|
|
1714
1751
|
constructor(...level) {
|
|
1715
|
-
level = level.map((x2, i) => new
|
|
1752
|
+
level = level.map((x2, i) => new EnumElement(String(x2), i));
|
|
1716
1753
|
level.forEach((l) => l.level = level);
|
|
1717
1754
|
level.mapping = Object.fromEntries(level.map((fct) => [fct, fct]));
|
|
1718
|
-
Object.setPrototypeOf(level,
|
|
1755
|
+
Object.setPrototypeOf(level, EnumLevel.prototype);
|
|
1719
1756
|
return level;
|
|
1720
1757
|
}
|
|
1721
1758
|
/**
|
|
1722
1759
|
* get the level instance by index or key
|
|
1723
1760
|
* @param {(number|string)} idx
|
|
1724
|
-
* @returns {
|
|
1761
|
+
* @returns {EnumElement}
|
|
1725
1762
|
*/
|
|
1726
1763
|
getItem(idx) {
|
|
1727
1764
|
if (typeof idx === "number" || idx instanceof Number) {
|
|
@@ -1733,15 +1770,15 @@ var VVPlot = (function(exports, vue) {
|
|
|
1733
1770
|
/**
|
|
1734
1771
|
* convert an array to a GEnum array
|
|
1735
1772
|
* @param {string[]} arr array to be converted, preferably a string array (items of other types will be converted to string)
|
|
1736
|
-
* @returns {
|
|
1773
|
+
* @returns {EnumElement[]}
|
|
1737
1774
|
*/
|
|
1738
1775
|
apply(arr) {
|
|
1739
|
-
let result = arr.map((x2) => this.mapping[x2]);
|
|
1776
|
+
let result = arr.map((x2) => x2 instanceof Asis ? x2 : this.mapping[x2]);
|
|
1740
1777
|
result.level = this;
|
|
1741
1778
|
return result;
|
|
1742
1779
|
}
|
|
1743
1780
|
}
|
|
1744
|
-
function
|
|
1781
|
+
function is_continuous(x2) {
|
|
1745
1782
|
return typeof x2 === "number" || x2 instanceof Number || x2 instanceof Date;
|
|
1746
1783
|
}
|
|
1747
1784
|
function plus$1(a, b = 0) {
|
|
@@ -1751,30 +1788,30 @@ var VVPlot = (function(exports, vue) {
|
|
|
1751
1788
|
}
|
|
1752
1789
|
const numutils = {
|
|
1753
1790
|
min(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
1754
|
-
if (na_rm) arr = arr.filter(
|
|
1791
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
1755
1792
|
if (infinity_rm) arr = arr.filter((x2) => isFinite(x2));
|
|
1756
1793
|
return Array.from(arr).reduce((a, b) => a < b ? a : b, Infinity);
|
|
1757
1794
|
},
|
|
1758
1795
|
max(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
1759
|
-
if (na_rm) arr = arr.filter(
|
|
1796
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
1760
1797
|
if (infinity_rm) arr = arr.filter((x2) => isFinite(x2));
|
|
1761
1798
|
return Array.from(arr).reduce((a, b) => a > b ? a : b, -Infinity);
|
|
1762
1799
|
},
|
|
1763
1800
|
mean(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
1764
|
-
if (na_rm) arr = arr.filter(
|
|
1801
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
1765
1802
|
if (infinity_rm) arr = arr.filter((x2) => isFinite(x2));
|
|
1766
1803
|
if (arr.length == 0) return NaN;
|
|
1767
1804
|
return Array.from(arr).reduce((a, v) => a + v, 0) / arr.length;
|
|
1768
1805
|
},
|
|
1769
1806
|
sd(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
1770
|
-
if (na_rm) arr = arr.filter(
|
|
1807
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
1771
1808
|
if (infinity_rm) arr = arr.filter((x2) => isFinite(x2));
|
|
1772
1809
|
if (arr.length <= 1) return NaN;
|
|
1773
1810
|
let mean = Array.from(arr).reduce((a, v) => a + v, 0) / arr.length;
|
|
1774
1811
|
return Math.sqrt(Array.from(arr).reduce((a, v) => a + (v - mean) ** 2, 0) / (arr.length - 1));
|
|
1775
1812
|
},
|
|
1776
1813
|
quantile(arr, p, { na_rm = true, infinity_rm = true } = {}) {
|
|
1777
|
-
if (na_rm) arr = arr.filter(
|
|
1814
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
1778
1815
|
if (infinity_rm) arr = arr.filter((x2) => isFinite(x2));
|
|
1779
1816
|
if (arr.length == 0) return NaN;
|
|
1780
1817
|
arr = Array.from(arr).sort((a, b) => a - b);
|
|
@@ -1783,7 +1820,7 @@ var VVPlot = (function(exports, vue) {
|
|
|
1783
1820
|
return arr[lo] * (hi - idx) + arr[hi] * (idx - lo);
|
|
1784
1821
|
},
|
|
1785
1822
|
extent(arr, { na_rm = true, infinity_rm = true } = {}) {
|
|
1786
|
-
if (na_rm) arr = arr.filter(
|
|
1823
|
+
if (na_rm) arr = arr.filter(is_continuous);
|
|
1787
1824
|
if (infinity_rm) arr = arr.filter((x2) => isFinite(x2));
|
|
1788
1825
|
if (arr.length == 0) return new Array(2);
|
|
1789
1826
|
let min = Array.from(arr).reduce((a, b) => a < b ? a : b, Infinity), max = Array.from(arr).reduce((a, b) => a > b ? a : b, -Infinity);
|
|
@@ -6591,7 +6628,7 @@ var VVPlot = (function(exports, vue) {
|
|
|
6591
6628
|
function format_auto(opts) {
|
|
6592
6629
|
let formatter_number = format_number(opts), formatter_datetime = format_datetime(opts);
|
|
6593
6630
|
return function(x2, i, arr = [x2]) {
|
|
6594
|
-
if (x2 instanceof
|
|
6631
|
+
if (x2 instanceof EnumElement) return String(x2);
|
|
6595
6632
|
if (x2 instanceof Date) return formatter_datetime(x2, i, arr);
|
|
6596
6633
|
return formatter_number(x2, i, arr);
|
|
6597
6634
|
};
|
|
@@ -6672,7 +6709,7 @@ var VVPlot = (function(exports, vue) {
|
|
|
6672
6709
|
this.$fnames = {};
|
|
6673
6710
|
for (const aes in $$aes) {
|
|
6674
6711
|
this.$fnames[aes] = String($$aes[aes]);
|
|
6675
|
-
data[aes] = $$data.map($$aes[aes]);
|
|
6712
|
+
data[aes] = $$data.map($$aes[aes]).map((x2) => x2 instanceof String || x2 instanceof Number ? new Asis(x2) : x2);
|
|
6676
6713
|
}
|
|
6677
6714
|
data.$raw = $$data;
|
|
6678
6715
|
let core_aes = stat?.core_attrs ?? ["x", "y", "xnudge", "ynudge"];
|
|
@@ -6723,9 +6760,9 @@ var VVPlot = (function(exports, vue) {
|
|
|
6723
6760
|
if ($$levels?.[aes] != null) {
|
|
6724
6761
|
scale.level = $$levels[aes];
|
|
6725
6762
|
} else if (values.some(is_categorical)) {
|
|
6726
|
-
scale.level =
|
|
6763
|
+
scale.level = EnumLevel.from(values);
|
|
6727
6764
|
} else {
|
|
6728
|
-
scale.extent = numutils.extent(values);
|
|
6765
|
+
scale.extent = numutils.extent(values.filter((v) => !(v instanceof Asis)));
|
|
6729
6766
|
}
|
|
6730
6767
|
}
|
|
6731
6768
|
this.applyScale(aes, scale);
|
|
@@ -6755,7 +6792,8 @@ var VVPlot = (function(exports, vue) {
|
|
|
6755
6792
|
if (scale.level) values = scale.level.apply(values);
|
|
6756
6793
|
if (scale.limits) values.extent = scale.limits;
|
|
6757
6794
|
scale.aes = aes;
|
|
6758
|
-
|
|
6795
|
+
let scaled = scale(values);
|
|
6796
|
+
this.data[aes] = values.map((v, i) => v instanceof Asis ? v.valueOf() : scaled[i]);
|
|
6759
6797
|
this.scales[aes] = scale;
|
|
6760
6798
|
}
|
|
6761
6799
|
applyCoordScale(coord_levels) {
|
|
@@ -6790,9 +6828,9 @@ var VVPlot = (function(exports, vue) {
|
|
|
6790
6828
|
if (levels?.[aes] != null) {
|
|
6791
6829
|
scale.level = levels[aes];
|
|
6792
6830
|
} else if (values.some(is_categorical)) {
|
|
6793
|
-
scale.level =
|
|
6831
|
+
scale.level = EnumLevel.from(values);
|
|
6794
6832
|
} else {
|
|
6795
|
-
scale.extent = numutils.extent(values);
|
|
6833
|
+
scale.extent = numutils.extent(values.filter((v) => !(v instanceof Asis)));
|
|
6796
6834
|
}
|
|
6797
6835
|
}
|
|
6798
6836
|
scale._title = this.layers.reduce((v, layer) => v ?? layer.$fnames?.[aes], null);
|
|
@@ -6824,17 +6862,17 @@ var VVPlot = (function(exports, vue) {
|
|
|
6824
6862
|
useCoordLevels(levels = {}) {
|
|
6825
6863
|
for (const aes of ["x", "y"]) {
|
|
6826
6864
|
if (levels[aes]) {
|
|
6827
|
-
this.levels[aes] = new
|
|
6865
|
+
this.levels[aes] = new EnumLevel(...levels[aes]);
|
|
6828
6866
|
} else {
|
|
6829
6867
|
let values = this.layers.flatMap((layer) => {
|
|
6830
6868
|
let fn = vvgeom[layer.geom].get_values ?? vvgeom[layer.geom].get_range;
|
|
6831
6869
|
return fn?.(layer.$data, aes);
|
|
6832
6870
|
});
|
|
6833
6871
|
if (values.some(is_categorical)) {
|
|
6834
|
-
this.levels[aes] =
|
|
6872
|
+
this.levels[aes] = EnumLevel.from(values);
|
|
6835
6873
|
} else {
|
|
6836
6874
|
values = this.layers.flatMap((layer) => vvgeom[layer.geom].get_range?.(layer.$data, aes)).filter((v) => !isNaN(v));
|
|
6837
|
-
this.extents[aes] = numutils.extent(values);
|
|
6875
|
+
this.extents[aes] = numutils.extent(values.filter((v) => !(v instanceof Asis)));
|
|
6838
6876
|
}
|
|
6839
6877
|
}
|
|
6840
6878
|
}
|
|
@@ -18033,12 +18071,22 @@ var VVPlot = (function(exports, vue) {
|
|
|
18033
18071
|
setup(__props, { emit: __emit }) {
|
|
18034
18072
|
const model = vue.useModel(__props, "modelValue");
|
|
18035
18073
|
const config = vue.createPropsRestProxy(__props, ["coord2pos", "pos2coord", "layout", "theme", "flip", "activeTransform", "transition"]);
|
|
18074
|
+
function normalize2({ xmin, xmax, ymin, ymax, xreverse = false, yreverse = false } = {}) {
|
|
18075
|
+
if ([xmin, xmax, ymin, ymax].every((v) => v == null)) return null;
|
|
18076
|
+
if (xmin != null && xmax != null && xmin > xmax) [xmin, xmax, xreverse] = [xmax, xmin, !xreverse];
|
|
18077
|
+
if (ymin != null && ymax != null && ymin > ymax) [ymin, ymax, yreverse] = [ymax, ymin, !yreverse];
|
|
18078
|
+
let coord = { xreverse, yreverse };
|
|
18079
|
+
if (xmin != null && isFinite(xmin)) coord.xmin = xmin;
|
|
18080
|
+
if (xmax != null && isFinite(xmax)) coord.xmax = xmax;
|
|
18081
|
+
if (ymin != null && isFinite(ymin)) coord.ymin = ymin;
|
|
18082
|
+
if (ymax != null && isFinite(ymax)) coord.ymax = ymax;
|
|
18083
|
+
return coord;
|
|
18084
|
+
}
|
|
18036
18085
|
const position = vue.computed(() => {
|
|
18037
18086
|
if (model.value == null || model.value.hidden) return null;
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
if (vmin != null && vmax != null) [vmin, vmax] = [vmin, vmax].sort((a, b) => a - b);
|
|
18087
|
+
let coord = normalize2(model.value);
|
|
18088
|
+
if (coord == null) return null;
|
|
18089
|
+
let { hmin, hmax, vmin, vmax } = __props.coord2pos(coord, { limited: true }), pos = __props.coord2pos(coord);
|
|
18042
18090
|
return { hmin, hmax, vmin, vmax, pos };
|
|
18043
18091
|
});
|
|
18044
18092
|
const transform = vue.computed(() => {
|
|
@@ -18151,7 +18199,8 @@ var VVPlot = (function(exports, vue) {
|
|
|
18151
18199
|
e.stopPropagation();
|
|
18152
18200
|
e.preventDefault();
|
|
18153
18201
|
e.target.setPointerCapture(e.pointerId);
|
|
18154
|
-
let
|
|
18202
|
+
let { xreverse: $xreverse, yreverse: $yreverse, ...coord0 } = normalize2(model.value);
|
|
18203
|
+
let pos0 = __props.coord2pos(coord0);
|
|
18155
18204
|
let { h: coordL, v: coordT } = __props.pos2coord({ h: pos0.hmin, v: pos0.vmin }), { h: coordR, v: coordB } = __props.pos2coord({ h: pos0.hmax, v: pos0.vmax });
|
|
18156
18205
|
let { hmin: hmin0, hmax: hmax0, vmin: vmin0, vmax: vmax0 } = pos0;
|
|
18157
18206
|
let pointerMoved = false;
|
|
@@ -18218,10 +18267,10 @@ var VVPlot = (function(exports, vue) {
|
|
|
18218
18267
|
let res = {
|
|
18219
18268
|
xmin,
|
|
18220
18269
|
xmax,
|
|
18221
|
-
xreverse: Boolean(xreverse ^
|
|
18270
|
+
xreverse: Boolean(xreverse ^ $xreverse),
|
|
18222
18271
|
ymin,
|
|
18223
18272
|
ymax,
|
|
18224
|
-
yreverse: Boolean(yreverse ^
|
|
18273
|
+
yreverse: Boolean(yreverse ^ $yreverse)
|
|
18225
18274
|
}, event = new PointerEvent("select", e);
|
|
18226
18275
|
model.value = dropNull(res);
|
|
18227
18276
|
emit("selectend");
|
|
@@ -18460,13 +18509,13 @@ var VVPlot = (function(exports, vue) {
|
|
|
18460
18509
|
},
|
|
18461
18510
|
setup(__props) {
|
|
18462
18511
|
const guides = vue.computed(() => {
|
|
18463
|
-
let guide_scales = new Map(Array.from(__props.scales).filter(([fn]) => fn.legend !== false));
|
|
18512
|
+
let guide_scales = new Map(Array.from(__props.scales).filter(([fn]) => fn.legend !== false && fn.limits?.min != fn.limits?.max));
|
|
18464
18513
|
let scale_fns = Array.from(guide_scales.keys());
|
|
18465
18514
|
let keys = scale_fns.map((s) => s.key);
|
|
18466
18515
|
let n = 1;
|
|
18467
18516
|
for (let i = 0; i < keys.length; i++) {
|
|
18468
18517
|
while (keys.includes("_guide_" + n)) n++;
|
|
18469
|
-
keys[i] ??= keys.find((_, j) => keys[j] != null &&
|
|
18518
|
+
keys[i] ??= keys.find((_, j) => keys[j] != null && EnumLevel.isEqual(scale_fns[j].level, scale_fns[i].level)) ?? "_guide_" + n;
|
|
18470
18519
|
}
|
|
18471
18520
|
let types = scale_fns.map((s) => getGuideType(s));
|
|
18472
18521
|
let groups = interaction(keys, types);
|