@antv/gpt-vis 1.3.1 → 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/cjs/vis-wrapper/index.js +2 -1
- 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/esm/vis-wrapper/index.js +2 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,222 @@
|
|
|
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
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."); }
|
|
4
|
+
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); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
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); }
|
|
13
|
+
import { measureTextWidth } from '@antv/component';
|
|
14
|
+
import { CHART_FONT_FAMILY } from "./tokens";
|
|
15
|
+
var DEFAULT_MARGIN_RIGHT = 16;
|
|
16
|
+
var MAX_DIAGONAL_MARGIN_RIGHT = 64;
|
|
17
|
+
// Conservative space budget before G2 resolves the actual plot (not a component default).
|
|
18
|
+
var AXIS_HORIZONTAL_PADDING = 96;
|
|
19
|
+
/** GPT-Vis policy only; component handles text truncation and overlap hiding. */
|
|
20
|
+
export function createCartesianAxis(options) {
|
|
21
|
+
var _category$labels, _category$layout;
|
|
22
|
+
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
|
+
var axisXTitle = options.axisXTitle,
|
|
24
|
+
axisYTitle = options.axisYTitle,
|
|
25
|
+
transposed = options.transposed,
|
|
26
|
+
_options$xValues = options.xValues,
|
|
27
|
+
xValues = _options$xValues === void 0 ? [] : _options$xValues,
|
|
28
|
+
xType = options.xType;
|
|
29
|
+
var numericX = xType === undefined ? xValues.length > 0 && xValues.every(function (value) {
|
|
30
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
31
|
+
}) : xType === 'number';
|
|
32
|
+
var numericLabels = {
|
|
33
|
+
labelAutoRotate: false,
|
|
34
|
+
transform: [{
|
|
35
|
+
type: 'hide'
|
|
36
|
+
}]
|
|
37
|
+
};
|
|
38
|
+
var horizontalNumericLabels = {
|
|
39
|
+
labelTextAlign: function labelTextAlign(_datum, index, ticks) {
|
|
40
|
+
return !ticks || ticks.length === 1 ? 'center' : index === 0 ? 'left' : index === ticks.length - 1 ? 'right' : 'center';
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var category = numericX ? undefined : createCategoryAxis(options, theme);
|
|
44
|
+
var axis = {
|
|
45
|
+
x: _objectSpread({
|
|
46
|
+
title: axisXTitle || false
|
|
47
|
+
}, (_category$labels = category === null || category === void 0 ? void 0 : category.labels) !== null && _category$labels !== void 0 ? _category$labels : _objectSpread(_objectSpread({}, numericLabels), horizontalNumericLabels)),
|
|
48
|
+
y: _objectSpread(_objectSpread({
|
|
49
|
+
title: axisYTitle || false
|
|
50
|
+
}, numericLabels), transposed ? horizontalNumericLabels : {})
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
axis: axis,
|
|
54
|
+
layout: (_category$layout = category === null || category === void 0 ? void 0 : category.layout) !== null && _category$layout !== void 0 ? _category$layout : function () {
|
|
55
|
+
return {
|
|
56
|
+
marginRight: undefined
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function getCartesianAxis(options) {
|
|
62
|
+
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
63
|
+
return createCartesianAxis(options, theme).axis;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Update right margin before G2's existing autoFit render. */
|
|
67
|
+
export function bindCartesianAxisLayout(chart, axis) {
|
|
68
|
+
chart.on('beforechangesize', function () {
|
|
69
|
+
return chart.attr('marginRight', axis.layout().marginRight);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Supply one policy to both G2's size measurement and component's final rendering. */
|
|
74
|
+
function createCategoryAxis(options, theme) {
|
|
75
|
+
var _font$labelFontSize, _font$labelFontFamily;
|
|
76
|
+
var _options$xValues2 = options.xValues,
|
|
77
|
+
xValues = _options$xValues2 === void 0 ? [] : _options$xValues2,
|
|
78
|
+
transposed = options.transposed,
|
|
79
|
+
preferHorizontal = options.preferHorizontal;
|
|
80
|
+
var labels = _toConsumableArray(new Set(xValues.map(function (value) {
|
|
81
|
+
return String(value !== null && value !== void 0 ? value : '');
|
|
82
|
+
})));
|
|
83
|
+
var font = _objectSpread(_objectSpread({
|
|
84
|
+
fontSize: 12,
|
|
85
|
+
fontFamily: CHART_FONT_FAMILY
|
|
86
|
+
}, theme.axis), theme.axisX);
|
|
87
|
+
var labelFont = {
|
|
88
|
+
fontSize: (_font$labelFontSize = font.labelFontSize) !== null && _font$labelFontSize !== void 0 ? _font$labelFontSize : font.fontSize,
|
|
89
|
+
fontFamily: (_font$labelFontFamily = font.labelFontFamily) !== null && _font$labelFontFamily !== void 0 ? _font$labelFontFamily : font.fontFamily,
|
|
90
|
+
fontWeight: font.labelFontWeight,
|
|
91
|
+
fontStyle: font.labelFontStyle
|
|
92
|
+
};
|
|
93
|
+
// Recompute during G2 measurement/render so autoFit uses the current container.
|
|
94
|
+
var getSize = function getSize() {
|
|
95
|
+
var element = typeof options.container === 'string' ? typeof document === 'undefined' ? null : document.getElementById(options.container) || document.querySelector(options.container) : options.container;
|
|
96
|
+
var width = (element === null || element === void 0 ? void 0 : element.clientWidth) || options.chartWidth || 640;
|
|
97
|
+
var height = (element === null || element === void 0 ? void 0 : element.clientHeight) || options.chartHeight || 400;
|
|
98
|
+
return {
|
|
99
|
+
width: width,
|
|
100
|
+
height: height
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
// Text and typography are fixed for this render; only container size changes.
|
|
104
|
+
var fullWidth;
|
|
105
|
+
var categoryLayout = function categoryLayout() {
|
|
106
|
+
var _fullWidth;
|
|
107
|
+
// measureTextWidth already caches individual text/font measurements in component.
|
|
108
|
+
(_fullWidth = fullWidth) !== null && _fullWidth !== void 0 ? _fullWidth : fullWidth = labels.reduce(function (max, label) {
|
|
109
|
+
return Math.max(max, measureTextWidth(label, labelFont));
|
|
110
|
+
}, 0);
|
|
111
|
+
return getCategoryLayout(_objectSpread(_objectSpread({}, getSize()), {}, {
|
|
112
|
+
transposed: transposed,
|
|
113
|
+
preferHorizontal: preferHorizontal,
|
|
114
|
+
xTicksAtEdges: options.xTicksAtEdges,
|
|
115
|
+
labelCount: labels.length,
|
|
116
|
+
fullWidth: fullWidth,
|
|
117
|
+
fontSize: Number(labelFont.fontSize)
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
var categoryLabels = {
|
|
121
|
+
// Explicit rotation also prevents G2's measurement pass forcing 0°/90°.
|
|
122
|
+
labelAutoRotate: false,
|
|
123
|
+
labelTransform: function labelTransform() {
|
|
124
|
+
return "rotate(".concat(categoryLayout().angle, ")");
|
|
125
|
+
},
|
|
126
|
+
labelWordWrap: true,
|
|
127
|
+
labelWordWrapWidth: function labelWordWrapWidth() {
|
|
128
|
+
return categoryLayout().textWidth;
|
|
129
|
+
},
|
|
130
|
+
labelMaxLines: 1,
|
|
131
|
+
labelTextOverflow: '…',
|
|
132
|
+
transform: [{
|
|
133
|
+
type: 'hide'
|
|
134
|
+
}]
|
|
135
|
+
};
|
|
136
|
+
if (preferHorizontal && !transposed) {
|
|
137
|
+
categoryLabels.labelTextAlign = function (datum, index, ticks) {
|
|
138
|
+
var layout = categoryLayout();
|
|
139
|
+
if (layout.angle !== 0) return 'start';
|
|
140
|
+
if (!ticks || ticks.length <= 1 || index !== 0 && index !== ticks.length - 1) return 'center';
|
|
141
|
+
// Component supplies normalized tick positions. Keep band labels
|
|
142
|
+
// centered unless their text may cross the canvas's default margin.
|
|
143
|
+
var edge = index === 0 ? datum.value : 1 - datum.value;
|
|
144
|
+
var available = Math.max(12, getSize().width - AXIS_HORIZONTAL_PADDING) * edge + DEFAULT_MARGIN_RIGHT;
|
|
145
|
+
var text = String(datum.label);
|
|
146
|
+
var textWidth = Math.min(measureTextWidth(text, labelFont), layout.textWidth);
|
|
147
|
+
return textWidth / 2 <= available ? 'center' : index === 0 ? 'left' : 'right';
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
labels: categoryLabels,
|
|
152
|
+
layout: function layout() {
|
|
153
|
+
return {
|
|
154
|
+
marginRight: categoryLayout().marginRight
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Decide angle and text budget before G2 measures the axis; component hides remaining overlaps. */
|
|
161
|
+
function getCategoryLayout(_ref) {
|
|
162
|
+
var width = _ref.width,
|
|
163
|
+
height = _ref.height,
|
|
164
|
+
transposed = _ref.transposed,
|
|
165
|
+
preferHorizontal = _ref.preferHorizontal,
|
|
166
|
+
xTicksAtEdges = _ref.xTicksAtEdges,
|
|
167
|
+
labelCount = _ref.labelCount,
|
|
168
|
+
fullWidth = _ref.fullWidth,
|
|
169
|
+
fontSize = _ref.fontSize;
|
|
170
|
+
if (transposed) return {
|
|
171
|
+
angle: 0,
|
|
172
|
+
textWidth: Math.max(24, Math.min(120, width * 0.3))
|
|
173
|
+
};
|
|
174
|
+
var limit = Math.max(24, Math.min(160, height * 0.5));
|
|
175
|
+
if (labelCount <= 1) return {
|
|
176
|
+
angle: 0,
|
|
177
|
+
textWidth: limit
|
|
178
|
+
};
|
|
179
|
+
var slot = Math.max(12, (width - AXIS_HORIZONTAL_PADDING) / labelCount - 6);
|
|
180
|
+
if (preferHorizontal) {
|
|
181
|
+
if (fullWidth <= fontSize * 3 || fullWidth <= slot) return {
|
|
182
|
+
angle: 0,
|
|
183
|
+
textWidth: limit
|
|
184
|
+
};
|
|
185
|
+
var marginRight = getDiagonalMarginRight(width, fullWidth, fontSize, labelCount, xTicksAtEdges);
|
|
186
|
+
if (marginRight > MAX_DIAGONAL_MARGIN_RIGHT) return {
|
|
187
|
+
angle: 90,
|
|
188
|
+
textWidth: limit
|
|
189
|
+
};
|
|
190
|
+
var fitsDiagonal = fullWidth <= slot * Math.SQRT2 && fullWidth <= limit && (fullWidth + fontSize) / Math.SQRT2 <= height * 0.25;
|
|
191
|
+
return {
|
|
192
|
+
angle: fitsDiagonal ? 45 : 0,
|
|
193
|
+
textWidth: fitsDiagonal ? fullWidth + 1 : limit,
|
|
194
|
+
marginRight: fitsDiagonal ? marginRight : undefined
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
var longest = Math.min(limit, fullWidth);
|
|
198
|
+
if (longest <= fontSize * 6 || longest <= slot) return {
|
|
199
|
+
angle: 0,
|
|
200
|
+
textWidth: limit
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Keep text attached to its tick. The last band leaves only half a slot at the edge.
|
|
204
|
+
var diagonalWidth = Math.min(limit, slot / Math.SQRT2);
|
|
205
|
+
return diagonalWidth >= Math.min(longest, fontSize * 3) ? {
|
|
206
|
+
angle: 45,
|
|
207
|
+
textWidth: diagonalWidth
|
|
208
|
+
} : {
|
|
209
|
+
angle: 90,
|
|
210
|
+
textWidth: limit
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Reserve diagonal overhang without moving labels away from their ticks. */
|
|
215
|
+
function getDiagonalMarginRight(width, textWidth, fontSize, labelCount) {
|
|
216
|
+
var ticksAtEdges = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
217
|
+
var projection = (textWidth + fontSize / 2) / Math.SQRT2;
|
|
218
|
+
var edgeFraction = ticksAtEdges ? 0 : 1 / (2 * labelCount);
|
|
219
|
+
// Increasing the margin also shrinks the last band's half-slot. Solve for
|
|
220
|
+
// total right margin, including a 4px gap; point scales have no half-slot.
|
|
221
|
+
return Math.max(DEFAULT_MARGIN_RIGHT, Math.ceil((projection + 4 - (width - AXIS_HORIZONTAL_PADDING + DEFAULT_MARGIN_RIGHT) * edgeFraction) / (1 - edgeFraction)));
|
|
222
|
+
}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import type { Theme } from '@antv/g2';
|
|
2
2
|
import type { PluginOptions } from '@antv/g6';
|
|
3
3
|
export type ChartLocale = 'en-US' | 'zh-CN';
|
|
4
|
-
export type CartesianXAxisOptions = {
|
|
5
|
-
xLabels?: unknown[];
|
|
6
|
-
chartWidth?: number;
|
|
7
|
-
};
|
|
8
|
-
export type CartesianAxisOptions = CartesianXAxisOptions & {
|
|
9
|
-
axisXTitle?: string | false;
|
|
10
|
-
axisYTitle?: string | false;
|
|
11
|
-
};
|
|
12
4
|
export declare const resolveChartLocale: (locale?: string) => ChartLocale;
|
|
13
|
-
export declare const getCartesianLayout: ({ xLabels, chartWidth, }: CartesianXAxisOptions) => Record<string, number>;
|
|
14
|
-
export declare const getCartesianAxis: ({ axisXTitle, axisYTitle, xLabels, chartWidth, }: CartesianAxisOptions) => Record<'x' | 'y', Record<string, unknown>>;
|
|
15
5
|
export declare const getColorLegend: (visible: boolean) => false | {
|
|
16
6
|
color: Record<string, never>;
|
|
17
7
|
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
var _excluded = ["visible", "defaultVisible", "contrast", "style", "transform"];
|
|
2
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
|
+
var _excluded = ["visible", "defaultVisible", "contrast", "style", "transform"];
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
3
8
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
9
|
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."); }
|
|
5
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); }
|
|
@@ -8,67 +13,9 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
8
13
|
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; }
|
|
9
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
|
-
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; }
|
|
12
|
-
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; }
|
|
13
|
-
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; }
|
|
14
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
|
-
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); }
|
|
16
|
-
var DEFAULT_CHART_WIDTH = 640;
|
|
17
|
-
var AXIS_HORIZONTAL_PADDING = 96;
|
|
18
|
-
var ANGLED_LABEL_MARGIN_RIGHT_MIN = 32;
|
|
19
|
-
var ANGLED_LABEL_MARGIN_RIGHT_MAX = 64;
|
|
20
|
-
var ANGLED_LABEL_EDGE_GAP = 8;
|
|
21
|
-
var estimateLabelWidth = function estimateLabelWidth(value) {
|
|
22
|
-
return Array.from(String(value !== null && value !== void 0 ? value : '')).reduce(function (width, character) {
|
|
23
|
-
var _character$codePointA;
|
|
24
|
-
return width + (((_character$codePointA = character.codePointAt(0)) !== null && _character$codePointA !== void 0 ? _character$codePointA : 0) > 0xff ? 12 : 7);
|
|
25
|
-
}, 0);
|
|
26
|
-
};
|
|
27
|
-
var shouldUseAngledXAxisLabels = function shouldUseAngledXAxisLabels(labels) {
|
|
28
|
-
var chartWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_CHART_WIDTH;
|
|
29
|
-
if (!(labels !== null && labels !== void 0 && labels.length)) return false;
|
|
30
|
-
var uniqueLabels = Array.from(new Set(labels.map(function (label) {
|
|
31
|
-
return String(label !== null && label !== void 0 ? label : '');
|
|
32
|
-
})));
|
|
33
|
-
if (uniqueLabels.length <= 1) return false;
|
|
34
|
-
var availableWidth = Math.max(chartWidth - AXIS_HORIZONTAL_PADDING, 240);
|
|
35
|
-
var estimatedWidth = uniqueLabels.reduce(function (total, label) {
|
|
36
|
-
return total + Math.max(28, estimateLabelWidth(label) + 16);
|
|
37
|
-
}, 0);
|
|
38
|
-
return estimatedWidth > availableWidth;
|
|
39
|
-
};
|
|
40
16
|
export var resolveChartLocale = function resolveChartLocale(locale) {
|
|
41
17
|
return locale !== null && locale !== void 0 && locale.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
|
|
42
18
|
};
|
|
43
|
-
export var getCartesianLayout = function getCartesianLayout(_ref) {
|
|
44
|
-
var xLabels = _ref.xLabels,
|
|
45
|
-
chartWidth = _ref.chartWidth;
|
|
46
|
-
if (!shouldUseAngledXAxisLabels(xLabels, chartWidth)) return {};
|
|
47
|
-
var tailLabel = xLabels === null || xLabels === void 0 ? void 0 : xLabels[xLabels.length - 1];
|
|
48
|
-
var labelWidth = estimateLabelWidth(tailLabel);
|
|
49
|
-
var projectedHalfWidth = (labelWidth + 12) * Math.SQRT1_2 / 2;
|
|
50
|
-
return {
|
|
51
|
-
marginRight: Math.min(ANGLED_LABEL_MARGIN_RIGHT_MAX, Math.max(ANGLED_LABEL_MARGIN_RIGHT_MIN, Math.ceil(projectedHalfWidth + ANGLED_LABEL_EDGE_GAP)))
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
export var getCartesianAxis = function getCartesianAxis(_ref2) {
|
|
55
|
-
var axisXTitle = _ref2.axisXTitle,
|
|
56
|
-
axisYTitle = _ref2.axisYTitle,
|
|
57
|
-
xLabels = _ref2.xLabels,
|
|
58
|
-
chartWidth = _ref2.chartWidth;
|
|
59
|
-
var useAngledXAxisLabels = shouldUseAngledXAxisLabels(xLabels, chartWidth);
|
|
60
|
-
return {
|
|
61
|
-
x: _objectSpread({
|
|
62
|
-
title: axisXTitle || false
|
|
63
|
-
}, useAngledXAxisLabels ? {
|
|
64
|
-
labelTransform: 'rotate(45)',
|
|
65
|
-
labelAutoRotate: false
|
|
66
|
-
} : {}),
|
|
67
|
-
y: {
|
|
68
|
-
title: axisYTitle || false
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
19
|
export var getColorLegend = function getColorLegend(visible) {
|
|
73
20
|
return visible ? {
|
|
74
21
|
color: {}
|
|
@@ -76,15 +23,15 @@ export var getColorLegend = function getColorLegend(visible) {
|
|
|
76
23
|
};
|
|
77
24
|
|
|
78
25
|
/** Label content and placement belong to the chart; paint comes from the native theme. */
|
|
79
|
-
export function getDataLabels(theme,
|
|
26
|
+
export function getDataLabels(theme, _ref) {
|
|
80
27
|
var _theme$label, _theme$innerLabel;
|
|
81
|
-
var visible =
|
|
82
|
-
|
|
83
|
-
defaultVisible =
|
|
84
|
-
contrast =
|
|
85
|
-
style =
|
|
86
|
-
transform =
|
|
87
|
-
content = _objectWithoutProperties(
|
|
28
|
+
var visible = _ref.visible,
|
|
29
|
+
_ref$defaultVisible = _ref.defaultVisible,
|
|
30
|
+
defaultVisible = _ref$defaultVisible === void 0 ? false : _ref$defaultVisible,
|
|
31
|
+
contrast = _ref.contrast,
|
|
32
|
+
style = _ref.style,
|
|
33
|
+
transform = _ref.transform,
|
|
34
|
+
content = _objectWithoutProperties(_ref, _excluded);
|
|
88
35
|
if (visible === false) return [];
|
|
89
36
|
if (visible !== true && !defaultVisible) return undefined;
|
|
90
37
|
var paint = contrast === 'inside' ? theme.innerLabel : theme.label;
|
|
@@ -94,8 +41,16 @@ export function getDataLabels(theme, _ref3) {
|
|
|
94
41
|
type: 'contrastReverse',
|
|
95
42
|
palette: [textColor, inverseColor]
|
|
96
43
|
}] : [];
|
|
97
|
-
|
|
98
|
-
|
|
44
|
+
// Native overflowStroke chooses a contrasting outline when a label crosses its
|
|
45
|
+
// mark's edge. Inside labels retain contrastReverse; explicit paint wins.
|
|
46
|
+
var strokeTransform = (paint === null || paint === void 0 ? void 0 : paint.stroke) === undefined && (style === null || style === void 0 ? void 0 : style.stroke) === undefined ? [{
|
|
47
|
+
type: 'overflowStroke'
|
|
48
|
+
}] : [];
|
|
49
|
+
var transforms = [].concat(contrastTransform, strokeTransform, _toConsumableArray(transform !== null && transform !== void 0 ? transform : []));
|
|
50
|
+
return [_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, content), strokeTransform.length ? {
|
|
51
|
+
lineWidth: 1.5,
|
|
52
|
+
paintFirst: 'stroke'
|
|
53
|
+
} : {}), transforms.length ? {
|
|
99
54
|
transform: transforms
|
|
100
55
|
} : {}), style), paint)];
|
|
101
56
|
}
|
package/dist/esm/util/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { getChartAnimation } from './animation';
|
|
2
|
+
export { bindCartesianAxisLayout, createCartesianAxis, getCartesianAxis } from './axis';
|
|
3
|
+
export { getColorLegend, getDataLabels, getGraphTitle, resolveChartLocale } from './components';
|
|
4
|
+
export { bindCrosshairAxisLabels } from './crosshair-axis-labels';
|
|
5
|
+
export { escapeHtml } from './html';
|
|
6
|
+
export { getCategoryBackgroundHighlightState, getCategoryHighlightInteraction, getElementHoverScaleInteraction, getLineHighlightState, getPointHighlightState, getSeriesHighlightByColorInteraction, getSharedTooltipInteraction, } from './interaction';
|
|
7
|
+
export { CHART_FONT_FAMILY, CHART_STYLE_DEFAULTS, getChartVisualTokens } from './tokens';
|
package/dist/esm/util/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { getChartAnimation } from "./animation";
|
|
2
|
+
export { bindCartesianAxisLayout, createCartesianAxis, getCartesianAxis } from "./axis";
|
|
3
|
+
export { getColorLegend, getDataLabels, getGraphTitle, resolveChartLocale } from "./components";
|
|
4
|
+
export { bindCrosshairAxisLabels } from "./crosshair-axis-labels";
|
|
5
|
+
export { escapeHtml } from "./html";
|
|
6
|
+
export { getCategoryBackgroundHighlightState, getCategoryHighlightInteraction, getElementHoverScaleInteraction, getLineHighlightState, getPointHighlightState, getSeriesHighlightByColorInteraction, getSharedTooltipInteraction } from "./interaction";
|
|
7
|
+
export { CHART_FONT_FAMILY, CHART_STYLE_DEFAULTS, getChartVisualTokens } from "./tokens";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RendererAnnotation } from '../../annotation/registry';
|
|
1
2
|
import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* AreaDataItem is the type for each data item in the area chart.
|
|
@@ -20,6 +21,7 @@ export interface AreaConfig {
|
|
|
20
21
|
axisYTitle?: string;
|
|
21
22
|
theme?: VisualizationTheme;
|
|
22
23
|
style?: ThemeStyle;
|
|
24
|
+
annotations?: RendererAnnotation<AreaDataItem, 'g2', 'area'>[];
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* AreaInstance represents an area chart instance with render and destroy methods.
|
|
@@ -8,10 +8,9 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
9
|
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); }
|
|
10
10
|
import { Chart } from '@antv/g2';
|
|
11
|
+
import { bindAnnotations } from "../../annotation";
|
|
11
12
|
import { getThemeObject } from "../../theme/g2";
|
|
12
|
-
import { bindCrosshairAxisLabels,
|
|
13
|
-
import { getColorLegend } from "../../util/components";
|
|
14
|
-
import { CHART_STYLE_DEFAULTS } from "../../util/tokens";
|
|
13
|
+
import { bindCartesianAxisLayout, bindCrosshairAxisLabels, CHART_STYLE_DEFAULTS, createCartesianAxis, getChartAnimation, getColorLegend, getLineHighlightState, getSeriesHighlightByColorInteraction, getSharedTooltipInteraction } from "../../util";
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* AreaDataItem is the type for each data item in the area chart.
|
|
@@ -64,6 +63,7 @@ export var Area = function Area(options) {
|
|
|
64
63
|
_options$theme = options.theme,
|
|
65
64
|
chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
|
|
66
65
|
var chart = null;
|
|
66
|
+
var cleanupAnnotations;
|
|
67
67
|
var hasRendered = false;
|
|
68
68
|
var cleanupCrosshairAxisLabels = null;
|
|
69
69
|
|
|
@@ -87,7 +87,8 @@ export var Area = function Area(options) {
|
|
|
87
87
|
|
|
88
88
|
// Clean up previous chart if exists
|
|
89
89
|
if (chart) {
|
|
90
|
-
var _cleanupCrosshairAxis;
|
|
90
|
+
var _cleanupAnnotations, _cleanupCrosshairAxis;
|
|
91
|
+
(_cleanupAnnotations = cleanupAnnotations) === null || _cleanupAnnotations === void 0 || _cleanupAnnotations();
|
|
91
92
|
(_cleanupCrosshairAxis = cleanupCrosshairAxisLabels) === null || _cleanupCrosshairAxis === void 0 || _cleanupCrosshairAxis();
|
|
92
93
|
cleanupCrosshairAxisLabels = null;
|
|
93
94
|
chart.destroy();
|
|
@@ -96,14 +97,19 @@ export var Area = function Area(options) {
|
|
|
96
97
|
var cartesianAxisOptions = {
|
|
97
98
|
axisXTitle: axisXTitle,
|
|
98
99
|
axisYTitle: axisYTitle,
|
|
99
|
-
|
|
100
|
+
preferHorizontal: true,
|
|
101
|
+
xTicksAtEdges: true,
|
|
102
|
+
xValues: data.map(function (_ref) {
|
|
100
103
|
var time = _ref.time;
|
|
101
104
|
return time;
|
|
102
105
|
}),
|
|
103
|
-
|
|
106
|
+
container: container,
|
|
107
|
+
chartWidth: width,
|
|
108
|
+
chartHeight: height
|
|
104
109
|
};
|
|
105
110
|
var appearance = getThemeObject('area', theme, localStyle);
|
|
106
111
|
var rendererTheme = appearance.theme;
|
|
112
|
+
var cartesianAxis = createCartesianAxis(cartesianAxisOptions, rendererTheme);
|
|
107
113
|
var areaMark = _objectSpread({
|
|
108
114
|
fillOpacity: CHART_STYLE_DEFAULTS.areaOpacity
|
|
109
115
|
}, appearance.mark.area);
|
|
@@ -252,9 +258,9 @@ export var Area = function Area(options) {
|
|
|
252
258
|
encode: encode,
|
|
253
259
|
transform: transform,
|
|
254
260
|
children: children,
|
|
255
|
-
scale: scaleConfig
|
|
256
|
-
|
|
257
|
-
|
|
261
|
+
scale: scaleConfig,
|
|
262
|
+
axis: cartesianAxis.axis
|
|
263
|
+
}, cartesianAxis.layout()), {}, {
|
|
258
264
|
legend: getColorLegend(hasGroupField),
|
|
259
265
|
interaction: _objectSpread({
|
|
260
266
|
tooltip: getSharedTooltipInteraction({
|
|
@@ -264,6 +270,20 @@ export var Area = function Area(options) {
|
|
|
264
270
|
theme: rendererTheme
|
|
265
271
|
});
|
|
266
272
|
chart.options(chartOptions);
|
|
273
|
+
cleanupAnnotations = bindAnnotations({
|
|
274
|
+
renderer: 'g2',
|
|
275
|
+
chartType: 'area',
|
|
276
|
+
chart: chart,
|
|
277
|
+
annotations: config.annotations,
|
|
278
|
+
mapping: {
|
|
279
|
+
x: 'time',
|
|
280
|
+
y: 'value',
|
|
281
|
+
series: hasGroupField ? 'group' : undefined,
|
|
282
|
+
data: data
|
|
283
|
+
},
|
|
284
|
+
themeObject: appearance
|
|
285
|
+
});
|
|
286
|
+
bindCartesianAxisLayout(chart, cartesianAxis);
|
|
267
287
|
cleanupCrosshairAxisLabels = bindCrosshairAxisLabels(chart, baseTheme);
|
|
268
288
|
chart.render();
|
|
269
289
|
hasRendered = true;
|
|
@@ -273,6 +293,9 @@ export var Area = function Area(options) {
|
|
|
273
293
|
* Destroy the chart instance and clean up resources.
|
|
274
294
|
*/
|
|
275
295
|
var destroy = function destroy() {
|
|
296
|
+
var _cleanupAnnotations2;
|
|
297
|
+
(_cleanupAnnotations2 = cleanupAnnotations) === null || _cleanupAnnotations2 === void 0 || _cleanupAnnotations2();
|
|
298
|
+
cleanupAnnotations = undefined;
|
|
276
299
|
if (chart) {
|
|
277
300
|
var _cleanupCrosshairAxis2;
|
|
278
301
|
(_cleanupCrosshairAxis2 = cleanupCrosshairAxisLabels) === null || _cleanupCrosshairAxis2 === void 0 || _cleanupCrosshairAxis2();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RendererAnnotation } from '../../annotation/registry';
|
|
1
2
|
import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* BarDataItem is the type for each data item in the bar chart.
|
|
@@ -23,6 +24,7 @@ export interface BarConfig {
|
|
|
23
24
|
axisYTitle?: string;
|
|
24
25
|
theme?: VisualizationTheme;
|
|
25
26
|
style?: ThemeStyle;
|
|
27
|
+
annotations?: RendererAnnotation<BarDataItem, 'g2', 'bar'>[];
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* BarInstance represents a bar chart instance with render and destroy methods.
|
|
@@ -5,10 +5,9 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
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); }
|
|
7
7
|
import { Chart } from '@antv/g2';
|
|
8
|
+
import { bindAnnotations } from "../../annotation";
|
|
8
9
|
import { getThemeObject } from "../../theme/g2";
|
|
9
|
-
import { getCartesianAxis, getCategoryBackgroundHighlightState, getCategoryHighlightInteraction } from "../../util";
|
|
10
|
-
import { getColorLegend, getDataLabels } from "../../util/components";
|
|
11
|
-
import { CHART_STYLE_DEFAULTS } from "../../util/tokens";
|
|
10
|
+
import { CHART_STYLE_DEFAULTS, getCartesianAxis, getCategoryBackgroundHighlightState, getCategoryHighlightInteraction, getColorLegend, getDataLabels } from "../../util";
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* BarDataItem is the type for each data item in the bar chart.
|
|
@@ -55,6 +54,7 @@ export var Bar = function Bar(options) {
|
|
|
55
54
|
_options$theme = options.theme,
|
|
56
55
|
chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
|
|
57
56
|
var chart = null;
|
|
57
|
+
var cleanupAnnotations;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Render the bar chart with the given configuration.
|
|
@@ -79,6 +79,8 @@ export var Bar = function Bar(options) {
|
|
|
79
79
|
|
|
80
80
|
// Clean up previous chart if exists
|
|
81
81
|
if (chart) {
|
|
82
|
+
var _cleanupAnnotations;
|
|
83
|
+
(_cleanupAnnotations = cleanupAnnotations) === null || _cleanupAnnotations === void 0 || _cleanupAnnotations();
|
|
82
84
|
chart.destroy();
|
|
83
85
|
}
|
|
84
86
|
var hasGroupField = data.length > 0 && ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.group) !== undefined;
|
|
@@ -165,9 +167,18 @@ export var Bar = function Bar(options) {
|
|
|
165
167
|
},
|
|
166
168
|
scale: scaleConfig,
|
|
167
169
|
axis: getCartesianAxis({
|
|
170
|
+
xType: 'category',
|
|
171
|
+
xValues: data.map(function (_ref) {
|
|
172
|
+
var category = _ref.category;
|
|
173
|
+
return category;
|
|
174
|
+
}),
|
|
175
|
+
container: container,
|
|
176
|
+
chartWidth: width,
|
|
177
|
+
chartHeight: height,
|
|
168
178
|
axisXTitle: axisXTitle,
|
|
169
|
-
axisYTitle: axisYTitle
|
|
170
|
-
|
|
179
|
+
axisYTitle: axisYTitle,
|
|
180
|
+
transposed: true
|
|
181
|
+
}, rendererTheme),
|
|
171
182
|
legend: getColorLegend(hasGroupField),
|
|
172
183
|
labels: getDataLabels(rendererTheme, {
|
|
173
184
|
visible: label,
|
|
@@ -176,7 +187,10 @@ export var Bar = function Bar(options) {
|
|
|
176
187
|
position: 'right',
|
|
177
188
|
contrast: 'inside',
|
|
178
189
|
dx: -4,
|
|
179
|
-
dy: 0
|
|
190
|
+
dy: 0,
|
|
191
|
+
transform: [{
|
|
192
|
+
type: 'overflowHide'
|
|
193
|
+
}]
|
|
180
194
|
}),
|
|
181
195
|
tooltip: {
|
|
182
196
|
items: [function (d) {
|
|
@@ -195,6 +209,20 @@ export var Bar = function Bar(options) {
|
|
|
195
209
|
theme: rendererTheme
|
|
196
210
|
};
|
|
197
211
|
chart.options(chartOptions);
|
|
212
|
+
cleanupAnnotations = bindAnnotations({
|
|
213
|
+
renderer: 'g2',
|
|
214
|
+
chartType: 'bar',
|
|
215
|
+
chart: chart,
|
|
216
|
+
annotations: config.annotations,
|
|
217
|
+
mapping: {
|
|
218
|
+
x: 'category',
|
|
219
|
+
y: 'value',
|
|
220
|
+
series: hasGroupField ? 'group' : undefined,
|
|
221
|
+
data: data,
|
|
222
|
+
interval: true
|
|
223
|
+
},
|
|
224
|
+
themeObject: appearance
|
|
225
|
+
});
|
|
198
226
|
chart.render();
|
|
199
227
|
};
|
|
200
228
|
|
|
@@ -202,6 +230,9 @@ export var Bar = function Bar(options) {
|
|
|
202
230
|
* Destroy the chart instance and clean up resources.
|
|
203
231
|
*/
|
|
204
232
|
var destroy = function destroy() {
|
|
233
|
+
var _cleanupAnnotations2;
|
|
234
|
+
(_cleanupAnnotations2 = cleanupAnnotations) === null || _cleanupAnnotations2 === void 0 || _cleanupAnnotations2();
|
|
235
|
+
cleanupAnnotations = undefined;
|
|
205
236
|
if (chart) {
|
|
206
237
|
chart.destroy();
|
|
207
238
|
chart = null;
|
|
@@ -12,7 +12,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
13
|
import { Chart } from '@antv/g2';
|
|
14
14
|
import { getThemeObject } from "../../theme/g2";
|
|
15
|
-
import { getCartesianAxis, getColorLegend } from "../../util
|
|
15
|
+
import { getCartesianAxis, getColorLegend } from "../../util";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* BoxplotDataItem is the type for each data item in the boxplot chart.
|
|
@@ -140,9 +140,17 @@ export var Boxplot = function Boxplot(options) {
|
|
|
140
140
|
} : '',
|
|
141
141
|
encode: encode,
|
|
142
142
|
axis: getCartesianAxis({
|
|
143
|
+
xType: 'category',
|
|
144
|
+
xValues: data.map(function (_ref3) {
|
|
145
|
+
var category = _ref3.category;
|
|
146
|
+
return category;
|
|
147
|
+
}),
|
|
148
|
+
container: container,
|
|
149
|
+
chartWidth: width,
|
|
150
|
+
chartHeight: height,
|
|
143
151
|
axisXTitle: axisXTitle,
|
|
144
152
|
axisYTitle: axisYTitle
|
|
145
|
-
}),
|
|
153
|
+
}, rendererTheme),
|
|
146
154
|
scale: {
|
|
147
155
|
x: {
|
|
148
156
|
paddingInner: 0.6,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RendererAnnotation } from '../../annotation/registry';
|
|
1
2
|
import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* ColumnDataItem is the type for each data item in the column chart.
|
|
@@ -23,6 +24,7 @@ export interface ColumnConfig {
|
|
|
23
24
|
axisYTitle?: string;
|
|
24
25
|
theme?: VisualizationTheme;
|
|
25
26
|
style?: ThemeStyle;
|
|
27
|
+
annotations?: RendererAnnotation<ColumnDataItem, 'g2', 'column'>[];
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* ColumnInstance represents a column chart instance with render and destroy methods.
|