@antv/gpt-vis 1.3.2 → 1.4.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 +261 -137
- package/README.zh-CN.md +263 -116
- package/dist/cjs/annotation/components/bottom-n.d.ts +2 -0
- package/dist/cjs/annotation/components/bottom-n.js +57 -0
- package/dist/cjs/annotation/components/centroid.d.ts +2 -0
- package/dist/cjs/annotation/components/centroid.js +75 -0
- package/dist/cjs/annotation/components/connector.d.ts +25 -0
- package/dist/cjs/annotation/components/connector.js +298 -0
- package/dist/cjs/annotation/components/contribution.d.ts +3 -0
- package/dist/cjs/annotation/components/contribution.js +136 -0
- package/dist/cjs/annotation/components/crossing.d.ts +3 -0
- package/dist/cjs/annotation/components/crossing.js +504 -0
- package/dist/cjs/annotation/components/event.d.ts +2 -0
- package/dist/cjs/annotation/components/event.js +62 -0
- package/dist/cjs/annotation/components/first.d.ts +2 -0
- package/dist/cjs/annotation/components/first.js +42 -0
- package/dist/cjs/annotation/components/group.d.ts +3 -0
- package/dist/cjs/annotation/components/group.js +73 -0
- package/dist/cjs/annotation/components/highlight.d.ts +14 -0
- package/dist/cjs/annotation/components/highlight.js +552 -0
- package/dist/cjs/annotation/components/index.d.ts +34 -0
- package/dist/cjs/annotation/components/index.js +128 -0
- package/dist/cjs/annotation/components/last.d.ts +2 -0
- package/dist/cjs/annotation/components/last.js +42 -0
- package/dist/cjs/annotation/components/max-x.d.ts +2 -0
- package/dist/cjs/annotation/components/max-x.js +41 -0
- package/dist/cjs/annotation/components/max-y.d.ts +2 -0
- package/dist/cjs/annotation/components/max-y.js +41 -0
- package/dist/cjs/annotation/components/mean.d.ts +2 -0
- package/dist/cjs/annotation/components/mean.js +50 -0
- package/dist/cjs/annotation/components/median.d.ts +2 -0
- package/dist/cjs/annotation/components/median.js +49 -0
- package/dist/cjs/annotation/components/min-x.d.ts +2 -0
- package/dist/cjs/annotation/components/min-x.js +41 -0
- package/dist/cjs/annotation/components/min-y.d.ts +2 -0
- package/dist/cjs/annotation/components/min-y.js +41 -0
- package/dist/cjs/annotation/components/outlier.d.ts +3 -0
- package/dist/cjs/annotation/components/outlier.js +83 -0
- package/dist/cjs/annotation/components/path.d.ts +20 -0
- package/dist/cjs/annotation/components/path.js +147 -0
- package/dist/cjs/annotation/components/peak.d.ts +2 -0
- package/dist/cjs/annotation/components/peak.js +42 -0
- package/dist/cjs/annotation/components/point.d.ts +26 -0
- package/dist/cjs/annotation/components/point.js +241 -0
- package/dist/cjs/annotation/components/quadrant.d.ts +3 -0
- package/dist/cjs/annotation/components/quadrant.js +97 -0
- package/dist/cjs/annotation/components/quantile.d.ts +2 -0
- package/dist/cjs/annotation/components/quantile.js +49 -0
- package/dist/cjs/annotation/components/range-inside.d.ts +2 -0
- package/dist/cjs/annotation/components/range-inside.js +65 -0
- package/dist/cjs/annotation/components/range-outside.d.ts +2 -0
- package/dist/cjs/annotation/components/range-outside.js +65 -0
- package/dist/cjs/annotation/components/range-x.d.ts +2 -0
- package/dist/cjs/annotation/components/range-x.js +39 -0
- package/dist/cjs/annotation/components/range-y.d.ts +2 -0
- package/dist/cjs/annotation/components/range-y.js +39 -0
- package/dist/cjs/annotation/components/range.d.ts +15 -0
- package/dist/cjs/annotation/components/range.js +87 -0
- package/dist/cjs/annotation/components/target.d.ts +2 -0
- package/dist/cjs/annotation/components/target.js +51 -0
- package/dist/cjs/annotation/components/text.d.ts +15 -0
- package/dist/cjs/annotation/components/text.js +74 -0
- package/dist/cjs/annotation/components/threshold-highlight.d.ts +3 -0
- package/dist/cjs/annotation/components/threshold-highlight.js +223 -0
- package/dist/cjs/annotation/components/threshold-x.d.ts +2 -0
- package/dist/cjs/annotation/components/threshold-x.js +39 -0
- package/dist/cjs/annotation/components/threshold-y.d.ts +2 -0
- package/dist/cjs/annotation/components/threshold-y.js +40 -0
- package/dist/cjs/annotation/components/top-n.d.ts +2 -0
- package/dist/cjs/annotation/components/top-n.js +57 -0
- package/dist/cjs/annotation/components/valley.d.ts +2 -0
- package/dist/cjs/annotation/components/valley.js +42 -0
- package/dist/cjs/annotation/index.d.ts +1 -0
- package/dist/cjs/annotation/index.js +29 -0
- package/dist/cjs/annotation/label.d.ts +38 -0
- package/dist/cjs/annotation/label.js +347 -0
- package/dist/cjs/annotation/layout.d.ts +12 -0
- package/dist/cjs/annotation/layout.js +142 -0
- package/dist/cjs/annotation/merge.d.ts +19 -0
- package/dist/cjs/annotation/merge.js +60 -0
- package/dist/cjs/annotation/registry.d.ts +190 -0
- package/dist/cjs/annotation/registry.js +134 -0
- package/dist/cjs/annotation/runtime/g2.d.ts +90 -0
- package/dist/cjs/annotation/runtime/g2.js +521 -0
- package/dist/cjs/annotation/runtime/g6.d.ts +40 -0
- package/dist/cjs/annotation/runtime/g6.js +310 -0
- package/dist/cjs/annotation/runtime/index.d.ts +11 -0
- package/dist/cjs/annotation/runtime/index.js +41 -0
- package/dist/cjs/annotation/runtime/summary.d.ts +17 -0
- package/dist/cjs/annotation/runtime/summary.js +39 -0
- package/dist/cjs/annotation/runtime/table.d.ts +16 -0
- package/dist/cjs/annotation/runtime/table.js +39 -0
- package/dist/cjs/annotation/utils.d.ts +40 -0
- package/dist/cjs/annotation/utils.js +275 -0
- package/dist/cjs/theme/annotation.d.ts +236 -0
- package/dist/cjs/theme/annotation.js +167 -0
- package/dist/cjs/theme/g2.js +13 -15
- package/dist/cjs/theme/g6.js +2 -2
- package/dist/cjs/theme/summary.js +2 -2
- package/dist/cjs/types/annotation.d.ts +310 -0
- package/dist/cjs/types/annotation.js +17 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/util/axis.d.ts +28 -0
- package/dist/cjs/util/axis.js +184 -0
- package/dist/cjs/util/components.d.ts +0 -10
- package/dist/cjs/util/components.js +9 -64
- package/dist/cjs/util/index.d.ts +7 -4
- package/dist/cjs/util/index.js +53 -9
- package/dist/cjs/vis/area/index.d.ts +2 -0
- package/dist/cjs/vis/area/index.js +30 -13
- package/dist/cjs/vis/bar/index.d.ts +2 -0
- package/dist/cjs/vis/bar/index.js +37 -7
- package/dist/cjs/vis/boxplot/index.js +14 -3
- package/dist/cjs/vis/column/index.d.ts +2 -0
- package/dist/cjs/vis/column/index.js +28 -9
- package/dist/cjs/vis/dual-axes/index.js +9 -9
- package/dist/cjs/vis/fishbone-diagram/index.js +2 -2
- package/dist/cjs/vis/flow-diagram/index.js +2 -2
- package/dist/cjs/vis/funnel/index.js +10 -13
- package/dist/cjs/vis/histogram/index.js +2 -2
- package/dist/cjs/vis/indented-tree/index.js +2 -2
- package/dist/cjs/vis/line/index.d.ts +2 -0
- package/dist/cjs/vis/line/index.js +26 -10
- package/dist/cjs/vis/liquid/index.js +2 -2
- package/dist/cjs/vis/mindmap/index.js +2 -2
- package/dist/cjs/vis/network-graph/index.d.ts +2 -0
- package/dist/cjs/vis/network-graph/index.js +24 -3
- package/dist/cjs/vis/organization-chart/index.js +2 -2
- package/dist/cjs/vis/pie/index.d.ts +2 -0
- package/dist/cjs/vis/pie/index.js +21 -10
- package/dist/cjs/vis/radar/index.js +4 -6
- package/dist/cjs/vis/sankey/index.js +14 -1
- package/dist/cjs/vis/scatter/index.d.ts +10 -3
- package/dist/cjs/vis/scatter/index.js +18 -7
- package/dist/cjs/vis/summary/index.d.ts +9 -2
- package/dist/cjs/vis/summary/index.js +25 -8
- package/dist/cjs/vis/table/index.d.ts +2 -0
- package/dist/cjs/vis/table/index.js +48 -30
- package/dist/cjs/vis/venn/index.js +2 -2
- package/dist/cjs/vis/violin/index.js +14 -3
- package/dist/cjs/vis/waterfall/index.js +17 -9
- package/dist/cjs/vis/word-cloud/index.js +4 -6
- package/dist/esm/annotation/components/bottom-n.d.ts +2 -0
- package/dist/esm/annotation/components/bottom-n.js +42 -0
- package/dist/esm/annotation/components/centroid.d.ts +2 -0
- package/dist/esm/annotation/components/centroid.js +73 -0
- package/dist/esm/annotation/components/connector.d.ts +25 -0
- package/dist/esm/annotation/components/connector.js +332 -0
- package/dist/esm/annotation/components/contribution.d.ts +3 -0
- package/dist/esm/annotation/components/contribution.js +174 -0
- package/dist/esm/annotation/components/crossing.d.ts +3 -0
- package/dist/esm/annotation/components/crossing.js +665 -0
- package/dist/esm/annotation/components/event.d.ts +2 -0
- package/dist/esm/annotation/components/event.js +46 -0
- package/dist/esm/annotation/components/first.d.ts +2 -0
- package/dist/esm/annotation/components/first.js +18 -0
- package/dist/esm/annotation/components/group.d.ts +3 -0
- package/dist/esm/annotation/components/group.js +64 -0
- package/dist/esm/annotation/components/highlight.d.ts +14 -0
- package/dist/esm/annotation/components/highlight.js +838 -0
- package/dist/esm/annotation/components/index.d.ts +34 -0
- package/dist/esm/annotation/components/index.js +34 -0
- package/dist/esm/annotation/components/last.d.ts +2 -0
- package/dist/esm/annotation/components/last.js +18 -0
- package/dist/esm/annotation/components/max-x.d.ts +2 -0
- package/dist/esm/annotation/components/max-x.js +17 -0
- package/dist/esm/annotation/components/max-y.d.ts +2 -0
- package/dist/esm/annotation/components/max-y.js +17 -0
- package/dist/esm/annotation/components/mean.d.ts +2 -0
- package/dist/esm/annotation/components/mean.js +40 -0
- package/dist/esm/annotation/components/median.d.ts +2 -0
- package/dist/esm/annotation/components/median.js +32 -0
- package/dist/esm/annotation/components/min-x.d.ts +2 -0
- package/dist/esm/annotation/components/min-x.js +17 -0
- package/dist/esm/annotation/components/min-y.d.ts +2 -0
- package/dist/esm/annotation/components/min-y.js +17 -0
- package/dist/esm/annotation/components/outlier.d.ts +3 -0
- package/dist/esm/annotation/components/outlier.js +98 -0
- package/dist/esm/annotation/components/path.d.ts +20 -0
- package/dist/esm/annotation/components/path.js +165 -0
- package/dist/esm/annotation/components/peak.d.ts +2 -0
- package/dist/esm/annotation/components/peak.js +20 -0
- package/dist/esm/annotation/components/point.d.ts +26 -0
- package/dist/esm/annotation/components/point.js +277 -0
- package/dist/esm/annotation/components/quadrant.d.ts +3 -0
- package/dist/esm/annotation/components/quadrant.js +83 -0
- package/dist/esm/annotation/components/quantile.d.ts +2 -0
- package/dist/esm/annotation/components/quantile.js +32 -0
- package/dist/esm/annotation/components/range-inside.d.ts +2 -0
- package/dist/esm/annotation/components/range-inside.js +55 -0
- package/dist/esm/annotation/components/range-outside.d.ts +2 -0
- package/dist/esm/annotation/components/range-outside.js +55 -0
- package/dist/esm/annotation/components/range-x.d.ts +2 -0
- package/dist/esm/annotation/components/range-x.js +15 -0
- package/dist/esm/annotation/components/range-y.d.ts +2 -0
- package/dist/esm/annotation/components/range-y.js +15 -0
- package/dist/esm/annotation/components/range.d.ts +15 -0
- package/dist/esm/annotation/components/range.js +92 -0
- package/dist/esm/annotation/components/target.d.ts +2 -0
- package/dist/esm/annotation/components/target.js +44 -0
- package/dist/esm/annotation/components/text.d.ts +15 -0
- package/dist/esm/annotation/components/text.js +78 -0
- package/dist/esm/annotation/components/threshold-highlight.d.ts +3 -0
- package/dist/esm/annotation/components/threshold-highlight.js +297 -0
- package/dist/esm/annotation/components/threshold-x.d.ts +2 -0
- package/dist/esm/annotation/components/threshold-x.js +23 -0
- package/dist/esm/annotation/components/threshold-y.d.ts +2 -0
- package/dist/esm/annotation/components/threshold-y.js +24 -0
- package/dist/esm/annotation/components/top-n.d.ts +2 -0
- package/dist/esm/annotation/components/top-n.js +42 -0
- package/dist/esm/annotation/components/valley.d.ts +2 -0
- package/dist/esm/annotation/components/valley.js +20 -0
- package/dist/esm/annotation/index.d.ts +1 -0
- package/dist/esm/annotation/index.js +1 -0
- package/dist/esm/annotation/label.d.ts +38 -0
- package/dist/esm/annotation/label.js +449 -0
- package/dist/esm/annotation/layout.d.ts +12 -0
- package/dist/esm/annotation/layout.js +182 -0
- package/dist/esm/annotation/merge.d.ts +19 -0
- package/dist/esm/annotation/merge.js +67 -0
- package/dist/esm/annotation/registry.d.ts +190 -0
- package/dist/esm/annotation/registry.js +220 -0
- package/dist/esm/annotation/runtime/g2.d.ts +90 -0
- package/dist/esm/annotation/runtime/g2.js +754 -0
- package/dist/esm/annotation/runtime/g6.d.ts +40 -0
- package/dist/esm/annotation/runtime/g6.js +447 -0
- package/dist/esm/annotation/runtime/index.d.ts +11 -0
- package/dist/esm/annotation/runtime/index.js +26 -0
- package/dist/esm/annotation/runtime/summary.d.ts +17 -0
- package/dist/esm/annotation/runtime/summary.js +21 -0
- package/dist/esm/annotation/runtime/table.d.ts +16 -0
- package/dist/esm/annotation/runtime/table.js +21 -0
- package/dist/esm/annotation/utils.d.ts +40 -0
- package/dist/esm/annotation/utils.js +370 -0
- package/dist/esm/theme/annotation.d.ts +236 -0
- package/dist/esm/theme/annotation.js +186 -0
- package/dist/esm/theme/g2.js +2 -10
- package/dist/esm/theme/g6.js +1 -1
- package/dist/esm/theme/summary.js +1 -1
- package/dist/esm/types/annotation.d.ts +310 -0
- package/dist/esm/types/annotation.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/util/axis.d.ts +28 -0
- package/dist/esm/util/axis.js +222 -0
- package/dist/esm/util/components.d.ts +0 -10
- package/dist/esm/util/components.js +24 -69
- package/dist/esm/util/index.d.ts +7 -4
- package/dist/esm/util/index.js +7 -4
- package/dist/esm/vis/area/index.d.ts +2 -0
- package/dist/esm/vis/area/index.js +32 -9
- package/dist/esm/vis/bar/index.d.ts +2 -0
- package/dist/esm/vis/bar/index.js +37 -6
- package/dist/esm/vis/boxplot/index.js +10 -2
- package/dist/esm/vis/column/index.d.ts +2 -0
- package/dist/esm/vis/column/index.js +33 -12
- package/dist/esm/vis/dual-axes/index.js +10 -10
- package/dist/esm/vis/fishbone-diagram/index.js +1 -1
- package/dist/esm/vis/flow-diagram/index.js +1 -1
- package/dist/esm/vis/funnel/index.js +2 -7
- package/dist/esm/vis/histogram/index.js +4 -3
- package/dist/esm/vis/indented-tree/index.js +1 -1
- package/dist/esm/vis/line/index.d.ts +2 -0
- package/dist/esm/vis/line/index.js +31 -9
- package/dist/esm/vis/liquid/index.js +1 -1
- package/dist/esm/vis/mindmap/index.js +1 -1
- package/dist/esm/vis/network-graph/index.d.ts +2 -0
- package/dist/esm/vis/network-graph/index.js +29 -2
- package/dist/esm/vis/organization-chart/index.js +1 -1
- package/dist/esm/vis/pie/index.d.ts +2 -0
- package/dist/esm/vis/pie/index.js +25 -8
- package/dist/esm/vis/radar/index.js +1 -3
- package/dist/esm/vis/sankey/index.js +15 -1
- package/dist/esm/vis/scatter/index.d.ts +10 -3
- package/dist/esm/vis/scatter/index.js +28 -5
- package/dist/esm/vis/summary/index.d.ts +9 -2
- package/dist/esm/vis/summary/index.js +31 -13
- package/dist/esm/vis/table/index.d.ts +2 -0
- package/dist/esm/vis/table/index.js +50 -33
- package/dist/esm/vis/venn/index.js +1 -1
- package/dist/esm/vis/violin/index.js +10 -2
- package/dist/esm/vis/waterfall/index.js +16 -13
- package/dist/esm/vis/word-cloud/index.js +1 -3
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
3
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
4
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
import { axisPosition, finiteValue, formatNumber, selectRows } from "../utils";
|
|
20
|
+
import { path } from "./path";
|
|
21
|
+
import { point } from "./point";
|
|
22
|
+
|
|
23
|
+
/** Resolve native curve crossings, then reuse paths and directional point presets. */
|
|
24
|
+
export var crossing = {
|
|
25
|
+
g2: function g2(annotations, context) {
|
|
26
|
+
return annotations.flatMap(function (annotation) {
|
|
27
|
+
var _context$sourceMarks$, _context$sourceMarks, _context$sourceMarks2, _annotation$direction, _annotation$style7;
|
|
28
|
+
var mapping = context.mapping,
|
|
29
|
+
defaults = context.defaults;
|
|
30
|
+
var type = (_context$sourceMarks$ = (_context$sourceMarks = context.sourceMarks) === null || _context$sourceMarks === void 0 || (_context$sourceMarks = _context$sourceMarks.find(function (mark) {
|
|
31
|
+
return mark.type === 'line';
|
|
32
|
+
})) === null || _context$sourceMarks === void 0 || (_context$sourceMarks = _context$sourceMarks.style) === null || _context$sourceMarks === void 0 ? void 0 : _context$sourceMarks.shape) !== null && _context$sourceMarks$ !== void 0 ? _context$sourceMarks$ : 'line';
|
|
33
|
+
if ((_context$sourceMarks2 = context.sourceMarks) !== null && _context$sourceMarks2 !== void 0 && _context$sourceMarks2.some(function (mark) {
|
|
34
|
+
var _mark$transform;
|
|
35
|
+
return (_mark$transform = mark.transform) === null || _mark$transform === void 0 ? void 0 : _mark$transform.some(function (t) {
|
|
36
|
+
return (t === null || t === void 0 ? void 0 : t.type) === 'stackY';
|
|
37
|
+
});
|
|
38
|
+
})) throw new Error('Invalid annotation: automatic crossing requires unstacked series.');
|
|
39
|
+
var deferred = false;
|
|
40
|
+
switch (type) {
|
|
41
|
+
case 'line':
|
|
42
|
+
case 'linear':
|
|
43
|
+
break;
|
|
44
|
+
case 'smooth':
|
|
45
|
+
case 'hv':
|
|
46
|
+
case 'vh':
|
|
47
|
+
case 'hvh':
|
|
48
|
+
deferred = true;
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
throw new Error("Invalid annotation: unsupported crossing curve ".concat(String(type), "."));
|
|
52
|
+
}
|
|
53
|
+
var direction = (_annotation$direction = annotation.direction) !== null && _annotation$direction !== void 0 ? _annotation$direction : 'both';
|
|
54
|
+
if (!['up', 'down', 'both'].includes(direction)) throw new Error('Invalid annotation: crossing direction must be up, down or both.');
|
|
55
|
+
var samples = function samples(rows) {
|
|
56
|
+
requireOneSeries(rows, mapping.series);
|
|
57
|
+
if (!rows.length) return [];
|
|
58
|
+
var selected = new Set(rows.map(function (row) {
|
|
59
|
+
return row[mapping.x];
|
|
60
|
+
}));
|
|
61
|
+
var all = mapping.series ? mapping.data.filter(function (row) {
|
|
62
|
+
return row[mapping.series] === rows[0][mapping.series];
|
|
63
|
+
}) : mapping.data;
|
|
64
|
+
// Selection must not turn nonadjacent observations into a new source segment.
|
|
65
|
+
return seriesSamples(all, mapping.x, mapping.y).map(function (sample) {
|
|
66
|
+
return selected.has(sample.x) ? sample : _objectSpread(_objectSpread({}, sample), {}, {
|
|
67
|
+
y: null
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
var compared;
|
|
72
|
+
var selected;
|
|
73
|
+
if (annotation.threshold !== undefined) {
|
|
74
|
+
var threshold = finiteValue(annotation.threshold, 'threshold');
|
|
75
|
+
var rows = selectRows(mapping.data, annotation.data);
|
|
76
|
+
selected = [rows];
|
|
77
|
+
compared = samples(rows).map(function (sample) {
|
|
78
|
+
return _objectSpread(_objectSpread({}, sample), {}, {
|
|
79
|
+
other: threshold,
|
|
80
|
+
difference: sample.y === null ? null : sample.y - threshold
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
var selection = annotation.data;
|
|
85
|
+
if (!selection || Array.isArray(selection) || !('series' in selection) || !Array.isArray(selection.series) || selection.series.length !== 2) throw new Error('Invalid annotation: crossing needs a threshold or two series selectors in data.series.');
|
|
86
|
+
var _selection$series$map = selection.series.map(function (selector) {
|
|
87
|
+
return selectRows(mapping.data, selector);
|
|
88
|
+
}),
|
|
89
|
+
_selection$series$map2 = _slicedToArray(_selection$series$map, 2),
|
|
90
|
+
first = _selection$series$map2[0],
|
|
91
|
+
second = _selection$series$map2[1];
|
|
92
|
+
selected = [first, second];
|
|
93
|
+
var firstRows = new Set(first);
|
|
94
|
+
if (second.some(function (row) {
|
|
95
|
+
return firstRows.has(row);
|
|
96
|
+
})) throw new Error('Invalid annotation: crossing series selectors must not overlap.');
|
|
97
|
+
compared = compareSeries(samples(first), samples(second));
|
|
98
|
+
}
|
|
99
|
+
var visible = function visible() {
|
|
100
|
+
return selected.every(function (rows) {
|
|
101
|
+
return rows.some(function (row) {
|
|
102
|
+
var _context$isVisible, _context$isVisible2;
|
|
103
|
+
return (_context$isVisible = (_context$isVisible2 = context.isVisible) === null || _context$isVisible2 === void 0 ? void 0 : _context$isVisible2.call(context, row)) !== null && _context$isVisible !== void 0 ? _context$isVisible : true;
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
var position = function position(sample) {
|
|
108
|
+
return _defineProperty(_defineProperty({}, mapping.x, sample.x), mapping.y, sample.y);
|
|
109
|
+
};
|
|
110
|
+
var createMarker = function createMarker(sample, positions) {
|
|
111
|
+
var _ref2, _annotation$style$str, _annotation$style, _annotation$style2, _annotation$label, _annotation$pulse, _annotation$style$siz, _annotation$style3, _annotation$style$lin, _annotation$style4, _annotation$style$fil, _annotation$style5, _annotation$style$str2, _annotation$style6;
|
|
112
|
+
var color = (_ref2 = (_annotation$style$str = (_annotation$style = annotation.style) === null || _annotation$style === void 0 ? void 0 : _annotation$style.stroke) !== null && _annotation$style$str !== void 0 ? _annotation$style$str : (_annotation$style2 = annotation.style) === null || _annotation$style2 === void 0 ? void 0 : _annotation$style2.fill) !== null && _ref2 !== void 0 ? _ref2 : defaults.directions[sample.direction];
|
|
113
|
+
return point.create({
|
|
114
|
+
data: position(sample),
|
|
115
|
+
label: (_annotation$label = annotation.label) !== null && _annotation$label !== void 0 ? _annotation$label : "".concat(sample.direction === 'up' ? 'Crosses above' : 'Crosses below').concat(annotation.threshold === undefined ? '' : " ".concat(formatNumber(annotation.threshold))),
|
|
116
|
+
pulse: (_annotation$pulse = annotation.pulse) !== null && _annotation$pulse !== void 0 ? _annotation$pulse : false,
|
|
117
|
+
style: _objectSpread(_objectSpread({}, annotation.style), {}, {
|
|
118
|
+
size: (_annotation$style$siz = (_annotation$style3 = annotation.style) === null || _annotation$style3 === void 0 ? void 0 : _annotation$style3.size) !== null && _annotation$style$siz !== void 0 ? _annotation$style$siz : Math.max(defaults.size, 7),
|
|
119
|
+
lineWidth: (_annotation$style$lin = (_annotation$style4 = annotation.style) === null || _annotation$style4 === void 0 ? void 0 : _annotation$style4.lineWidth) !== null && _annotation$style$lin !== void 0 ? _annotation$style$lin : 2,
|
|
120
|
+
fill: (_annotation$style$fil = (_annotation$style5 = annotation.style) === null || _annotation$style5 === void 0 ? void 0 : _annotation$style5.fill) !== null && _annotation$style$fil !== void 0 ? _annotation$style$fil : color,
|
|
121
|
+
stroke: color
|
|
122
|
+
})
|
|
123
|
+
}, {
|
|
124
|
+
shape: sample.direction === 'up' ? 'triangle' : 'triangleDown',
|
|
125
|
+
outline: (_annotation$style$str2 = (_annotation$style6 = annotation.style) === null || _annotation$style6 === void 0 ? void 0 : _annotation$style6.stroke) !== null && _annotation$style$str2 !== void 0 ? _annotation$style$str2 : defaults.pointStroke,
|
|
126
|
+
zIndex: 2,
|
|
127
|
+
visible: visible,
|
|
128
|
+
positions: positions
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
var references = annotation.threshold === undefined ? [] : path.create({
|
|
132
|
+
data: axisPosition(mapping.y, annotation.threshold),
|
|
133
|
+
label: annotation.label === '' ? '' : "Threshold: ".concat(formatNumber(annotation.threshold)),
|
|
134
|
+
style: {
|
|
135
|
+
lineDash: [4, 4],
|
|
136
|
+
stroke: (_annotation$style7 = annotation.style) === null || _annotation$style7 === void 0 ? void 0 : _annotation$style7.stroke
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
var createBand = function createBand(band, positions) {
|
|
140
|
+
var _ref3, _annotation$style$fil2, _annotation$style8, _annotation$style9;
|
|
141
|
+
return path.create({
|
|
142
|
+
data: [].concat(_toConsumableArray(band.upper), _toConsumableArray(band.lower.slice().reverse()), [band.upper[0]]).map(position),
|
|
143
|
+
label: ''
|
|
144
|
+
}, {
|
|
145
|
+
fill: (_ref3 = (_annotation$style$fil2 = (_annotation$style8 = annotation.style) === null || _annotation$style8 === void 0 ? void 0 : _annotation$style8.fill) !== null && _annotation$style$fil2 !== void 0 ? _annotation$style$fil2 : (_annotation$style9 = annotation.style) === null || _annotation$style9 === void 0 ? void 0 : _annotation$style9.stroke) !== null && _ref3 !== void 0 ? _ref3 : defaults.directions[band.direction],
|
|
146
|
+
fillOpacity: 0.07,
|
|
147
|
+
visible: visible,
|
|
148
|
+
positions: positions
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
// Categorical crossings remain observed events; no synthetic category is introduced.
|
|
152
|
+
if (!deferred || compared.some(function (_ref4) {
|
|
153
|
+
var x = _ref4.x;
|
|
154
|
+
return typeof x === 'string';
|
|
155
|
+
})) {
|
|
156
|
+
var _marks = intersections(compared).filter(function (sample) {
|
|
157
|
+
return direction === 'both' || direction === sample.direction;
|
|
158
|
+
}).flatMap(function (sample) {
|
|
159
|
+
return createMarker(sample);
|
|
160
|
+
});
|
|
161
|
+
var _bands = (context.chartType === 'area' ? [] : relationshipBands(compared)).filter(function (_ref5) {
|
|
162
|
+
var side = _ref5.direction;
|
|
163
|
+
return direction === 'both' || direction === side;
|
|
164
|
+
}).flatMap(function (band) {
|
|
165
|
+
return createBand(band);
|
|
166
|
+
});
|
|
167
|
+
return [].concat(_toConsumableArray(_bands), _toConsumableArray(references), _toConsumableArray(_marks));
|
|
168
|
+
}
|
|
169
|
+
var series = selected.map(function (rows) {
|
|
170
|
+
var _rows$;
|
|
171
|
+
var group = mapping.series && ((_rows$ = rows[0]) === null || _rows$ === void 0 ? void 0 : _rows$[mapping.series]);
|
|
172
|
+
var all = mapping.series ? mapping.data.filter(function (row) {
|
|
173
|
+
return row[mapping.series] === group;
|
|
174
|
+
}) : mapping.data;
|
|
175
|
+
var full = seriesSamples(all, mapping.x, mapping.y);
|
|
176
|
+
var chosen = new Set(rows.map(function (row) {
|
|
177
|
+
return row[mapping.x];
|
|
178
|
+
}));
|
|
179
|
+
var runs = [];
|
|
180
|
+
var run;
|
|
181
|
+
for (var _i = 0, _full = full; _i < _full.length; _i++) {
|
|
182
|
+
var sample = _full[_i];
|
|
183
|
+
if (!chosen.has(sample.x)) run = undefined;else {
|
|
184
|
+
if (!run) runs.push(run = []);
|
|
185
|
+
run.push(sample);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Step direction depends on source order; normalize only after native path generation.
|
|
189
|
+
if (full.length && Number(all[0][mapping.x]) > Number(all.at(-1)[mapping.x])) full.reverse();
|
|
190
|
+
return {
|
|
191
|
+
samples: full,
|
|
192
|
+
runs: runs,
|
|
193
|
+
chosen: chosen
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
var resolve = function resolve(geometry, coordinate) {
|
|
197
|
+
// G2's D3 paths round to 0.001px; keep boundary jumps and exact threshold touches stable.
|
|
198
|
+
var tolerance = 0.002 / Math.max(1, Math.min.apply(Math, _toConsumableArray(coordinate.getSize())));
|
|
199
|
+
var paths = series.map(function (_ref6) {
|
|
200
|
+
var samples = _ref6.samples,
|
|
201
|
+
runs = _ref6.runs,
|
|
202
|
+
chosen = _ref6.chosen;
|
|
203
|
+
// Step curves depend only on adjacent observations; masking preserves their exact edges.
|
|
204
|
+
var source = type === 'smooth' ? samples : samples.map(function (sample) {
|
|
205
|
+
return chosen.has(sample.x) ? sample : _objectSpread(_objectSpread({}, sample), {}, {
|
|
206
|
+
y: null
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
var full = sampleCurve(type, source, geometry, coordinate);
|
|
210
|
+
if (type !== 'smooth') return full;
|
|
211
|
+
return runs.filter(function (run) {
|
|
212
|
+
return run.length > 1;
|
|
213
|
+
}).flatMap(function (run, i) {
|
|
214
|
+
var from = geometry.axisValue('x', run[0].x);
|
|
215
|
+
var to = geometry.axisValue('x', run.at(-1).x);
|
|
216
|
+
var clipped = clipSamples(full, Math.min(from, to), Math.max(from, to), tolerance);
|
|
217
|
+
return i ? [{
|
|
218
|
+
x: from,
|
|
219
|
+
y: null
|
|
220
|
+
}].concat(clipped) : clipped;
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
if (annotation.threshold !== undefined) {
|
|
224
|
+
var _threshold = -geometry.axisValue('y', annotation.threshold);
|
|
225
|
+
return paths[0].map(function (sample) {
|
|
226
|
+
return _objectSpread(_objectSpread({}, sample), {}, {
|
|
227
|
+
other: _threshold,
|
|
228
|
+
difference: sample.y === null ? null : Math.abs(sample.y - _threshold) <= tolerance ? 0 : sample.y - _threshold
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return comparePaths(paths[0], paths[1], tolerance);
|
|
233
|
+
};
|
|
234
|
+
var sides = direction === 'both' ? ['up', 'down'] : [direction];
|
|
235
|
+
var seed = {
|
|
236
|
+
x: 0,
|
|
237
|
+
y: 0
|
|
238
|
+
};
|
|
239
|
+
var marks = sides.flatMap(function (side) {
|
|
240
|
+
return createMarker(_objectSpread(_objectSpread({}, seed), {}, {
|
|
241
|
+
direction: side
|
|
242
|
+
}), function (geometry, coordinate) {
|
|
243
|
+
return intersections(resolve(geometry, coordinate)).filter(function (sample) {
|
|
244
|
+
return sample.direction === side;
|
|
245
|
+
}).map(function (sample) {
|
|
246
|
+
return [Number(sample.x), -sample.y];
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
var bands = context.chartType === 'area' ? [] : sides.flatMap(function (side) {
|
|
251
|
+
return createBand({
|
|
252
|
+
upper: [seed],
|
|
253
|
+
lower: [seed],
|
|
254
|
+
direction: side
|
|
255
|
+
}, function (geometry, coordinate) {
|
|
256
|
+
return relationshipBands(resolve(geometry, coordinate)).filter(function (band) {
|
|
257
|
+
return band.direction === side;
|
|
258
|
+
}).map(function (band) {
|
|
259
|
+
return [].concat(_toConsumableArray(band.upper), _toConsumableArray(band.lower.slice().reverse()), [band.upper[0]]).map(function (sample) {
|
|
260
|
+
return [Number(sample.x), -sample.y];
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
return [].concat(_toConsumableArray(bands), _toConsumableArray(references), _toConsumableArray(marks));
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
/** G2 owns the curve construction; crossing only reads and flattens its detached path. */
|
|
270
|
+
function sampleCurve(type, samples, context, coordinate) {
|
|
271
|
+
var _projected$, _projected$at;
|
|
272
|
+
var library = context.library;
|
|
273
|
+
var line = library['mark.line'];
|
|
274
|
+
var shape = line.props.shape[type];
|
|
275
|
+
var element = shape({}, {
|
|
276
|
+
document: context.getScene(),
|
|
277
|
+
coordinate: coordinate
|
|
278
|
+
})(samples.map(function (_ref7) {
|
|
279
|
+
var x = _ref7.x,
|
|
280
|
+
y = _ref7.y;
|
|
281
|
+
return y === null ? [NaN, NaN] : coordinate.map([context.axisValue('x', x), context.axisValue('y', y)]);
|
|
282
|
+
}), {}, {
|
|
283
|
+
color: 'none',
|
|
284
|
+
lineWidth: 0
|
|
285
|
+
});
|
|
286
|
+
var commands;
|
|
287
|
+
try {
|
|
288
|
+
// Detached shapes have not run G's style parser yet; D3 emits only M/L/C/Z commands here.
|
|
289
|
+
var _path = element.getAttribute('d');
|
|
290
|
+
commands = typeof _path === 'string' ? Array.from(_path.matchAll(/([MLCZ])([^MLCZ]*)/g), function (_ref8) {
|
|
291
|
+
var _values$match;
|
|
292
|
+
var _ref9 = _slicedToArray(_ref8, 3),
|
|
293
|
+
command = _ref9[1],
|
|
294
|
+
values = _ref9[2];
|
|
295
|
+
return [command].concat(_toConsumableArray(((_values$match = values.match(/[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/g)) !== null && _values$match !== void 0 ? _values$match : []).map(Number)));
|
|
296
|
+
}) : [];
|
|
297
|
+
} finally {
|
|
298
|
+
element.destroy();
|
|
299
|
+
}
|
|
300
|
+
var paths = [];
|
|
301
|
+
var _iterator = _createForOfIteratorHelper(commands),
|
|
302
|
+
_step;
|
|
303
|
+
try {
|
|
304
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
305
|
+
var _step$value = _toArray(_step.value),
|
|
306
|
+
command = _step$value[0],
|
|
307
|
+
values = _step$value.slice(1);
|
|
308
|
+
var end = [values.at(-2), values.at(-1)];
|
|
309
|
+
switch (command) {
|
|
310
|
+
case 'M':
|
|
311
|
+
paths.push([end]);
|
|
312
|
+
break;
|
|
313
|
+
case 'L':
|
|
314
|
+
paths.at(-1).push(end);
|
|
315
|
+
break;
|
|
316
|
+
case 'C':
|
|
317
|
+
{
|
|
318
|
+
var _path2 = paths.at(-1);
|
|
319
|
+
flattenCubic(_path2.at(-1), [values[0], values[1]], [values[2], values[3]], end, _path2);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
case 'Z':
|
|
323
|
+
break;
|
|
324
|
+
// G2 closes single-observation lines without introducing another observation.
|
|
325
|
+
default:
|
|
326
|
+
throw new Error("Invalid annotation: unsupported crossing path command ".concat(command, "."));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} catch (err) {
|
|
330
|
+
_iterator.e(err);
|
|
331
|
+
} finally {
|
|
332
|
+
_iterator.f();
|
|
333
|
+
}
|
|
334
|
+
var projected = paths.map(function (points) {
|
|
335
|
+
return points.map(function (point) {
|
|
336
|
+
var _coordinate$invert = coordinate.invert(point),
|
|
337
|
+
_coordinate$invert2 = _slicedToArray(_coordinate$invert, 2),
|
|
338
|
+
x = _coordinate$invert2[0],
|
|
339
|
+
y = _coordinate$invert2[1];
|
|
340
|
+
return {
|
|
341
|
+
x: x,
|
|
342
|
+
y: -y
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
if (Number((_projected$ = projected[0]) === null || _projected$ === void 0 ? void 0 : _projected$[0].x) > Number((_projected$at = projected.at(-1)) === null || _projected$at === void 0 || (_projected$at = _projected$at.at(-1)) === null || _projected$at === void 0 ? void 0 : _projected$at.x)) {
|
|
347
|
+
projected.reverse();
|
|
348
|
+
projected.forEach(function (path) {
|
|
349
|
+
return path.reverse();
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
var result = [];
|
|
353
|
+
var _iterator2 = _createForOfIteratorHelper(projected),
|
|
354
|
+
_step2;
|
|
355
|
+
try {
|
|
356
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
357
|
+
var _path3 = _step2.value;
|
|
358
|
+
if (result.length) result.push({
|
|
359
|
+
x: (Number(result.at(-1).x) + Number(_path3[0].x)) / 2,
|
|
360
|
+
y: null
|
|
361
|
+
});
|
|
362
|
+
result.push.apply(result, _toConsumableArray(_path3));
|
|
363
|
+
}
|
|
364
|
+
} catch (err) {
|
|
365
|
+
_iterator2.e(err);
|
|
366
|
+
} finally {
|
|
367
|
+
_iterator2.f();
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Subdivide in screen pixels so marker and fill errors remain below a visible pixel. */
|
|
373
|
+
function flattenCubic(a, b, c, d, points) {
|
|
374
|
+
var depth = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
375
|
+
var length = Math.hypot(d[0] - a[0], d[1] - a[1]);
|
|
376
|
+
var distance = function distance(p) {
|
|
377
|
+
return length ? Math.abs((d[0] - a[0]) * (a[1] - p[1]) - (a[0] - p[0]) * (d[1] - a[1])) / length : Math.hypot(p[0] - a[0], p[1] - a[1]);
|
|
378
|
+
};
|
|
379
|
+
if (depth >= 16 || Math.max(distance(b), distance(c)) <= 0.1) {
|
|
380
|
+
points.push(d);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
var middle = function middle(a, b) {
|
|
384
|
+
return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
|
385
|
+
};
|
|
386
|
+
var ab = middle(a, b),
|
|
387
|
+
bc = middle(b, c),
|
|
388
|
+
cd = middle(c, d);
|
|
389
|
+
var abc = middle(ab, bc),
|
|
390
|
+
bcd = middle(bc, cd),
|
|
391
|
+
center = middle(abc, bcd);
|
|
392
|
+
flattenCubic(a, ab, abc, center, points, depth + 1);
|
|
393
|
+
flattenCubic(center, bcd, cd, d, points, depth + 1);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Preserve both limits at a step's vertical edge; ordinary curves have identical limits. */
|
|
397
|
+
function sampleAt(samples, x, side) {
|
|
398
|
+
var _samples$from;
|
|
399
|
+
var from = 0,
|
|
400
|
+
to = samples.length;
|
|
401
|
+
while (from < to) {
|
|
402
|
+
var mid = from + to >>> 1;
|
|
403
|
+
if (Number(samples[mid].x) < x || side === 'after' && samples[mid].x === x) from = mid + 1;else to = mid;
|
|
404
|
+
}
|
|
405
|
+
if (side === 'before' && ((_samples$from = samples[from]) === null || _samples$from === void 0 ? void 0 : _samples$from.x) === x) return samples[from].y;
|
|
406
|
+
var a = samples[from - 1],
|
|
407
|
+
b = samples[from];
|
|
408
|
+
if ((a === null || a === void 0 ? void 0 : a.x) === x) return a.y;
|
|
409
|
+
if (!a || !b || a.y === null || b.y === null) return null;
|
|
410
|
+
var t = interpolationFraction(Number(a.x), Number(b.x), x);
|
|
411
|
+
return a.y * (1 - t) + b.y * t;
|
|
412
|
+
}
|
|
413
|
+
function clipSamples(samples, from, to, tolerance) {
|
|
414
|
+
if (!samples.length || from > to) return [];
|
|
415
|
+
var result = samples.filter(function (_ref10) {
|
|
416
|
+
var x = _ref10.x;
|
|
417
|
+
return Number(x) >= from - tolerance && Number(x) <= to + tolerance;
|
|
418
|
+
});
|
|
419
|
+
if (!result.length || Math.abs(Number(result[0].x) - from) > tolerance) result.unshift({
|
|
420
|
+
x: from,
|
|
421
|
+
y: sampleAt(samples, from, 'after')
|
|
422
|
+
});
|
|
423
|
+
if (Math.abs(Number(result.at(-1).x) - to) > tolerance) result.push({
|
|
424
|
+
x: to,
|
|
425
|
+
y: sampleAt(samples, to, 'before')
|
|
426
|
+
});
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Compare continuous segments and single-series jumps without inventing a point on overlaps. */
|
|
431
|
+
function comparePaths(first, second, tolerance) {
|
|
432
|
+
if (!first.length || !second.length) return [];
|
|
433
|
+
var from = Math.max(Number(first[0].x), Number(second[0].x));
|
|
434
|
+
var to = Math.min(Number(first.at(-1).x), Number(second.at(-1).x));
|
|
435
|
+
var xs = _toConsumableArray(new Set([].concat(_toConsumableArray(first), _toConsumableArray(second)).map(function (_ref11) {
|
|
436
|
+
var x = _ref11.x;
|
|
437
|
+
return Number(x);
|
|
438
|
+
}))).filter(function (x) {
|
|
439
|
+
return x >= from && x <= to;
|
|
440
|
+
}).sort(function (a, b) {
|
|
441
|
+
return a - b;
|
|
442
|
+
});
|
|
443
|
+
var result = [];
|
|
444
|
+
var _iterator3 = _createForOfIteratorHelper(xs),
|
|
445
|
+
_step3;
|
|
446
|
+
try {
|
|
447
|
+
var _loop = function _loop() {
|
|
448
|
+
var x = _step3.value;
|
|
449
|
+
var a0 = sampleAt(first, x, 'before'),
|
|
450
|
+
a1 = sampleAt(first, x, 'after');
|
|
451
|
+
var b0 = sampleAt(second, x, 'before'),
|
|
452
|
+
b1 = sampleAt(second, x, 'after');
|
|
453
|
+
var compared = function compared(a, b) {
|
|
454
|
+
return {
|
|
455
|
+
x: x,
|
|
456
|
+
y: a,
|
|
457
|
+
other: a !== null && b !== null && Math.abs(a - b) <= tolerance ? a : b,
|
|
458
|
+
difference: a === null || b === null ? null : Math.abs(a - b) <= tolerance ? 0 : a - b
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
result.push(compared(a0, b0));
|
|
462
|
+
// Two simultaneous jumps can overlap along an entire vertical segment, with no unique crossing.
|
|
463
|
+
if (a0 !== a1 && b0 !== b1) result.push({
|
|
464
|
+
x: x,
|
|
465
|
+
y: null,
|
|
466
|
+
other: null,
|
|
467
|
+
difference: null
|
|
468
|
+
});
|
|
469
|
+
if (a0 !== a1 || b0 !== b1) result.push(compared(a1, b1));
|
|
470
|
+
};
|
|
471
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
472
|
+
_loop();
|
|
473
|
+
}
|
|
474
|
+
} catch (err) {
|
|
475
|
+
_iterator3.e(err);
|
|
476
|
+
} finally {
|
|
477
|
+
_iterator3.f();
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
function seriesSamples(rows, x, y) {
|
|
482
|
+
var _samples$;
|
|
483
|
+
var samples = rows.map(function (row) {
|
|
484
|
+
var value = row[x];
|
|
485
|
+
axisPosition(x, value);
|
|
486
|
+
var raw = row[y];
|
|
487
|
+
if (raw === null || raw === undefined || typeof raw === 'number' && !Number.isFinite(raw)) return {
|
|
488
|
+
x: value,
|
|
489
|
+
y: null
|
|
490
|
+
};
|
|
491
|
+
return {
|
|
492
|
+
x: value,
|
|
493
|
+
y: finiteValue(raw, y)
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
if (new Set(samples.map(function (_ref12) {
|
|
497
|
+
var x = _ref12.x;
|
|
498
|
+
return x;
|
|
499
|
+
})).size !== samples.length) throw new Error('Invalid annotation: crossing requires unique x values per series.');
|
|
500
|
+
if (samples.some(function (sample) {
|
|
501
|
+
return _typeof(sample.x) !== _typeof(samples[0].x);
|
|
502
|
+
})) throw new Error('Invalid annotation: crossing x values must have a consistent type.');
|
|
503
|
+
if (typeof ((_samples$ = samples[0]) === null || _samples$ === void 0 ? void 0 : _samples$.x) === 'number' && samples.length > 1) {
|
|
504
|
+
var direction = Number(samples[1].x) - Number(samples[0].x);
|
|
505
|
+
if (samples.slice(1).some(function (sample, i) {
|
|
506
|
+
return (Number(sample.x) - Number(samples[i].x)) * direction <= 0;
|
|
507
|
+
})) throw new Error('Invalid annotation: crossing x values must be monotonic.');
|
|
508
|
+
if (direction < 0) samples.reverse();
|
|
509
|
+
}
|
|
510
|
+
return samples;
|
|
511
|
+
}
|
|
512
|
+
function interpolate(samples, x) {
|
|
513
|
+
var left = 0;
|
|
514
|
+
var right = samples.length - 1;
|
|
515
|
+
while (left < right) {
|
|
516
|
+
var middle = Math.ceil((left + right) / 2);
|
|
517
|
+
if (Number(samples[middle].x) <= x) left = middle;else right = middle - 1;
|
|
518
|
+
}
|
|
519
|
+
var a = samples[left];
|
|
520
|
+
if (a.x === x) return a.y;
|
|
521
|
+
var b = samples[left + 1];
|
|
522
|
+
if (!b || a.y === null || b.y === null) return null;
|
|
523
|
+
var t = interpolationFraction(Number(a.x), Number(b.x), x);
|
|
524
|
+
return a.y * (1 - t) + b.y * t;
|
|
525
|
+
}
|
|
526
|
+
function compareSeries(first, second) {
|
|
527
|
+
if (!first.length || !second.length) return [];
|
|
528
|
+
if (typeof first[0].x === 'number' && typeof second[0].x === 'number') {
|
|
529
|
+
var min = Math.max(Number(first[0].x), Number(second[0].x));
|
|
530
|
+
var max = Math.min(Number(first[first.length - 1].x), Number(second[second.length - 1].x));
|
|
531
|
+
return _toConsumableArray(new Set([].concat(_toConsumableArray(first), _toConsumableArray(second)).map(function (_ref13) {
|
|
532
|
+
var x = _ref13.x;
|
|
533
|
+
return Number(x);
|
|
534
|
+
}))).filter(function (x) {
|
|
535
|
+
return x >= min && x <= max;
|
|
536
|
+
}).sort(function (a, b) {
|
|
537
|
+
return a - b;
|
|
538
|
+
}).map(function (x) {
|
|
539
|
+
var y = interpolate(first, x);
|
|
540
|
+
var other = interpolate(second, x);
|
|
541
|
+
return {
|
|
542
|
+
x: x,
|
|
543
|
+
y: y,
|
|
544
|
+
other: other,
|
|
545
|
+
difference: y === null || other === null ? null : y - other
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (first.length !== second.length || first.some(function (sample, i) {
|
|
550
|
+
return sample.x !== second[i].x;
|
|
551
|
+
})) throw new Error('Invalid annotation: categorical crossing requires identical categories in identical order.');
|
|
552
|
+
return first.map(function (sample, i) {
|
|
553
|
+
return _objectSpread(_objectSpread({}, sample), {}, {
|
|
554
|
+
other: second[i].y,
|
|
555
|
+
difference: sample.y === null || second[i].y === null ? null : sample.y - second[i].y
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** Skip touches; an equality plateau that changes side is marked at its first coordinate. */
|
|
561
|
+
function intersections(samples) {
|
|
562
|
+
var points = [];
|
|
563
|
+
var previous = -1;
|
|
564
|
+
for (var i = 0; i < samples.length; i++) {
|
|
565
|
+
var current = samples[i];
|
|
566
|
+
if (current.difference === null) {
|
|
567
|
+
previous = -1;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
if (current.difference === 0) continue;
|
|
571
|
+
var start = samples[previous];
|
|
572
|
+
if (start && Math.sign(start.difference) !== Math.sign(current.difference)) {
|
|
573
|
+
var direction = current.difference > 0 ? 'up' : 'down';
|
|
574
|
+
if (i > previous + 1) points.push(_objectSpread(_objectSpread({}, samples[previous + 1]), {}, {
|
|
575
|
+
direction: direction
|
|
576
|
+
}));else if (typeof start.x === 'number' && typeof current.x === 'number') {
|
|
577
|
+
var t = crossingFraction(start, current);
|
|
578
|
+
points.push({
|
|
579
|
+
x: start.x * (1 - t) + current.x * t,
|
|
580
|
+
y: start.y * (1 - t) + current.y * t,
|
|
581
|
+
direction: direction
|
|
582
|
+
});
|
|
583
|
+
} else points.push(_objectSpread(_objectSpread({}, current), {}, {
|
|
584
|
+
direction: direction
|
|
585
|
+
}));
|
|
586
|
+
}
|
|
587
|
+
previous = i;
|
|
588
|
+
}
|
|
589
|
+
return points;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** Numeric relationships split at exact intersections; missing values never form a filled bridge. */
|
|
593
|
+
function relationshipBands(samples) {
|
|
594
|
+
var bands = [];
|
|
595
|
+
if (!samples.every(function (_ref14) {
|
|
596
|
+
var x = _ref14.x;
|
|
597
|
+
return typeof x === 'number';
|
|
598
|
+
})) return bands;
|
|
599
|
+
var active;
|
|
600
|
+
var append = function append(a, b) {
|
|
601
|
+
var difference = a.difference || b.difference;
|
|
602
|
+
if (!difference) {
|
|
603
|
+
active = undefined;
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
var direction = difference > 0 ? 'up' : 'down';
|
|
607
|
+
if (!active || active.direction !== direction) {
|
|
608
|
+
active = {
|
|
609
|
+
upper: [a],
|
|
610
|
+
lower: [{
|
|
611
|
+
x: a.x,
|
|
612
|
+
y: a.other
|
|
613
|
+
}],
|
|
614
|
+
direction: direction
|
|
615
|
+
};
|
|
616
|
+
bands.push(active);
|
|
617
|
+
}
|
|
618
|
+
active.upper.push(b);
|
|
619
|
+
active.lower.push({
|
|
620
|
+
x: b.x,
|
|
621
|
+
y: b.other
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
for (var i = 1; i < samples.length; i++) {
|
|
625
|
+
var a = samples[i - 1],
|
|
626
|
+
b = samples[i];
|
|
627
|
+
if (a.difference === null || b.difference === null) {
|
|
628
|
+
active = undefined;
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
if (Math.sign(a.difference) * Math.sign(b.difference) < 0) {
|
|
632
|
+
var t = crossingFraction(a, b);
|
|
633
|
+
var intersection = {
|
|
634
|
+
x: Number(a.x) * (1 - t) + Number(b.x) * t,
|
|
635
|
+
y: a.y * (1 - t) + b.y * t,
|
|
636
|
+
other: a.y * (1 - t) + b.y * t,
|
|
637
|
+
difference: 0
|
|
638
|
+
};
|
|
639
|
+
append(a, intersection);
|
|
640
|
+
append(intersection, b);
|
|
641
|
+
} else append(a, b);
|
|
642
|
+
}
|
|
643
|
+
return bands;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/** Normalize before subtracting opposite extremes, and before summing the two distances. */
|
|
647
|
+
function crossingFraction(a, b) {
|
|
648
|
+
var scale = Math.max(Math.abs(a.y), Math.abs(a.other), Math.abs(b.y), Math.abs(b.other));
|
|
649
|
+
var difference = function difference(sample) {
|
|
650
|
+
return Number.isFinite(sample.difference) ? sample.difference / scale : sample.y / scale - sample.other / scale;
|
|
651
|
+
};
|
|
652
|
+
var left = Math.abs(difference(a));
|
|
653
|
+
var right = Math.abs(difference(b));
|
|
654
|
+
return left / (left + right);
|
|
655
|
+
}
|
|
656
|
+
function interpolationFraction(from, to, value) {
|
|
657
|
+
if (Number.isFinite(to - from)) return (value - from) / (to - from);
|
|
658
|
+
var scale = Math.max(Math.abs(from), Math.abs(to));
|
|
659
|
+
return (value / scale - from / scale) / (to / scale - from / scale);
|
|
660
|
+
}
|
|
661
|
+
function requireOneSeries(rows, series) {
|
|
662
|
+
if (series && new Set(rows.map(function (row) {
|
|
663
|
+
return row[series];
|
|
664
|
+
})).size > 1) throw new Error('Invalid annotation: select a single series with data.');
|
|
665
|
+
}
|