@opentiny/vue-renderless 3.6.7 → 3.8.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/action-sheet/index.js +28 -1
- package/action-sheet/vue.js +10 -4
- package/alert/index.js +24 -2
- package/alert/vue.js +15 -11
- package/amount/index.js +4 -4
- package/anchor/index.js +1 -1
- package/autocomplete/vue.js +3 -3
- package/autonavi-map/index.js +1 -1
- package/badge/vue.js +6 -6
- package/baidu-map/index.js +1 -1
- package/bulletin-board/index.js +1 -1
- package/calendar/index.js +2 -2
- package/calendar-bar/index.js +268 -0
- package/calendar-bar/vue.js +87 -0
- package/card/index.js +84 -0
- package/card/vue.js +70 -0
- package/card-group/index.js +16 -0
- package/card-group/vue.js +21 -0
- package/card-template/index.js +1 -1
- package/carousel/index.js +89 -2
- package/carousel/vue.js +14 -5
- package/carousel-item/index.js +8 -0
- package/carousel-item/vue.js +7 -3
- package/cascader/index.js +6 -6
- package/cascader/vue.js +3 -3
- package/cascader-menu/vue.js +2 -2
- package/cascader-panel/index.js +4 -4
- package/cascader-panel/node.js +4 -4
- package/cascader-panel/vue.js +2 -2
- package/cascader-select/index.js +179 -0
- package/cascader-select/vue.js +74 -0
- package/cell/vue.js +16 -0
- package/chart-bar/index.js +3 -3
- package/chart-boxplot/index.js +2 -2
- package/chart-candle/index.js +3 -3
- package/chart-core/deps/utils.js +7 -7
- package/chart-core/index.js +2 -2
- package/chart-funnel/index.js +3 -3
- package/chart-gauge/index.js +3 -3
- package/chart-graph/index.js +1 -1
- package/chart-heatmap/index.js +2 -2
- package/chart-line/index.js +3 -3
- package/chart-liquidfill/index.js +2 -2
- package/chart-map/index.js +3 -3
- package/chart-pie/index.js +3 -3
- package/chart-radar/index.js +3 -3
- package/chart-sankey/index.js +3 -3
- package/chart-scatter/index.js +4 -4
- package/chart-sunburst/index.js +1 -1
- package/chart-tree/index.js +2 -2
- package/chart-waterfall/index.js +3 -3
- package/chart-wordcloud/index.js +2 -2
- package/checkbox/index.js +21 -0
- package/checkbox/vue.js +16 -3
- package/checkbox-button/vue.js +1 -1
- package/collapse-item/vue.js +1 -1
- package/column-list-group/index.js +0 -0
- package/column-list-group/vue.js +14 -0
- package/column-list-item/index.js +50 -0
- package/column-list-item/vue.js +39 -0
- package/common/array.js +3 -3
- package/common/bigInt.js +5 -2
- package/common/dataset/index.js +3 -3
- package/common/date.js +2 -2
- package/common/deps/ResizeObserver.js +1 -1
- package/common/deps/clickoutside.js +1 -1
- package/common/deps/date-util.js +4 -4
- package/common/deps/date.js +2 -2
- package/common/deps/debounce.js +1 -1
- package/common/deps/dom.js +1 -1
- package/common/deps/fullscreen/apis.js +3 -3
- package/common/deps/fullscreen/screenfull.js +1 -1
- package/common/deps/infinite-scroll.js +176 -0
- package/common/deps/letter-only.js +1 -1
- package/common/deps/number-only.js +1 -1
- package/common/deps/observe-visibility.js +106 -0
- package/common/deps/popper.js +20 -22
- package/common/deps/popup-manager.js +2 -2
- package/common/deps/repeat-click.js +1 -1
- package/common/deps/resize-event.js +1 -1
- package/common/deps/tree-model/node.js +5 -5
- package/common/deps/tree-model/tree-store.js +3 -3
- package/common/deps/upload-ajax.js +2 -2
- package/common/deps/vue-popper.js +4 -4
- package/common/deps/vue-popup.js +4 -4
- package/common/index.js +2 -2
- package/common/object.js +1 -1
- package/common/runtime.js +24 -24
- package/common/string.js +23 -4
- package/common/validate/rules/range.js +2 -2
- package/common/validate/rules/required.js +1 -1
- package/common/validate/rules/type.js +3 -3
- package/common/validate/schema.js +1 -1
- package/common/validate/util.js +1 -1
- package/common/validate/validations/array.js +1 -1
- package/common/validate/validations/date.js +1 -1
- package/common/validate/validations/enum.js +1 -1
- package/common/validate/validations/float.js +1 -1
- package/common/validate/validations/integer.js +1 -1
- package/common/validate/validations/method.js +1 -1
- package/common/validate/validations/number.js +1 -1
- package/common/validate/validations/pattern.js +1 -1
- package/common/validate/validations/string.js +1 -1
- package/common/validate/validations/type.js +1 -1
- package/container/index.js +1 -1
- package/crop/index.js +2 -2
- package/currency/index.js +2 -2
- package/date-panel/index.js +7 -7
- package/date-panel/vue.js +3 -2
- package/date-picker-mobile/index.js +250 -0
- package/date-picker-mobile/vue.js +86 -0
- package/date-range/index.js +1 -1
- package/date-range/vue.js +1 -1
- package/date-table/index.js +3 -3
- package/date-table/vue.js +1 -1
- package/dialog-box/index.js +10 -6
- package/dialog-box/vue.js +1 -1
- package/dialog-select/index.js +345 -0
- package/dialog-select/vue.js +110 -0
- package/drawer/index.js +83 -0
- package/drawer/vue.js +51 -0
- package/drop-times/index.js +1 -1
- package/dropdown/index.js +2 -2
- package/dropdown/vue.js +1 -1
- package/dropdown-item/index.js +1 -1
- package/dropdown-item/mf.js +79 -0
- package/dropdown-menu/index.js +30 -1
- package/dropdown-menu/vue.js +17 -7
- package/dynamic-scroller/index.js +117 -0
- package/dynamic-scroller/vue.js +88 -0
- package/dynamic-scroller-item/index.js +147 -0
- package/dynamic-scroller-item/vue.js +92 -0
- package/espace/index.js +1 -1
- package/espace/vue.js +1 -1
- package/exception/vue.js +3 -1
- package/fall-menu/index.js +4 -4
- package/file-upload/index.js +872 -408
- package/file-upload/vue.js +87 -36
- package/filter/index.js +131 -0
- package/filter/tag-group.js +43 -0
- package/filter/vue.js +73 -0
- package/filter-bar/index.js +9 -0
- package/filter-bar/vue.js +16 -0
- package/filter-box/index.js +17 -0
- package/filter-box/vue.js +19 -0
- package/filter-panel/index.js +42 -0
- package/filter-panel/vue.js +33 -0
- package/floatbar/index.js +1 -1
- package/flowchart/index.js +721 -0
- package/flowchart/vue.js +81 -0
- package/form/index.js +15 -1
- package/form/vue.js +10 -4
- package/form-item/index.js +46 -6
- package/form-item/vue.js +27 -3
- package/fullscreen/index.js +1 -1
- package/fullscreen/vue.js +1 -1
- package/grid/plugins/export.js +2 -2
- package/grid/plugins/exportExcel.js +2 -2
- package/grid/plugins/resize.js +1 -1
- package/grid/static/base/helperEqualCompare.js +1 -1
- package/grid/static/base/isPlainObject.js +1 -1
- package/grid/utils/common.js +3 -3
- package/grid/utils/dom.js +3 -3
- package/grid/utils/event.js +2 -2
- package/guide/index.js +168 -0
- package/guide/vue.js +36 -0
- package/hrapprover/index.js +1 -1
- package/image/index.js +8 -4
- package/image/vue.js +12 -6
- package/image-viewer/index.js +3 -3
- package/image-viewer/vue.js +16 -6
- package/input/index.js +34 -1
- package/input/vue.js +22 -6
- package/ip-address/index.js +1 -1
- package/ip-address/vue.js +1 -1
- package/link-menu/index.js +2 -2
- package/link-menu/vue.js +2 -2
- package/loading/index.js +2 -2
- package/loading/vue.js +2 -1
- package/locales/index.js +1 -1
- package/logout/index.js +1 -1
- package/milestone/index.js +5 -1
- package/modal/index.js +68 -39
- package/modal/vue.js +15 -12
- package/month-range/index.js +1 -1
- package/month-range/vue.js +1 -1
- package/month-table/index.js +5 -5
- package/month-table/vue.js +1 -1
- package/multi-select/index.js +5 -2
- package/multi-select/vue.js +4 -5
- package/nav-menu/index.js +6 -6
- package/notify/index.js +3 -3
- package/numeric/index.js +15 -5
- package/numeric/vue.js +15 -6
- package/option/index.js +1 -1
- package/package.json +2 -1
- package/pager-item/index.js +1 -1
- package/panel/index.js +1 -1
- package/picker/index.js +7 -7
- package/picker/vue.js +1 -1
- package/picker-column/index.js +1 -1
- package/popconfirm/index.js +25 -0
- package/popconfirm/vue.js +22 -0
- package/popeditor/index.js +7 -7
- package/popeditor/vue.js +2 -2
- package/popover/index.js +11 -3
- package/popover/vue.js +33 -10
- package/popup/index.js +4 -4
- package/pull-refresh/index.js +8 -11
- package/pull-refresh/vue.js +7 -7
- package/radio/index.js +17 -0
- package/radio/vue.js +18 -3
- package/radio-button/index.js +8 -0
- package/radio-button/vue.js +19 -4
- package/radio-group/index.js +1 -1
- package/radio-group/vue.js +5 -2
- package/rate/index.js +4 -2
- package/rate/vue.js +1 -1
- package/record/index.js +190 -0
- package/record/vue.js +44 -0
- package/recycle-scroller/index.js +470 -0
- package/recycle-scroller/vue.js +135 -0
- package/river/index.js +371 -0
- package/river/river.js +352 -0
- package/river/vue.js +77 -0
- package/roles/index.js +1 -1
- package/scrollbar/vue-bar.js +1 -1
- package/scrollbar/vue.js +1 -1
- package/search/index.js +3 -3
- package/select/index.js +17 -14
- package/select/vue.js +14 -8
- package/select-dropdown/vue.js +1 -1
- package/select-mobile/index.js +111 -0
- package/select-mobile/vue.js +58 -0
- package/select-view/index.js +170 -0
- package/select-view/vue.js +82 -0
- package/selected-box/index.js +216 -0
- package/selected-box/vue.js +98 -0
- package/slide-bar/index.js +1 -1
- package/slider/index.js +49 -4
- package/slider/vue.js +15 -4
- package/split/vue.js +1 -1
- package/standard-list-item/index.js +18 -0
- package/standard-list-item/vue.js +22 -0
- package/steps/index.js +30 -0
- package/steps/slide-bar.js +122 -0
- package/steps/vue.js +15 -3
- package/switch/index.js +1 -1
- package/switch/vue.js +2 -1
- package/tab-bar/index.js +2 -2
- package/tab-item/index.js +2 -2
- package/tab-item/vue.js +1 -1
- package/tab-item-mf/index.js +0 -0
- package/tab-item-mf/vue.js +16 -0
- package/tab-nav/index.js +78 -4
- package/tab-nav/vue.js +11 -3
- package/tabbar-item/index.js +1 -1
- package/tabbar-item/vue.js +1 -1
- package/tabs/index.js +8 -9
- package/tabs/vue.js +1 -1
- package/tabs-mf/index.js +109 -0
- package/tabs-mf/vue-bar.js +49 -0
- package/tabs-mf/vue-nav-item.js +22 -0
- package/tabs-mf/vue-nav.js +13 -0
- package/tabs-mf/vue.js +45 -0
- package/tabs-mf/wheel.js +71 -0
- package/tag/index.js +8 -2
- package/tag/vue.js +13 -5
- package/tag-group/index.js +24 -0
- package/tag-group/vue.js +29 -0
- package/tall-storage/index.js +1 -1
- package/tall-storage/vue.js +1 -1
- package/time/index.js +1 -1
- package/time/vue.js +2 -2
- package/time-line/index.js +28 -7
- package/time-line/vue.js +9 -4
- package/time-panel/index.js +2 -2
- package/time-panel/vue.js +1 -1
- package/time-picker-mobile/index.js +30 -0
- package/time-picker-mobile/vue.js +30 -0
- package/time-range/index.js +1 -1
- package/time-range/vue.js +1 -1
- package/time-spinner/index.js +2 -2
- package/time-spinner/vue.js +1 -1
- package/toggle-menu/index.js +2 -2
- package/toggle-menu/vue.js +1 -1
- package/tooltip/index.js +30 -3
- package/tooltip/vue.js +33 -12
- package/top-box/index.js +3 -3
- package/transfer/index.js +1 -1
- package/transfer-panel/index.js +2 -2
- package/tree/index.js +6 -6
- package/tree/vue.js +1 -1
- package/tree-node/index.js +1 -1
- package/upload/index.js +1 -2
- package/upload/vue.js +2 -2
- package/upload-dragger/index.js +5 -1
- package/upload-dragger/vue.js +9 -3
- package/upload-list/index.js +158 -8
- package/upload-list/vue.js +77 -25
- package/user/index.js +86 -70
- package/user/vue.js +15 -5
- package/user-account/vue.js +1 -1
- package/user-contact/index.js +49 -3
- package/user-contact/vue.js +17 -8
- package/user-head-group/vue.js +17 -0
- package/user-link/index.js +10 -2
- package/user-link/vue.js +11 -6
- package/wheel/index.js +1 -1
- package/wizard/index.js +3 -3
- package/year-range/index.js +125 -0
- package/year-range/vue.js +88 -0
- package/year-table/index.js +175 -11
- package/year-table/vue.js +17 -5
|
@@ -0,0 +1,721 @@
|
|
|
1
|
+
import "../chunk-PKUHTIDK.js";
|
|
2
|
+
import debounce from "../common/deps/debounce";
|
|
3
|
+
import { omitText as omit } from "../common/string";
|
|
4
|
+
const compute = ({ api, markRaw, props, state }) => () => {
|
|
5
|
+
const { data, config } = props;
|
|
6
|
+
const { nodes, links } = data;
|
|
7
|
+
const seg = (qty, segs) => {
|
|
8
|
+
const rmd = qty % segs;
|
|
9
|
+
const quot = (qty - rmd) / segs;
|
|
10
|
+
const rmdHalf = rmd / 2;
|
|
11
|
+
const rmd1 = Math.floor(rmdHalf);
|
|
12
|
+
const rmd2 = Math.ceil(rmdHalf);
|
|
13
|
+
return Array.from({ length: segs }).map((o, i) => quot + (i === 0 ? rmd1 : i === segs - 1 ? rmd2 : 0));
|
|
14
|
+
};
|
|
15
|
+
const widths = seg(config.width, config.cols);
|
|
16
|
+
const heights = seg(config.height, config.rows);
|
|
17
|
+
const afterNodes = api.buildAfterNode(nodes, widths, heights);
|
|
18
|
+
const afterLinks = api.buildAfterLink(links, widths, heights, afterNodes);
|
|
19
|
+
const hoverState = api.buildHoverState(afterLinks);
|
|
20
|
+
const allItem = api.getAllItem(nodes);
|
|
21
|
+
const dropdowns = api.initDropdowns(nodes);
|
|
22
|
+
state.afterData = markRaw({ afterNodes, afterLinks, widths, heights, allItem, hoverState });
|
|
23
|
+
state.wrapperStyle = `width:${config.width}px;height:${config.height}px`;
|
|
24
|
+
state.dropdowns = dropdowns;
|
|
25
|
+
};
|
|
26
|
+
const buildAfterNode = (props) => (nodes, widths, heights) => {
|
|
27
|
+
const { config } = props;
|
|
28
|
+
const cache = { col: {}, row: {} };
|
|
29
|
+
const half = (qty) => qty >>> 1;
|
|
30
|
+
const pos = (node, widths2, heights2, cache2) => {
|
|
31
|
+
const { info } = node;
|
|
32
|
+
const { col, row } = info;
|
|
33
|
+
let x = cache2.col[col];
|
|
34
|
+
let y = cache2.row[row];
|
|
35
|
+
if (!x) {
|
|
36
|
+
cache2.col[col] = x = widths2.reduce((p2, c, i) => p2 + (i < col ? c : i === col ? half(c) : 0), 0);
|
|
37
|
+
}
|
|
38
|
+
if (!y) {
|
|
39
|
+
cache2.row[row] = y = heights2.reduce((p2, c, i) => p2 + (i < row ? c : i === row ? half(c) : 0), 0);
|
|
40
|
+
}
|
|
41
|
+
let p = { type: "node", x, y, raw: node };
|
|
42
|
+
typeof config.adjustPos === "function" && config.adjustPos(p);
|
|
43
|
+
return p;
|
|
44
|
+
};
|
|
45
|
+
return nodes.map((node) => pos(node, widths, heights, cache));
|
|
46
|
+
};
|
|
47
|
+
const buildAfterLink = () => (links, widths, heights, afterNodes) => {
|
|
48
|
+
const path = (link, cWidth, rHeight, afterNodes2) => {
|
|
49
|
+
const { from, to, p } = link;
|
|
50
|
+
const nodeFrom = afterNodes2.find((node) => node.raw.name === from);
|
|
51
|
+
const nodeTo = afterNodes2.find((node) => node.raw.name === to);
|
|
52
|
+
const { x: fx, y: fy } = nodeFrom;
|
|
53
|
+
const { x: tx, y: ty } = nodeTo;
|
|
54
|
+
const regDir = /^([lrtb])(\d+(\.\d+)?)$/;
|
|
55
|
+
const regDirC = /^([lrtb])(\d+(\.\d+)?)c$/;
|
|
56
|
+
const relative = (x, y, p2, cw, rh) => {
|
|
57
|
+
p2 = p2.toLowerCase();
|
|
58
|
+
p2 = p2.replace(/\s+/g, " ");
|
|
59
|
+
p2 = p2.replace(/\sc/g, "c");
|
|
60
|
+
const paths = p2.split(/\s/);
|
|
61
|
+
let curr = [];
|
|
62
|
+
let match, n, ar0, ar1, curr2;
|
|
63
|
+
const operCurr = (curr3, type, value) => {
|
|
64
|
+
if (type === "l") {
|
|
65
|
+
curr3[0] -= Math.floor(value * cw);
|
|
66
|
+
} else if (type === "r") {
|
|
67
|
+
curr3[0] += Math.floor(value * cw);
|
|
68
|
+
} else if (type === "t") {
|
|
69
|
+
curr3[1] -= Math.floor(value * rh);
|
|
70
|
+
} else if (type === "b") {
|
|
71
|
+
curr3[1] += Math.floor(value * rh);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return paths.reduce((p3, c, i, a) => {
|
|
75
|
+
if (i) {
|
|
76
|
+
if (regDir.test(c)) {
|
|
77
|
+
match = regDir.exec(c);
|
|
78
|
+
operCurr(curr, match[1], parseFloat(match[2]));
|
|
79
|
+
p3.push(`l,${curr[0]},${curr[1]}`);
|
|
80
|
+
} else if (regDirC.test(c)) {
|
|
81
|
+
n = a[i + 1];
|
|
82
|
+
match = regDirC.exec(c);
|
|
83
|
+
operCurr(curr, match[1], parseFloat(match[2]));
|
|
84
|
+
ar0 = [...curr];
|
|
85
|
+
if (regDir.test(n)) {
|
|
86
|
+
match = regDir.exec(n);
|
|
87
|
+
} else if (regDirC.test(n)) {
|
|
88
|
+
match = regDirC.exec(n);
|
|
89
|
+
}
|
|
90
|
+
curr2 = [...curr];
|
|
91
|
+
operCurr(curr2, match[1], parseFloat(match[2]) / 2);
|
|
92
|
+
ar1 = [...curr2];
|
|
93
|
+
p3.push(`a,${ar0[0]},${ar0[1]},${ar1[0]},${ar1[1]},8`);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
curr = [x, y];
|
|
97
|
+
if (regDir.test(c)) {
|
|
98
|
+
match = regDir.exec(c);
|
|
99
|
+
operCurr(curr, match[1], parseFloat(match[2]));
|
|
100
|
+
}
|
|
101
|
+
p3.push(`m,${curr[0]},${curr[1]}`);
|
|
102
|
+
}
|
|
103
|
+
return p3;
|
|
104
|
+
}, []);
|
|
105
|
+
};
|
|
106
|
+
if (p) {
|
|
107
|
+
return { type: "link", p: relative(fx, fy, p, cWidth, rHeight), raw: link };
|
|
108
|
+
}
|
|
109
|
+
return { type: "link", p: [`m,${fx},${fy}`, `l,${tx},${ty}`], raw: link };
|
|
110
|
+
};
|
|
111
|
+
return links.map((link) => path(link, widths[1], heights[1], afterNodes));
|
|
112
|
+
};
|
|
113
|
+
const drawAfterLink = ({ api, props, state, vm }) => () => {
|
|
114
|
+
const { config } = props;
|
|
115
|
+
const { afterData } = state;
|
|
116
|
+
const { $refs } = vm;
|
|
117
|
+
const { afterLinks, afterNodes, graph } = afterData;
|
|
118
|
+
const mmap = { m: "moveTo", l: "lineTo", a: "arcTo" };
|
|
119
|
+
const dpr = window.devicePixelRatio;
|
|
120
|
+
const drawLinePart = (ctx, p) => {
|
|
121
|
+
const paths = p.split(",");
|
|
122
|
+
ctx[mmap[paths[0]]](...paths.slice(1).map(Number));
|
|
123
|
+
};
|
|
124
|
+
const draw = (ctx, afterLink) => {
|
|
125
|
+
const { p, raw } = afterLink;
|
|
126
|
+
const { status, style } = raw.info;
|
|
127
|
+
const color = config.colors[status];
|
|
128
|
+
ctx.save();
|
|
129
|
+
ctx.beginPath();
|
|
130
|
+
if (typeof config.drawLink === "function") {
|
|
131
|
+
config.drawLink(ctx, afterLink, afterNodes);
|
|
132
|
+
} else {
|
|
133
|
+
if (typeof config.styleLink === "function") {
|
|
134
|
+
config.styleLink(ctx);
|
|
135
|
+
} else {
|
|
136
|
+
ctx.strokeStyle = color;
|
|
137
|
+
style !== "solid" && ctx.setLineDash(api.isMf() ? [6, 6] : [2, 4]);
|
|
138
|
+
}
|
|
139
|
+
if (api.isLinkHover(afterLink) && typeof config.styleHoverLink === "function") {
|
|
140
|
+
config.styleHoverLink(ctx);
|
|
141
|
+
}
|
|
142
|
+
p.map((p2) => drawLinePart(ctx, p2));
|
|
143
|
+
}
|
|
144
|
+
ctx.stroke();
|
|
145
|
+
ctx.restore();
|
|
146
|
+
};
|
|
147
|
+
if ($refs.canvas && $refs.canvas.getContext) {
|
|
148
|
+
const ctx = $refs.canvas.getContext("2d");
|
|
149
|
+
const width = graph ? graph.width : config.width;
|
|
150
|
+
const height = graph ? graph.height : config.height;
|
|
151
|
+
if (ctx) {
|
|
152
|
+
ctx.save();
|
|
153
|
+
ctx.beginPath();
|
|
154
|
+
ctx.clearRect(0, 0, width, height);
|
|
155
|
+
ctx.fillStyle = config.background;
|
|
156
|
+
ctx.fillRect(0, 0, width, height);
|
|
157
|
+
ctx.imageSmoothingEnabled = true;
|
|
158
|
+
ctx.webkitImageSmoothingEnabled = true;
|
|
159
|
+
ctx.imageSmoothingQuality = "high";
|
|
160
|
+
ctx.webkitImageSmoothingQuality = "high";
|
|
161
|
+
ctx.lineCap = "round";
|
|
162
|
+
ctx.lineJoin = "round";
|
|
163
|
+
ctx.lineWidth = api.isMf() ? (config.lineWidth || 1) / dpr : 2;
|
|
164
|
+
ctx.miterLimit = 0;
|
|
165
|
+
ctx.lineDashOffset = 0;
|
|
166
|
+
afterLinks.map((afterLink) => draw(ctx, afterLink));
|
|
167
|
+
ctx.restore();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
api.isMf() && api.drawArrow();
|
|
171
|
+
};
|
|
172
|
+
const refresh = ({ api, nextTick, state }) => () => {
|
|
173
|
+
api.removeListeners();
|
|
174
|
+
if (api.isMf()) {
|
|
175
|
+
api.computeMf();
|
|
176
|
+
} else {
|
|
177
|
+
api.compute();
|
|
178
|
+
}
|
|
179
|
+
state.refreshKey++;
|
|
180
|
+
nextTick(() => {
|
|
181
|
+
api.drawAfterLink();
|
|
182
|
+
api.addListeners();
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
const getAllItem = (props) => (nodes) => {
|
|
186
|
+
const allItem = {};
|
|
187
|
+
const { config } = props;
|
|
188
|
+
const { headUrl } = config;
|
|
189
|
+
nodes.map(({ info: { items } }) => {
|
|
190
|
+
if (Array.isArray(items) && items.length) {
|
|
191
|
+
items.map(({ key }) => {
|
|
192
|
+
allItem[key] = (headUrl || "").replace("{0}", String(key));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return allItem;
|
|
197
|
+
};
|
|
198
|
+
const initDropdowns = () => (nodes) => {
|
|
199
|
+
const res = {};
|
|
200
|
+
nodes.map(({ name }) => res[name] = false);
|
|
201
|
+
return res;
|
|
202
|
+
};
|
|
203
|
+
const getVars = () => (afterNode, config) => {
|
|
204
|
+
const statusFn = () => afterNode.raw.info.status;
|
|
205
|
+
const isCompleteFn = () => statusFn() === config.statusComplete;
|
|
206
|
+
const isOngoingFn = () => statusFn() === config.statusOngoing;
|
|
207
|
+
const isFailFn = () => statusFn() === config.statusFail;
|
|
208
|
+
const half = (qty) => qty >>> 1;
|
|
209
|
+
const white = "#fff";
|
|
210
|
+
let { background, borderColor, statusName } = {};
|
|
211
|
+
background = borderColor = config.colors[statusFn()];
|
|
212
|
+
statusName = config.status[statusFn()];
|
|
213
|
+
isCompleteFn() && (background = white);
|
|
214
|
+
return { background, borderColor, half, isCompleteFn, isFailFn, isOngoingFn, statusName, white };
|
|
215
|
+
};
|
|
216
|
+
const isLinkHover = (state) => (afterLink) => state.hoverAfterLink === afterLink;
|
|
217
|
+
const omitText = omit;
|
|
218
|
+
const buildHoverState = (props) => (afterLinks) => {
|
|
219
|
+
const { config } = props;
|
|
220
|
+
const { hoverHit } = config;
|
|
221
|
+
const hoverMap = /* @__PURE__ */ new WeakMap();
|
|
222
|
+
const hoverList = [];
|
|
223
|
+
const createItem = (cur, next, afterLink) => {
|
|
224
|
+
if (cur[0] === next[0]) {
|
|
225
|
+
const top = cur[1] < next[1] ? cur : next;
|
|
226
|
+
const bottom = cur[1] < next[1] ? next : cur;
|
|
227
|
+
const tri1 = [top[0] + hoverHit, top[1], top[0] - hoverHit, top[1], bottom[0] - hoverHit, bottom[1]];
|
|
228
|
+
const tri2 = [bottom[0] - hoverHit, bottom[1], bottom[0] + hoverHit, bottom[1], top[0] + hoverHit, top[1]];
|
|
229
|
+
hoverList.push(tri1);
|
|
230
|
+
hoverMap.set(tri1, afterLink);
|
|
231
|
+
hoverList.push(tri2);
|
|
232
|
+
hoverMap.set(tri2, afterLink);
|
|
233
|
+
} else if (cur[1] === next[1]) {
|
|
234
|
+
const left = cur[0] < next[0] ? cur : next;
|
|
235
|
+
const right = cur[0] < next[0] ? next : cur;
|
|
236
|
+
const tri1 = [left[0], left[1] - hoverHit, left[0], left[1] + hoverHit, right[0], right[1] + hoverHit];
|
|
237
|
+
const tri2 = [right[0], right[1] + hoverHit, right[0], right[1] - hoverHit, left[0], left[1] - hoverHit];
|
|
238
|
+
hoverList.push(tri1);
|
|
239
|
+
hoverMap.set(tri1, afterLink);
|
|
240
|
+
hoverList.push(tri2);
|
|
241
|
+
hoverMap.set(tri2, afterLink);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
afterLinks.map((afterLink) => {
|
|
245
|
+
const { p } = afterLink;
|
|
246
|
+
let cur, next;
|
|
247
|
+
p.map((p2) => {
|
|
248
|
+
const parts = p2.split(",");
|
|
249
|
+
if (parts[0] === "m") {
|
|
250
|
+
cur = parts.slice(1).map(Number);
|
|
251
|
+
} else if (parts[0] === "l") {
|
|
252
|
+
next = parts.slice(1).map(Number);
|
|
253
|
+
createItem(cur, next, afterLink);
|
|
254
|
+
cur = next;
|
|
255
|
+
} else if (parts[0] === "a") {
|
|
256
|
+
next = parts.slice(1, 3).map(Number);
|
|
257
|
+
createItem(cur, next, afterLink);
|
|
258
|
+
cur = next;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
return { hoverMap, hoverList };
|
|
263
|
+
};
|
|
264
|
+
const addListeners = ({ api, state, vm }) => () => {
|
|
265
|
+
api.setListeners();
|
|
266
|
+
vm.$refs.canvas.addEventListener("mousemove", state.mousemoveListener);
|
|
267
|
+
vm.$refs.canvas.addEventListener("click", state.mousemoveListener);
|
|
268
|
+
vm.$refs.canvas.addEventListener("click", state.clickListener);
|
|
269
|
+
};
|
|
270
|
+
const removeListeners = ({ state, vm }) => () => {
|
|
271
|
+
vm.$refs.canvas.removeEventListener("mousemove", state.mousemoveListener);
|
|
272
|
+
vm.$refs.canvas.removeEventListener("click", state.mousemoveListener);
|
|
273
|
+
vm.$refs.canvas.removeEventListener("click", state.clickListener);
|
|
274
|
+
};
|
|
275
|
+
const setListeners = ({ api, emit, props, state, vm }) => () => {
|
|
276
|
+
const { config } = props;
|
|
277
|
+
const { delay } = config;
|
|
278
|
+
state.mousemoveListener = debounce(delay, (e) => {
|
|
279
|
+
const { left, top } = vm.$refs.canvas.getBoundingClientRect();
|
|
280
|
+
const { clientX, clientY } = e;
|
|
281
|
+
let x = clientX - left;
|
|
282
|
+
let y = clientY - top;
|
|
283
|
+
if (api.isMf() && state.afterData.graph && state.afterData.graph.thin) {
|
|
284
|
+
x *= state.afterData.graph.thinValue;
|
|
285
|
+
y *= state.afterData.graph.thinValue;
|
|
286
|
+
}
|
|
287
|
+
api.hitTest(x, y);
|
|
288
|
+
});
|
|
289
|
+
state.clickListener = debounce(delay, (e) => {
|
|
290
|
+
const afterLink = state.hoverAfterLink;
|
|
291
|
+
if (afterLink) {
|
|
292
|
+
emit("click-link", afterLink, e);
|
|
293
|
+
} else {
|
|
294
|
+
emit("click-blank", null, e);
|
|
295
|
+
}
|
|
296
|
+
api.clearDropdown();
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
const hitTest = ({ api, state, vm }) => (x, y) => {
|
|
300
|
+
const { afterData } = state;
|
|
301
|
+
const { hoverState } = afterData;
|
|
302
|
+
const { hoverMap, hoverList } = hoverState;
|
|
303
|
+
const pointInTriangle = (x0, y0, x1, y1, x2, y2, px, py) => {
|
|
304
|
+
const v0 = [x2 - x0, y2 - y0];
|
|
305
|
+
const v1 = [x1 - x0, y1 - y0];
|
|
306
|
+
const v2 = [px - x0, py - y0];
|
|
307
|
+
const dot00 = v0[0] * v0[0] + v0[1] * v0[1];
|
|
308
|
+
const dot01 = v0[0] * v1[0] + v0[1] * v1[1];
|
|
309
|
+
const dot02 = v0[0] * v2[0] + v0[1] * v2[1];
|
|
310
|
+
const dot11 = v1[0] * v1[0] + v1[1] * v1[1];
|
|
311
|
+
const dot12 = v1[0] * v2[0] + v1[1] * v2[1];
|
|
312
|
+
const inverDeno = 1 / (dot00 * dot11 - dot01 * dot01);
|
|
313
|
+
const u = (dot11 * dot02 - dot01 * dot12) * inverDeno;
|
|
314
|
+
if (u < 0 || u > 1) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
const v = (dot00 * dot12 - dot01 * dot02) * inverDeno;
|
|
318
|
+
if (v < 0 || v > 1) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
return u + v <= 1;
|
|
322
|
+
};
|
|
323
|
+
const tri = hoverList.find((item) => pointInTriangle(...item, x, y));
|
|
324
|
+
state.hoverAfterLink = tri ? hoverMap.get(tri) : null;
|
|
325
|
+
if (state.hoverAfterLink) {
|
|
326
|
+
api.drawAfterLink();
|
|
327
|
+
vm.$refs.canvas.style.cursor = "pointer";
|
|
328
|
+
} else {
|
|
329
|
+
api.clearHoverAfterLink();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const clearHoverAfterLink = ({ api, state, vm }) => () => {
|
|
333
|
+
if (state.hoverAfterLink) {
|
|
334
|
+
state.hoverAfterLink = null;
|
|
335
|
+
}
|
|
336
|
+
api.drawAfterLink();
|
|
337
|
+
if (vm.$refs.canvas.style.cursor) {
|
|
338
|
+
vm.$refs.canvas.style.cursor = "";
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const clickNode = ({ api, emit }) => (params, e) => {
|
|
342
|
+
const { node, afterNode } = params;
|
|
343
|
+
!api.isMf() && api.clearDropdown(node.name);
|
|
344
|
+
emit("click-node", afterNode, e);
|
|
345
|
+
};
|
|
346
|
+
const clearDropdown = (state) => (nodeName) => {
|
|
347
|
+
const { dropdowns } = state;
|
|
348
|
+
Object.keys(dropdowns).map((item) => {
|
|
349
|
+
if (dropdowns[item] && (nodeName && item !== nodeName || !nodeName)) {
|
|
350
|
+
dropdowns[item] = false;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
const computeMf = ({ api, markRaw, props, state }) => () => {
|
|
355
|
+
const { data, config } = props;
|
|
356
|
+
const { nodes, links } = hideNodeLink(data);
|
|
357
|
+
const { gap = 0, align = "", width = 0, height = 0, padding = 0 } = config;
|
|
358
|
+
const { prior = "", radius = 4, font, showArrow = true, lineWidth = 1, arrowEdge = 4 } = config;
|
|
359
|
+
const thin = false;
|
|
360
|
+
const getRow = buildGetRow(gap);
|
|
361
|
+
const getCol = buildGetCol(gap);
|
|
362
|
+
const rectRow = buildRectRow({ getRow, gap });
|
|
363
|
+
const rectNode = buildRectNode({ rectRow, gap, align, getRow });
|
|
364
|
+
const { afterNodes, graph } = buildAfterNodeGraph({ nodes, thin, getRow, getCol, rectNode, padding, width, height });
|
|
365
|
+
const { afterLinks, arrows } = buildAfterLinkArrow({
|
|
366
|
+
links,
|
|
367
|
+
afterNodes,
|
|
368
|
+
graph,
|
|
369
|
+
prior,
|
|
370
|
+
radius,
|
|
371
|
+
showArrow,
|
|
372
|
+
lineWidth,
|
|
373
|
+
arrowEdge
|
|
374
|
+
});
|
|
375
|
+
const hoverState = api.buildHoverState(afterLinks);
|
|
376
|
+
state.afterData = markRaw({ afterNodes, afterLinks, hoverState, graph, arrows });
|
|
377
|
+
state.wrapperStyle = `width:${graph.width}px;height:${graph.height}px;font:${font}`;
|
|
378
|
+
};
|
|
379
|
+
const isMf = (mode) => () => mode === "mobile-first";
|
|
380
|
+
const getNodeDef = (node, type) => {
|
|
381
|
+
const shape = node.info.shape || "circle";
|
|
382
|
+
if (shape === "circle")
|
|
383
|
+
return 40;
|
|
384
|
+
if (shape === "rectangle") {
|
|
385
|
+
if (type === "width")
|
|
386
|
+
return 160;
|
|
387
|
+
if (type === "height")
|
|
388
|
+
return 56;
|
|
389
|
+
}
|
|
390
|
+
return 0;
|
|
391
|
+
};
|
|
392
|
+
const getNode = (node, type) => {
|
|
393
|
+
const shape = node.info.shape || "circle";
|
|
394
|
+
if (shape === "circle") {
|
|
395
|
+
return node.info.width || getNodeDef(node, type);
|
|
396
|
+
}
|
|
397
|
+
if (shape === "rectangle") {
|
|
398
|
+
return node.info[type] || getNodeDef(node, type);
|
|
399
|
+
}
|
|
400
|
+
return 0;
|
|
401
|
+
};
|
|
402
|
+
const buildGetRow = (gap) => (afterNodes, row, type) => {
|
|
403
|
+
const rowAfterNodes = afterNodes.filter((afterNode) => afterNode.row === row);
|
|
404
|
+
const rowNodes = rowAfterNodes.map((rowAfterNode) => rowAfterNode.raw);
|
|
405
|
+
if (rowNodes.length > 0) {
|
|
406
|
+
if (type === "width") {
|
|
407
|
+
return rowNodes.reduce((p, c) => p + getNode(c, type), 0) + (rowNodes.length - 1) * gap;
|
|
408
|
+
}
|
|
409
|
+
if (type === "height") {
|
|
410
|
+
return Math.max(...rowNodes.map((rowNode) => getNode(rowNode, type)));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return 0;
|
|
414
|
+
};
|
|
415
|
+
const buildGetCol = (gap) => (afterNodes, col, type) => {
|
|
416
|
+
const colAfterNodes = afterNodes.filter((afterNode) => afterNode.col === col);
|
|
417
|
+
const colNodes = colAfterNodes.map((colAfterNode) => colAfterNode.raw);
|
|
418
|
+
if (colNodes.length > 0) {
|
|
419
|
+
if (type === "width") {
|
|
420
|
+
return Math.max(...colNodes.map((colNode) => getNode(colNode, type)));
|
|
421
|
+
}
|
|
422
|
+
if (type === "height") {
|
|
423
|
+
return colNodes.reduce((p, c) => p + getNode(c, type), 0) + (colNodes.length - 1) * gap;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return 0;
|
|
427
|
+
};
|
|
428
|
+
const buildRectRow = ({ getRow, gap }) => (afterNodes, row, graph) => {
|
|
429
|
+
const accrueRowHeight = Array.from({ length: row }).map((c, i) => i).map((i) => getRow(afterNodes, i, "height")).reduce((p, c) => p + c, 0);
|
|
430
|
+
const accrueGapHeight = row > 0 ? row * gap : 0;
|
|
431
|
+
return {
|
|
432
|
+
x: 0,
|
|
433
|
+
y: accrueRowHeight + accrueGapHeight,
|
|
434
|
+
width: graph.width,
|
|
435
|
+
height: getRow(afterNodes, row, "height")
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
const buildRectNode = ({ rectRow, gap, align, getRow }) => (afterNode, afterNodes, graph) => {
|
|
439
|
+
const { row, col } = afterNode;
|
|
440
|
+
const prevRowRect = rectRow(afterNodes, row - 1, graph);
|
|
441
|
+
const rowRect = rectRow(afterNodes, row, graph);
|
|
442
|
+
const width = getNode(afterNode.raw, "width");
|
|
443
|
+
const height = getNode(afterNode.raw, "height");
|
|
444
|
+
const y = prevRowRect.y + prevRowRect.height + (row > 0 ? gap : 0) + (rowRect.height - height) / 2;
|
|
445
|
+
const rowAfterNodes = afterNodes.filter((afterNode2) => afterNode2.row === row);
|
|
446
|
+
const get = (i) => rowAfterNodes.find((rowAfterNode) => rowAfterNode.col === i);
|
|
447
|
+
const accrueColWidth = Array.from({ length: col }).map((c, i) => i).map((i) => {
|
|
448
|
+
const afterNode2 = get(i);
|
|
449
|
+
return afterNode2 ? getNode(afterNode2.raw, "width") : 0;
|
|
450
|
+
}).reduce((p, c) => p + c, 0);
|
|
451
|
+
const accrueGapWidth = col > 0 ? col * gap : 0;
|
|
452
|
+
const dx = align === "center" ? (graph.width - getRow(afterNodes, row, "width")) / 2 : 0;
|
|
453
|
+
const x = accrueColWidth + accrueGapWidth + dx;
|
|
454
|
+
return { x, y, width, height };
|
|
455
|
+
};
|
|
456
|
+
const normalRowCol = (nodes) => {
|
|
457
|
+
let rows = /* @__PURE__ */ new Set();
|
|
458
|
+
const rowMap = /* @__PURE__ */ new Map();
|
|
459
|
+
nodes.forEach((node) => !rows.has(node.info.row) && rows.add(node.info.row));
|
|
460
|
+
rows = [...rows].sort((a, b) => a - b);
|
|
461
|
+
rows.forEach((row, i) => rowMap.set(row, i));
|
|
462
|
+
const afterNodes = nodes.map((node) => {
|
|
463
|
+
return { type: "node", row: rowMap.get(node.info.row), col: 0, raw: node };
|
|
464
|
+
});
|
|
465
|
+
rows.forEach((r, row) => {
|
|
466
|
+
const rowAfterNodes = afterNodes.filter((afterNode) => afterNode.row === row);
|
|
467
|
+
let cols = rowAfterNodes.map((rowAfterNode) => rowAfterNode.raw).map((node) => node.info.col);
|
|
468
|
+
const colMap = /* @__PURE__ */ new Map();
|
|
469
|
+
cols = new Set(cols);
|
|
470
|
+
cols = [...cols].sort((a, b) => a - b);
|
|
471
|
+
cols.forEach((col, i) => colMap.set(col, i));
|
|
472
|
+
rowAfterNodes.forEach((rowAfterNode) => rowAfterNode.col = colMap.get(rowAfterNode.raw.info.col));
|
|
473
|
+
});
|
|
474
|
+
return afterNodes;
|
|
475
|
+
};
|
|
476
|
+
const buildAfterNodeGraph = ({ nodes, thin, getRow, getCol, rectNode, padding, width, height }) => {
|
|
477
|
+
const afterNodes = normalRowCol(nodes);
|
|
478
|
+
const maxRow = Math.max(...afterNodes.map((afterNode) => afterNode.row));
|
|
479
|
+
const maxCol = Math.max(...afterNodes.map((afterNode) => afterNode.col));
|
|
480
|
+
const graph = { width: 0, height: 0, thin, thinValue: 1 };
|
|
481
|
+
for (let i = 0; i <= maxRow; i++) {
|
|
482
|
+
const tmp = getRow(afterNodes, i, "width");
|
|
483
|
+
tmp > graph.width && (graph.width = tmp);
|
|
484
|
+
}
|
|
485
|
+
for (let i = 0; i <= maxCol; i++) {
|
|
486
|
+
const tmp = getCol(afterNodes, i, "height");
|
|
487
|
+
tmp > graph.height && (graph.height = tmp);
|
|
488
|
+
}
|
|
489
|
+
afterNodes.forEach((afterNode) => Object.assign(afterNode, rectNode(afterNode, afterNodes, graph)));
|
|
490
|
+
if (padding > 0) {
|
|
491
|
+
graph.width += 2 * padding;
|
|
492
|
+
graph.height += 2 * padding;
|
|
493
|
+
afterNodes.forEach((afterNode) => {
|
|
494
|
+
afterNode.x += padding;
|
|
495
|
+
afterNode.y += padding;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
let dx = 0;
|
|
499
|
+
let dy = 0;
|
|
500
|
+
if (width > graph.width) {
|
|
501
|
+
dx = (width - graph.width) / 2;
|
|
502
|
+
graph.width = width;
|
|
503
|
+
afterNodes.forEach((afterNode) => afterNode.x += dx);
|
|
504
|
+
}
|
|
505
|
+
if (height > graph.height) {
|
|
506
|
+
dy = (height - graph.height) / 2;
|
|
507
|
+
graph.height = height;
|
|
508
|
+
afterNodes.forEach((afterNode) => afterNode.y += dy);
|
|
509
|
+
}
|
|
510
|
+
return { afterNodes, graph };
|
|
511
|
+
};
|
|
512
|
+
const adjustLine = ({ lineWidth }) => (f, t) => {
|
|
513
|
+
const dpr = window.devicePixelRatio;
|
|
514
|
+
const isOdd = lineWidth & 1;
|
|
515
|
+
const dx = Math.abs(f.x - t.x);
|
|
516
|
+
const isVertical = dx < Number.EPSILON;
|
|
517
|
+
if (isOdd) {
|
|
518
|
+
if (isVertical) {
|
|
519
|
+
f.x = t.x = Math.floor(f.x) + 0.5 / dpr;
|
|
520
|
+
} else {
|
|
521
|
+
f.y = t.y = Math.floor(f.y) + 0.5 / dpr;
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
if (isVertical) {
|
|
525
|
+
f.x = t.x = Math.floor(f.x);
|
|
526
|
+
} else {
|
|
527
|
+
f.y = t.y = Math.floor(f.y);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const buildAfterLinkArrow = ({ links, afterNodes, graph, prior, radius, showArrow, lineWidth, arrowEdge }) => {
|
|
532
|
+
const arrows = [];
|
|
533
|
+
const buildArrow = getBuildArrow({ arrows, arrowEdge });
|
|
534
|
+
const adjust = adjustLine({ lineWidth });
|
|
535
|
+
const afterLinks = links.map((link) => {
|
|
536
|
+
const { from, to, fromJoint = "bottom", toJoint = "top" } = link;
|
|
537
|
+
const fromAfterNode = afterNodes.find((afterNode) => afterNode.raw.name === from);
|
|
538
|
+
const toAfterNode = afterNodes.find((afterNode) => afterNode.raw.name === to);
|
|
539
|
+
const f = point(fromAfterNode, fromJoint, graph);
|
|
540
|
+
const t = point(toAfterNode, toJoint, graph);
|
|
541
|
+
const p = [];
|
|
542
|
+
const dx = Math.abs(f.x - t.x);
|
|
543
|
+
const dy = Math.abs(f.y - t.y);
|
|
544
|
+
if (dx < Number.EPSILON || dy < Number.EPSILON) {
|
|
545
|
+
adjust(f, t);
|
|
546
|
+
p.push(`m,${f.x},${f.y}`);
|
|
547
|
+
p.push(`l,${t.x},${t.y}`);
|
|
548
|
+
showArrow && buildArrow([f.x, f.y], [t.x, t.y], link);
|
|
549
|
+
} else {
|
|
550
|
+
const mid = [(f.x + t.x) / 2, (f.y + t.y) / 2];
|
|
551
|
+
if (!prior || prior === "vertical") {
|
|
552
|
+
const tmp0 = { x: f.x, y: mid[1] };
|
|
553
|
+
const tmp1 = { x: t.x, y: mid[1] };
|
|
554
|
+
adjust(f, tmp0);
|
|
555
|
+
adjust(tmp0, tmp1);
|
|
556
|
+
adjust(tmp1, t);
|
|
557
|
+
mid[1] = tmp0.y;
|
|
558
|
+
p.push(`m,${f.x},${f.y}`);
|
|
559
|
+
p.push(`a,${f.x},${mid[1]},${mid[0]},${mid[1]},${radius}`);
|
|
560
|
+
p.push(`a,${t.x},${mid[1]},${t.x},${t.y},${radius}`);
|
|
561
|
+
p.push(`l,${t.x},${t.y}`);
|
|
562
|
+
showArrow && buildArrow([t.x, mid[1]], [t.x, t.y], link);
|
|
563
|
+
} else if (prior === "horizontal") {
|
|
564
|
+
const tmp0 = { x: mid[0], y: f.y };
|
|
565
|
+
const tmp1 = { x: mid[0], y: t.y };
|
|
566
|
+
adjust(f, tmp0);
|
|
567
|
+
adjust(tmp0, tmp1);
|
|
568
|
+
adjust(tmp1, t);
|
|
569
|
+
mid[0] = tmp0.x;
|
|
570
|
+
p.push(`m,${f.x},${f.y}`);
|
|
571
|
+
p.push(`a,${mid[0]},${f.y},${mid[0]},${mid[1]},${radius}`);
|
|
572
|
+
p.push(`a,${mid[0]},${t.y},${t.x},${t.y},${radius}`);
|
|
573
|
+
p.push(`l,${t.x},${t.y}`);
|
|
574
|
+
showArrow && buildArrow([mid[0], t.y], [t.x, t.y], link);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return { type: "link", f, t, p, raw: link };
|
|
578
|
+
});
|
|
579
|
+
return { afterLinks, arrows };
|
|
580
|
+
};
|
|
581
|
+
const point = (afterNode, joint, graph) => {
|
|
582
|
+
const exp = /^(bottom|top|left|right)$/;
|
|
583
|
+
const variant = /^(bottom|top|left|right)-(\d+)\/(\d+)$/;
|
|
584
|
+
const res = { x: 0, y: 0 };
|
|
585
|
+
if (exp.test(joint)) {
|
|
586
|
+
if (joint === "bottom") {
|
|
587
|
+
res.x = afterNode.x + afterNode.width / 2;
|
|
588
|
+
res.y = afterNode.y + afterNode.height;
|
|
589
|
+
} else if (joint === "top") {
|
|
590
|
+
res.x = afterNode.x + afterNode.width / 2;
|
|
591
|
+
res.y = afterNode.y;
|
|
592
|
+
} else if (joint === "left") {
|
|
593
|
+
res.x = afterNode.x;
|
|
594
|
+
res.y = afterNode.y + afterNode.height / 2;
|
|
595
|
+
} else if (joint === "right") {
|
|
596
|
+
res.x = afterNode.x + afterNode.width;
|
|
597
|
+
res.y = afterNode.y + afterNode.height / 2;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
if (variant.test(joint)) {
|
|
601
|
+
const m = variant.exec(joint).slice(1);
|
|
602
|
+
m[1] = parseFloat(m[1]);
|
|
603
|
+
m[2] = parseFloat(m[2]);
|
|
604
|
+
if (m[0] === "bottom") {
|
|
605
|
+
res.x = afterNode.x + (m[1] - 0.5) * afterNode.width / m[2];
|
|
606
|
+
res.y = afterNode.y + afterNode.height;
|
|
607
|
+
} else if (m[0] === "top") {
|
|
608
|
+
res.x = afterNode.x + (m[1] - 0.5) * afterNode.width / m[2];
|
|
609
|
+
res.y = afterNode.y;
|
|
610
|
+
} else if (m[0] === "left") {
|
|
611
|
+
res.x = afterNode.x;
|
|
612
|
+
res.y = afterNode.y + (m[1] - 0.5) * afterNode.height / m[2];
|
|
613
|
+
} else if (m[0] === "right") {
|
|
614
|
+
res.x = afterNode.x + afterNode.width;
|
|
615
|
+
res.y = afterNode.y + (m[1] - 0.5) * afterNode.height / m[2];
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (graph.thin) {
|
|
619
|
+
res.x *= graph.thinValue;
|
|
620
|
+
res.y *= graph.thinValue;
|
|
621
|
+
}
|
|
622
|
+
return res;
|
|
623
|
+
};
|
|
624
|
+
const getBuildArrow = ({ arrows, arrowEdge }) => (from, to, link) => {
|
|
625
|
+
const p0 = [0, 0];
|
|
626
|
+
const p2 = [0, 0];
|
|
627
|
+
const dx = from[0] - to[0];
|
|
628
|
+
const dy = from[1] - to[1];
|
|
629
|
+
const absx = Math.abs(dx);
|
|
630
|
+
const absy = Math.abs(dy);
|
|
631
|
+
let t = 1;
|
|
632
|
+
const edge = arrowEdge;
|
|
633
|
+
if (absx < Number.EPSILON) {
|
|
634
|
+
t = dy > 0 ? 1 : dy < 0 ? -1 : 1;
|
|
635
|
+
p0[0] = to[0] - edge;
|
|
636
|
+
p0[1] = to[1] + Math.sqrt(3) * edge * t;
|
|
637
|
+
p2[0] = to[0] + edge;
|
|
638
|
+
p2[1] = p0[1];
|
|
639
|
+
if (dy !== 0) {
|
|
640
|
+
arrows.push({ p0, p1: to, p2, link });
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (absy < Number.EPSILON) {
|
|
644
|
+
t = dx > 0 ? 1 : dx < 0 ? -1 : 1;
|
|
645
|
+
p0[0] = to[0] + Math.sqrt(3) * edge * t;
|
|
646
|
+
p0[1] = to[1] - edge;
|
|
647
|
+
p2[0] = p0[0];
|
|
648
|
+
p2[1] = to[1] + edge;
|
|
649
|
+
if (dx !== 0) {
|
|
650
|
+
arrows.push({ p0, p1: to, p2, link });
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
const hideNodeLink = (data) => {
|
|
655
|
+
let { nodes, links } = data;
|
|
656
|
+
const hiddenNodeNames = nodes.filter((node) => node.hidden === true).map((node) => node.name);
|
|
657
|
+
nodes = nodes.filter((node) => node.hidden !== true);
|
|
658
|
+
links = links.filter((link) => !~hiddenNodeNames.indexOf(link.from) && !~hiddenNodeNames.indexOf(link.to));
|
|
659
|
+
return { nodes, links };
|
|
660
|
+
};
|
|
661
|
+
const drawArrow = ({ state, vm, props }) => () => {
|
|
662
|
+
const { $refs } = vm;
|
|
663
|
+
const { config } = props;
|
|
664
|
+
const { showArrow = true } = config;
|
|
665
|
+
const { afterData } = state;
|
|
666
|
+
const { arrows } = afterData;
|
|
667
|
+
if (showArrow && $refs.canvas && $refs.canvas.getContext) {
|
|
668
|
+
const ctx = $refs.canvas.getContext("2d");
|
|
669
|
+
if (ctx) {
|
|
670
|
+
ctx.save();
|
|
671
|
+
arrows.forEach((arrow) => {
|
|
672
|
+
ctx.beginPath();
|
|
673
|
+
ctx.moveTo(...arrow.p0);
|
|
674
|
+
ctx.lineTo(...arrow.p1);
|
|
675
|
+
ctx.lineTo(...arrow.p2);
|
|
676
|
+
ctx.closePath();
|
|
677
|
+
ctx.fillStyle = config.colors[arrow.link.info.status];
|
|
678
|
+
ctx.fill();
|
|
679
|
+
});
|
|
680
|
+
ctx.restore();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const antialiasing = (vm) => () => {
|
|
685
|
+
const canvas = vm.$refs.canvas;
|
|
686
|
+
const context = canvas.getContext("2d");
|
|
687
|
+
const width = canvas.width;
|
|
688
|
+
const height = canvas.height;
|
|
689
|
+
let dpr = window.devicePixelRatio;
|
|
690
|
+
if (dpr) {
|
|
691
|
+
canvas.style.width = width + "px";
|
|
692
|
+
canvas.style.height = height + "px";
|
|
693
|
+
canvas.height = height * dpr;
|
|
694
|
+
canvas.width = width * dpr;
|
|
695
|
+
context.scale(dpr, dpr);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
export {
|
|
699
|
+
addListeners,
|
|
700
|
+
antialiasing,
|
|
701
|
+
buildAfterLink,
|
|
702
|
+
buildAfterNode,
|
|
703
|
+
buildHoverState,
|
|
704
|
+
clearDropdown,
|
|
705
|
+
clearHoverAfterLink,
|
|
706
|
+
clickNode,
|
|
707
|
+
compute,
|
|
708
|
+
computeMf,
|
|
709
|
+
drawAfterLink,
|
|
710
|
+
drawArrow,
|
|
711
|
+
getAllItem,
|
|
712
|
+
getVars,
|
|
713
|
+
hitTest,
|
|
714
|
+
initDropdowns,
|
|
715
|
+
isLinkHover,
|
|
716
|
+
isMf,
|
|
717
|
+
omitText,
|
|
718
|
+
refresh,
|
|
719
|
+
removeListeners,
|
|
720
|
+
setListeners
|
|
721
|
+
};
|