@daoyi/nmtl-ui 2.0.1-beta.44 → 2.0.1-beta.46

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.
Files changed (93) hide show
  1. package/lib/components/Autocomplete-aa4a8d6c.js +335 -0
  2. package/lib/components/Autocomplete.js +13 -1
  3. package/lib/components/Avatar.js +49 -1
  4. package/lib/components/BackTop.js +109 -1
  5. package/lib/components/BarChart.js +762 -1
  6. package/lib/components/Breadcrumbs.js +122 -1
  7. package/lib/components/Button-2f8f0493.js +92 -0
  8. package/lib/components/Button.js +6 -1
  9. package/lib/components/Carousel.js +4713 -1
  10. package/lib/components/Checkbox.js +37 -1
  11. package/lib/components/CollapseContent.js +179 -1
  12. package/lib/components/ContactModal-c8240b19.js +10759 -0
  13. package/lib/components/ContactModal.js +22 -1
  14. package/lib/components/Drawer-dd8942f1.js +157 -0
  15. package/lib/components/Drawer.js +11 -1
  16. package/lib/components/Dropdown.js +134 -1
  17. package/lib/components/Empty-3637b766.js +45 -0
  18. package/lib/components/Empty.js +5 -1
  19. package/lib/components/ExportButton.js +112 -1
  20. package/lib/components/ExtraTools-55dad795.js +3479 -0
  21. package/lib/components/ExtraTools.js +10 -1
  22. package/lib/components/Filter.js +776 -1
  23. package/lib/components/Footer.js +271 -1
  24. package/lib/components/ForwardLink.js +105 -1
  25. package/lib/components/Header.js +187 -1
  26. package/lib/components/Image.js +61 -1
  27. package/lib/components/Input.js +77 -1
  28. package/lib/components/InputMethod.js +33963 -1
  29. package/lib/components/KeywordSearch-2d01266e.js +139 -0
  30. package/lib/components/KeywordSearch.js +15 -1
  31. package/lib/components/KeywordTicker.js +180 -1
  32. package/lib/components/Keywords.js +317 -1
  33. package/lib/components/Loading.js +28 -1
  34. package/lib/components/MUITheme.js +2627 -1
  35. package/lib/components/Modal-572e17ea.js +108 -0
  36. package/lib/components/Modal.js +9 -1
  37. package/lib/components/MoreButton-80996b5f.js +110 -0
  38. package/lib/components/MoreButton.js +6 -1
  39. package/lib/components/Radio.js +78 -1
  40. package/lib/components/SNA.js +1735 -1
  41. package/lib/components/Select-5533b506.js +115 -0
  42. package/lib/components/Select.js +8 -1
  43. package/lib/components/Spin-ebf79c17.js +75 -0
  44. package/lib/components/Spin.js +6 -1
  45. package/lib/components/Table.js +51 -1
  46. package/lib/components/Tooltip-907eaa2e.js +70 -0
  47. package/lib/components/Tooltip.js +7 -1
  48. package/lib/components/_commonjsHelpers-70de2c37.js +28 -0
  49. package/lib/components/_rollupPluginBabelHelpers-fde6d1c6.js +491 -1
  50. package/lib/components/createSvgIcon-48da8b6e.js +576 -0
  51. package/lib/components/dataExport-d55d6fa3.js +92 -0
  52. package/lib/components/debounce-127da66c.js +355 -0
  53. package/lib/components/defaultTheme-19a14721.js +1485 -0
  54. package/lib/components/globalConfig-40069b54.js +158 -0
  55. package/lib/components/hoist-non-react-statics.cjs-3f408ad2.js +105 -0
  56. package/lib/components/index-7b60a97d.js +481 -0
  57. package/lib/components/index-f491ebce.js +61 -0
  58. package/lib/components/isObjectLike-e111475d.js +190 -0
  59. package/lib/components/style-inject.es-1f59c1d0.js +28 -0
  60. package/lib/components/transform-3a04288b.js +5475 -0
  61. package/lib/globalConfig.js +186 -1
  62. package/lib/utils/_rollupPluginBabelHelpers-a6e0e6e3.js +139 -1
  63. package/lib/utils/arrayMerge.js +100 -1
  64. package/lib/utils/chunkArray.js +15 -1
  65. package/lib/utils/convert2HtmlEntities.js +42 -1
  66. package/lib/utils/domToImage.js +802 -1
  67. package/lib/utils/downloadGephi.js +106 -1
  68. package/lib/utils/exportXlsx.js +219 -1
  69. package/lib/utils/historyAppendSearch.js +502 -1
  70. package/lib/utils/isDevelopMode.js +5 -1
  71. package/lib/utils/parseYMD.js +36 -1
  72. package/lib/utils/removeDuplicateItem.js +11 -1
  73. package/lib/utils/sendEmail.js +39 -1
  74. package/lib/utils/snaDefine-6a2bcd94.js +5 -1
  75. package/lib/utils/snaDefine.js +1 -1
  76. package/lib/utils/snaPreProcess.js +84 -1
  77. package/package.json +1 -1
  78. package/lib/components/Autocomplete-5439ff22.js +0 -1
  79. package/lib/components/Button-63c7e9f3.js +0 -1
  80. package/lib/components/ContactModal-d852ae32.js +0 -1
  81. package/lib/components/Drawer-af3ed21a.js +0 -1
  82. package/lib/components/Empty-70f040a9.js +0 -1
  83. package/lib/components/ExtraTools-f10a66a8.js +0 -1
  84. package/lib/components/KeywordSearch-224f84c1.js +0 -1
  85. package/lib/components/Modal-a7591b98.js +0 -1
  86. package/lib/components/MoreButton-f15ca38e.js +0 -1
  87. package/lib/components/Select-98a8e973.js +0 -1
  88. package/lib/components/Spin-690a3597.js +0 -1
  89. package/lib/components/Tooltip-b7eb966d.js +0 -1
  90. package/lib/components/dataExport-f418e6fe.js +0 -1
  91. package/lib/components/globalConfig-63dfbe94.js +0 -1
  92. package/lib/components/vendor-851c6356.js +0 -63
  93. package/lib/utils/vendor-3ec75cc9.js +0 -1
@@ -1 +1,1735 @@
1
- import t,{useMemo as e,useEffect as n}from"react";import r from"prop-types";import{e as a,s as o,c as i,o as c,g as l,h as s,l as d,m as f,i as p,j as u,x as h,y as g,r as m,k as y,z as x,n as w,p as N}from"./vendor-851c6356.js";import{E as v}from"./ExtraTools-f10a66a8.js";import{Tooltip as k,IconButton as b}from"@material-ui/core";import"react-is";import"@material-ui/styles";import"react-dom";import"./_rollupPluginBabelHelpers-fde6d1c6.js";import"./Tooltip-b7eb966d.js";import"./dataExport-f418e6fe.js";const A=e=>{let{renderSNA:n}=e;return t.createElement("div",{id:"resetBtn"},t.createElement(k,{title:"回到原來位置與大小"},t.createElement(b,{onClick:()=>n()},t.createElement(a,null))))};A.propTypes={renderSNA:r.func.isRequired};o(".SNA {\n overflow: hidden;\n object-fit: contain;\n position: relative;\n font-size: 0.75rem;\n width: 100%; }\n .SNA--smallSize .node {\n padding-top: 8px;\n font-size: 0.75rem;\n width: 3rem;\n height: 3rem;\n overflow: hidden;\n white-space: pre-wrap;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical; }\n .SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 20px;\n font-weight: 500;\n height: 54px;\n width: 54px;\n padding-top: 15px;\n position: absolute;\n text-align: center;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: grab; }\n .SNA .links line {\n stroke: #c7bfb4;\n stroke-width: 2; }\n .SNA .mainNode {\n fill: #4e3a16; }\n .SNA .person {\n fill: #867b3a; }\n .SNA .publication {\n fill: #825c0d; }\n .SNA .article {\n fill: #afafaf; }\n .SNA .keyword {\n fill: #fcfae8; }\n .SNA .org {\n fill: #000000; }\n .SNA #resetBtn {\n float: right; }\n .SNA #network-graph svg {\n width: 100%;\n height: 100%; }\n\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px; }\n .SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 1px;\n font-weight: 500;\n height: 44px;\n width: 44px;\n padding-top: 12px;\n position: absolute;\n text-align: center;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: grab; } }\n\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px; } }\n");var S=function(r){var a,o=r.className,k=r.intl,b=r.exclude,S=r.distance,E=r.SNAData,C=r.handleClickNodeGoto,M=r.DownloadExcel,j=r.width,z=r.height,D=r.fontColor,T=r.backgroundColor,F=r.iconColor;if(!E||0===E.nodes.length)return t.createElement("div",{className:"noData"},k?k.formatMessage({id:"common.noData"}):"暫無資料");var O=e((function(){return screen.width>1050?j:screen.width-80}),[screen.width]),B=e((function(){return screen.width>1050?z:screen.height-300}),[screen.width]),q=function(t,e,n){var r=function(t,e,n){var r=.5*(e.x+t.x),a=.5*(e.y+t.y),o=e.x-t.x,i=e.y-t.y,c=Math.pow(Math.pow(o,2)+Math.pow(i,2),.5);return{qx:r-i*n/c,qy:a+o*n/c}}(t,e,n),a=r.qx,o=r.qy;return isNaN(a)?"M".concat(t.x,", ").concat(t.y," Q0 0 ").concat(e.x," ").concat(e.y):"M".concat(t.x,", ").concat(t.y," Q").concat(a," ").concat(o," ").concat(e.x," ").concat(e.y)},I=function(t){var e=8.5,n="-0 -".concat(e," ").concat(17," ").concat(17),r="M 0,-".concat(6.800000000000001," L ").concat(13.600000000000001," ,0 L 0,").concat(6.800000000000001),o=c(l),i=t.links.map((function(t){return Object.create(t)})),v=t.nodes.map((function(t){return Object.create(t)})),b=s(v).force("link",d(i).id((function(t){return t.index})).distance(50)).force("charge",f().strength(-200).distanceMax(1e3)).force("center",p(O/2,B/2)).force("collide",u().radius((function(){return 13.5})).strength(1).iterations(10)).force("x",h(O/2)).force("y",g(B/2)).force("radial",m(100,O/1.5,B/1.5)),A=y("#sna-graph").append("svg").attr("viewBox",[0,0,O,B]).style("background-color",T);A.append("defs").append("marker").attr("id","arrowhead").attr("viewBox",n).attr("refX",23.8).attr("refY",0).attr("orient","auto").attr("markerWidth",15.3).attr("markerHeight",15.3).attr("xoverflow","visible").append("svg:path").attr("d",r).attr("fill","#999").style("stroke","none"),a=A.append("g");x().scaleExtent([.5,20]).extent([[0,0],[O,B]]).on("zoom",(function(){a.attr("transform",N.transform)}))(A);var S=a.append("g").attr("stroke","#999").attr("stroke-opacity",.6).selectAll("line").data(i).join("path").attr("fill","none").attr("stroke-dasharray",(function(t){return"protege"===t.ontology?"2,5,3":""})).attr("key",(function(t){return t.type})),E=a.append("g").attr("stroke","#fff").attr("stroke-width",1.5).selectAll("circle").data(v).join("circle").attr("r",(function(t){return"mainNode"===t.type?13.5:e})).attr("fill",(function(t){return o(t.type)})).attr("key",(function(t){return t.type})).attr("class",(function(t){return"node node-".concat(t.id," ").concat(t.type&&"organization"===t.type?"org":"person"===t.type?"person":"publication"===t.type?"publication":"mainNode"===t.type?"mainNode":"article"===t.type?"article":"keyword"===t.type?"keyword":"event"===t.type?"event":"")})).on("click",(function(t){return t.hasClick?C({name:t.name,id:t.id,type:t.type}):null})).call(function(t){return w().on("start",(function(e){N.active||t.alphaTarget(.3).restart(),e.fx=e.x,e.fy=e.y})).on("drag",(function(t){t.fx=N.x>O-10||N.x<20?t.x:N.x,t.fy=N.y>B-10||N.y<20?t.y:N.y}))}(b));E.append("title").text((function(t){return"".concat(t.name,"-").concat(function(t){switch(t){case"mainNode":return k?k.formatMessage({id:"SNA.search.center"}):"主要搜尋中心";case"organization":return k?k.formatMessage({id:"SNA.organization"}):"組織";case"person":return k?k.formatMessage({id:"SNA.author"}):"作家";case"publication":return k?k.formatMessage({id:"SNA.publication"}):"作家";case"article":return k?k.formatMessage({id:"SNA.article"}):"單篇作品";case"keyword":return k?k.formatMessage({id:"SNA.keyword"}):"關鍵字";case"event":return k?k.formatMessage({id:"SNA.event"}):"事件";default:return""}}(t.type))}));var M=a.append("g").selectAll("text").data(v).join("text").attr("fill",D).attr("text-anchor","middle").attr("key",(function(t){return t.type})).style("color","#fff").style("font-size","14px").text((function(t){return t.name})),j=a.selectAll(".edgepath").data(i).enter().append("path").attr("class","edgepath").attr("fill-opacity",0).attr("stroke-opacity",0).attr("id",(function(t,e){return"edgepath".concat(e)})).style("pointer-events","none");a.selectAll(".edgelabel").data(i).enter().append("text").style("pointer-events","none").attr("class","edgelabel").attr("font-size","10px").attr("fill","#aaa").attr("visibility","visible").attr("key",(function(t){return t.type})).attr("id",(function(t,e){return"edgelabel".concat(e)})).append("textPath").attr("xlink:href",(function(t,e){return"#edgepath".concat(e)})).style("text-anchor","middle").style("pointer-events","none").attr("startOffset","50%").text((function(t){return t.property})),b.on("tick",(function(){v.forEach((function(t){t.x>=O-20&&(t.x=O-20),t.y>=B-20&&(t.y=B-20),t.x<=20&&(t.x=20),t.y<=20&&(t.y=20)})),S.attr("d",(function(t){return q(t.source,t.target,30)})),E.attr("cx",(function(t){return t.x})).attr("cy",(function(t){return t.y})),M.attr("x",(function(t){return t.x})).attr("y",(function(t){return t.y-e})),j.attr("d",(function(t){return q(t.source,t.target,30)}))}))},G=function(){if(E&&E.nodes&&E.nodes.length>0){var t=document.getElementById("sna-graph");t&&t.childNodes[0]&&t.removeChild(t.childNodes[0]),I(E)}};return n((function(){G()}),[E]),t.createElement("div",{className:i("SNA",{"SNA--smallSize":S<200},o),style:{contentWidth:O,contentHeight:B,backgroundColor:T}},t.createElement(v,{intl:k,data:E,iconColor:F,domToImageId:"sna-graph",FontSizeTargets:["#sna-graph svg g text"],exclude:b,DownloadExcel:M,fullscreenDomId:"sna-graph"}),t.createElement(A,{renderSNA:G}),t.createElement("div",{id:"sna-graph"}))};S.defaultProps={className:void 0,intl:void 0,width:1050,height:600,distance:400,SNAData:null,fontColor:"#000000",backgroundColor:"#FFFFFF",iconColor:"#825c0d",exclude:["downloadXls","downloadTsv"],handleClickNodeGoto:null,DownloadExcel:void 0},S.propTypes={className:r.string,intl:r.objectOf(r.any),width:r.number,height:r.number,distance:r.number,SNAData:r.objectOf(r.any),fontColor:r.string,backgroundColor:r.string,iconColor:r.string,exclude:r.arrayOf(r.string),handleClickNodeGoto:r.func,DownloadExcel:r.oneOfType([r.node,r.func])};export{S as default};
1
+ import React__default, { useMemo, useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { c as classNames } from './index-f491ebce.js';
4
+ import { e as event, d as d3Select, a as dispatch, c as customEvent, D as DragEvent, q as quadtree, m as map, t as timer, T as Transform, i as identity, b as interrupt, o as ordinal, f as category10 } from './transform-3a04288b.js';
5
+ import { E as ExtraTools } from './ExtraTools-55dad795.js';
6
+ import { Tooltip, IconButton } from '@material-ui/core';
7
+ import { r as requireCreateSvgIcon, i as interopRequireDefault, a as interopRequireWildcard } from './createSvgIcon-48da8b6e.js';
8
+ import { s as styleInject } from './style-inject.es-1f59c1d0.js';
9
+ import './_rollupPluginBabelHelpers-fde6d1c6.js';
10
+ import './_commonjsHelpers-70de2c37.js';
11
+ import './Tooltip-907eaa2e.js';
12
+ import './dataExport-d55d6fa3.js';
13
+ import './defaultTheme-19a14721.js';
14
+ import 'react-is';
15
+ import '@material-ui/styles';
16
+ import 'react-dom';
17
+
18
+ function sourceEvent() {
19
+ var current = event, source;
20
+ while (source = current.sourceEvent) current = source;
21
+ return current;
22
+ }
23
+
24
+ function point(node, event) {
25
+ var svg = node.ownerSVGElement || node;
26
+
27
+ if (svg.createSVGPoint) {
28
+ var point = svg.createSVGPoint();
29
+ point.x = event.clientX, point.y = event.clientY;
30
+ point = point.matrixTransform(node.getScreenCTM().inverse());
31
+ return [point.x, point.y];
32
+ }
33
+
34
+ var rect = node.getBoundingClientRect();
35
+ return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
36
+ }
37
+
38
+ function mouse(node) {
39
+ var event = sourceEvent();
40
+ if (event.changedTouches) event = event.changedTouches[0];
41
+ return point(node, event);
42
+ }
43
+
44
+ function touch(node, touches, identifier) {
45
+ if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
46
+
47
+ for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
48
+ if ((touch = touches[i]).identifier === identifier) {
49
+ return point(node, touch);
50
+ }
51
+ }
52
+
53
+ return null;
54
+ }
55
+
56
+ function nopropagation$1() {
57
+ event.stopImmediatePropagation();
58
+ }
59
+
60
+ function noevent$1() {
61
+ event.preventDefault();
62
+ event.stopImmediatePropagation();
63
+ }
64
+
65
+ function dragDisable(view) {
66
+ var root = view.document.documentElement,
67
+ selection = d3Select(view).on("dragstart.drag", noevent$1, true);
68
+ if ("onselectstart" in root) {
69
+ selection.on("selectstart.drag", noevent$1, true);
70
+ } else {
71
+ root.__noselect = root.style.MozUserSelect;
72
+ root.style.MozUserSelect = "none";
73
+ }
74
+ }
75
+
76
+ function yesdrag(view, noclick) {
77
+ var root = view.document.documentElement,
78
+ selection = d3Select(view).on("dragstart.drag", null);
79
+ if (noclick) {
80
+ selection.on("click.drag", noevent$1, true);
81
+ setTimeout(function() { selection.on("click.drag", null); }, 0);
82
+ }
83
+ if ("onselectstart" in root) {
84
+ selection.on("selectstart.drag", null);
85
+ } else {
86
+ root.style.MozUserSelect = root.__noselect;
87
+ delete root.__noselect;
88
+ }
89
+ }
90
+
91
+ function constant$2(x) {
92
+ return function() {
93
+ return x;
94
+ };
95
+ }
96
+
97
+ // Ignore right-click, since that should open the context menu.
98
+ function defaultFilter$1() {
99
+ return !event.ctrlKey && !event.button;
100
+ }
101
+
102
+ function defaultContainer() {
103
+ return this.parentNode;
104
+ }
105
+
106
+ function defaultSubject(d) {
107
+ return d == null ? {x: event.x, y: event.y} : d;
108
+ }
109
+
110
+ function defaultTouchable$1() {
111
+ return navigator.maxTouchPoints || ("ontouchstart" in this);
112
+ }
113
+
114
+ function drag() {
115
+ var filter = defaultFilter$1,
116
+ container = defaultContainer,
117
+ subject = defaultSubject,
118
+ touchable = defaultTouchable$1,
119
+ gestures = {},
120
+ listeners = dispatch("start", "drag", "end"),
121
+ active = 0,
122
+ mousedownx,
123
+ mousedowny,
124
+ mousemoving,
125
+ touchending,
126
+ clickDistance2 = 0;
127
+
128
+ function drag(selection) {
129
+ selection
130
+ .on("mousedown.drag", mousedowned)
131
+ .filter(touchable)
132
+ .on("touchstart.drag", touchstarted)
133
+ .on("touchmove.drag", touchmoved)
134
+ .on("touchend.drag touchcancel.drag", touchended)
135
+ .style("touch-action", "none")
136
+ .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
137
+ }
138
+
139
+ function mousedowned() {
140
+ if (touchending || !filter.apply(this, arguments)) return;
141
+ var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
142
+ if (!gesture) return;
143
+ d3Select(event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
144
+ dragDisable(event.view);
145
+ nopropagation$1();
146
+ mousemoving = false;
147
+ mousedownx = event.clientX;
148
+ mousedowny = event.clientY;
149
+ gesture("start");
150
+ }
151
+
152
+ function mousemoved() {
153
+ noevent$1();
154
+ if (!mousemoving) {
155
+ var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
156
+ mousemoving = dx * dx + dy * dy > clickDistance2;
157
+ }
158
+ gestures.mouse("drag");
159
+ }
160
+
161
+ function mouseupped() {
162
+ d3Select(event.view).on("mousemove.drag mouseup.drag", null);
163
+ yesdrag(event.view, mousemoving);
164
+ noevent$1();
165
+ gestures.mouse("end");
166
+ }
167
+
168
+ function touchstarted() {
169
+ if (!filter.apply(this, arguments)) return;
170
+ var touches = event.changedTouches,
171
+ c = container.apply(this, arguments),
172
+ n = touches.length, i, gesture;
173
+
174
+ for (i = 0; i < n; ++i) {
175
+ if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
176
+ nopropagation$1();
177
+ gesture("start");
178
+ }
179
+ }
180
+ }
181
+
182
+ function touchmoved() {
183
+ var touches = event.changedTouches,
184
+ n = touches.length, i, gesture;
185
+
186
+ for (i = 0; i < n; ++i) {
187
+ if (gesture = gestures[touches[i].identifier]) {
188
+ noevent$1();
189
+ gesture("drag");
190
+ }
191
+ }
192
+ }
193
+
194
+ function touchended() {
195
+ var touches = event.changedTouches,
196
+ n = touches.length, i, gesture;
197
+
198
+ if (touchending) clearTimeout(touchending);
199
+ touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
200
+ for (i = 0; i < n; ++i) {
201
+ if (gesture = gestures[touches[i].identifier]) {
202
+ nopropagation$1();
203
+ gesture("end");
204
+ }
205
+ }
206
+ }
207
+
208
+ function beforestart(id, container, point, that, args) {
209
+ var p = point(container, id), s, dx, dy,
210
+ sublisteners = listeners.copy();
211
+
212
+ if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
213
+ if ((event.subject = s = subject.apply(that, args)) == null) return false;
214
+ dx = s.x - p[0] || 0;
215
+ dy = s.y - p[1] || 0;
216
+ return true;
217
+ })) return;
218
+
219
+ return function gesture(type) {
220
+ var p0 = p, n;
221
+ switch (type) {
222
+ case "start": gestures[id] = gesture, n = active++; break;
223
+ case "end": delete gestures[id], --active; // nobreak
224
+ case "drag": p = point(container, id), n = active; break;
225
+ }
226
+ customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
227
+ };
228
+ }
229
+
230
+ drag.filter = function(_) {
231
+ return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
232
+ };
233
+
234
+ drag.container = function(_) {
235
+ return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
236
+ };
237
+
238
+ drag.subject = function(_) {
239
+ return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
240
+ };
241
+
242
+ drag.touchable = function(_) {
243
+ return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
244
+ };
245
+
246
+ drag.on = function() {
247
+ var value = listeners.on.apply(listeners, arguments);
248
+ return value === listeners ? drag : value;
249
+ };
250
+
251
+ drag.clickDistance = function(_) {
252
+ return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
253
+ };
254
+
255
+ return drag;
256
+ }
257
+
258
+ var rho = Math.SQRT2,
259
+ rho2 = 2,
260
+ rho4 = 4,
261
+ epsilon2 = 1e-12;
262
+
263
+ function cosh(x) {
264
+ return ((x = Math.exp(x)) + 1 / x) / 2;
265
+ }
266
+
267
+ function sinh(x) {
268
+ return ((x = Math.exp(x)) - 1 / x) / 2;
269
+ }
270
+
271
+ function tanh(x) {
272
+ return ((x = Math.exp(2 * x)) - 1) / (x + 1);
273
+ }
274
+
275
+ // p0 = [ux0, uy0, w0]
276
+ // p1 = [ux1, uy1, w1]
277
+ function interpolateZoom(p0, p1) {
278
+ var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
279
+ ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
280
+ dx = ux1 - ux0,
281
+ dy = uy1 - uy0,
282
+ d2 = dx * dx + dy * dy,
283
+ i,
284
+ S;
285
+
286
+ // Special case for u0 ≅ u1.
287
+ if (d2 < epsilon2) {
288
+ S = Math.log(w1 / w0) / rho;
289
+ i = function(t) {
290
+ return [
291
+ ux0 + t * dx,
292
+ uy0 + t * dy,
293
+ w0 * Math.exp(rho * t * S)
294
+ ];
295
+ };
296
+ }
297
+
298
+ // General case.
299
+ else {
300
+ var d1 = Math.sqrt(d2),
301
+ b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
302
+ b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
303
+ r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
304
+ r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
305
+ S = (r1 - r0) / rho;
306
+ i = function(t) {
307
+ var s = t * S,
308
+ coshr0 = cosh(r0),
309
+ u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
310
+ return [
311
+ ux0 + u * dx,
312
+ uy0 + u * dy,
313
+ w0 * coshr0 / cosh(rho * s + r0)
314
+ ];
315
+ };
316
+ }
317
+
318
+ i.duration = S * 1000;
319
+
320
+ return i;
321
+ }
322
+
323
+ function center(x, y) {
324
+ var nodes;
325
+
326
+ if (x == null) x = 0;
327
+ if (y == null) y = 0;
328
+
329
+ function force() {
330
+ var i,
331
+ n = nodes.length,
332
+ node,
333
+ sx = 0,
334
+ sy = 0;
335
+
336
+ for (i = 0; i < n; ++i) {
337
+ node = nodes[i], sx += node.x, sy += node.y;
338
+ }
339
+
340
+ for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
341
+ node = nodes[i], node.x -= sx, node.y -= sy;
342
+ }
343
+ }
344
+
345
+ force.initialize = function(_) {
346
+ nodes = _;
347
+ };
348
+
349
+ force.x = function(_) {
350
+ return arguments.length ? (x = +_, force) : x;
351
+ };
352
+
353
+ force.y = function(_) {
354
+ return arguments.length ? (y = +_, force) : y;
355
+ };
356
+
357
+ return force;
358
+ }
359
+
360
+ function constant$1(x) {
361
+ return function() {
362
+ return x;
363
+ };
364
+ }
365
+
366
+ function jiggle() {
367
+ return (Math.random() - 0.5) * 1e-6;
368
+ }
369
+
370
+ function x$2(d) {
371
+ return d.x + d.vx;
372
+ }
373
+
374
+ function y$2(d) {
375
+ return d.y + d.vy;
376
+ }
377
+
378
+ function collide(radius) {
379
+ var nodes,
380
+ radii,
381
+ strength = 1,
382
+ iterations = 1;
383
+
384
+ if (typeof radius !== "function") radius = constant$1(radius == null ? 1 : +radius);
385
+
386
+ function force() {
387
+ var i, n = nodes.length,
388
+ tree,
389
+ node,
390
+ xi,
391
+ yi,
392
+ ri,
393
+ ri2;
394
+
395
+ for (var k = 0; k < iterations; ++k) {
396
+ tree = quadtree(nodes, x$2, y$2).visitAfter(prepare);
397
+ for (i = 0; i < n; ++i) {
398
+ node = nodes[i];
399
+ ri = radii[node.index], ri2 = ri * ri;
400
+ xi = node.x + node.vx;
401
+ yi = node.y + node.vy;
402
+ tree.visit(apply);
403
+ }
404
+ }
405
+
406
+ function apply(quad, x0, y0, x1, y1) {
407
+ var data = quad.data, rj = quad.r, r = ri + rj;
408
+ if (data) {
409
+ if (data.index > node.index) {
410
+ var x = xi - data.x - data.vx,
411
+ y = yi - data.y - data.vy,
412
+ l = x * x + y * y;
413
+ if (l < r * r) {
414
+ if (x === 0) x = jiggle(), l += x * x;
415
+ if (y === 0) y = jiggle(), l += y * y;
416
+ l = (r - (l = Math.sqrt(l))) / l * strength;
417
+ node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
418
+ node.vy += (y *= l) * r;
419
+ data.vx -= x * (r = 1 - r);
420
+ data.vy -= y * r;
421
+ }
422
+ }
423
+ return;
424
+ }
425
+ return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
426
+ }
427
+ }
428
+
429
+ function prepare(quad) {
430
+ if (quad.data) return quad.r = radii[quad.data.index];
431
+ for (var i = quad.r = 0; i < 4; ++i) {
432
+ if (quad[i] && quad[i].r > quad.r) {
433
+ quad.r = quad[i].r;
434
+ }
435
+ }
436
+ }
437
+
438
+ function initialize() {
439
+ if (!nodes) return;
440
+ var i, n = nodes.length, node;
441
+ radii = new Array(n);
442
+ for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
443
+ }
444
+
445
+ force.initialize = function(_) {
446
+ nodes = _;
447
+ initialize();
448
+ };
449
+
450
+ force.iterations = function(_) {
451
+ return arguments.length ? (iterations = +_, force) : iterations;
452
+ };
453
+
454
+ force.strength = function(_) {
455
+ return arguments.length ? (strength = +_, force) : strength;
456
+ };
457
+
458
+ force.radius = function(_) {
459
+ return arguments.length ? (radius = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : radius;
460
+ };
461
+
462
+ return force;
463
+ }
464
+
465
+ function index(d) {
466
+ return d.index;
467
+ }
468
+
469
+ function find(nodeById, nodeId) {
470
+ var node = nodeById.get(nodeId);
471
+ if (!node) throw new Error("missing: " + nodeId);
472
+ return node;
473
+ }
474
+
475
+ function link(links) {
476
+ var id = index,
477
+ strength = defaultStrength,
478
+ strengths,
479
+ distance = constant$1(30),
480
+ distances,
481
+ nodes,
482
+ count,
483
+ bias,
484
+ iterations = 1;
485
+
486
+ if (links == null) links = [];
487
+
488
+ function defaultStrength(link) {
489
+ return 1 / Math.min(count[link.source.index], count[link.target.index]);
490
+ }
491
+
492
+ function force(alpha) {
493
+ for (var k = 0, n = links.length; k < iterations; ++k) {
494
+ for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
495
+ link = links[i], source = link.source, target = link.target;
496
+ x = target.x + target.vx - source.x - source.vx || jiggle();
497
+ y = target.y + target.vy - source.y - source.vy || jiggle();
498
+ l = Math.sqrt(x * x + y * y);
499
+ l = (l - distances[i]) / l * alpha * strengths[i];
500
+ x *= l, y *= l;
501
+ target.vx -= x * (b = bias[i]);
502
+ target.vy -= y * b;
503
+ source.vx += x * (b = 1 - b);
504
+ source.vy += y * b;
505
+ }
506
+ }
507
+ }
508
+
509
+ function initialize() {
510
+ if (!nodes) return;
511
+
512
+ var i,
513
+ n = nodes.length,
514
+ m = links.length,
515
+ nodeById = map(nodes, id),
516
+ link;
517
+
518
+ for (i = 0, count = new Array(n); i < m; ++i) {
519
+ link = links[i], link.index = i;
520
+ if (typeof link.source !== "object") link.source = find(nodeById, link.source);
521
+ if (typeof link.target !== "object") link.target = find(nodeById, link.target);
522
+ count[link.source.index] = (count[link.source.index] || 0) + 1;
523
+ count[link.target.index] = (count[link.target.index] || 0) + 1;
524
+ }
525
+
526
+ for (i = 0, bias = new Array(m); i < m; ++i) {
527
+ link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
528
+ }
529
+
530
+ strengths = new Array(m), initializeStrength();
531
+ distances = new Array(m), initializeDistance();
532
+ }
533
+
534
+ function initializeStrength() {
535
+ if (!nodes) return;
536
+
537
+ for (var i = 0, n = links.length; i < n; ++i) {
538
+ strengths[i] = +strength(links[i], i, links);
539
+ }
540
+ }
541
+
542
+ function initializeDistance() {
543
+ if (!nodes) return;
544
+
545
+ for (var i = 0, n = links.length; i < n; ++i) {
546
+ distances[i] = +distance(links[i], i, links);
547
+ }
548
+ }
549
+
550
+ force.initialize = function(_) {
551
+ nodes = _;
552
+ initialize();
553
+ };
554
+
555
+ force.links = function(_) {
556
+ return arguments.length ? (links = _, initialize(), force) : links;
557
+ };
558
+
559
+ force.id = function(_) {
560
+ return arguments.length ? (id = _, force) : id;
561
+ };
562
+
563
+ force.iterations = function(_) {
564
+ return arguments.length ? (iterations = +_, force) : iterations;
565
+ };
566
+
567
+ force.strength = function(_) {
568
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$1(+_), initializeStrength(), force) : strength;
569
+ };
570
+
571
+ force.distance = function(_) {
572
+ return arguments.length ? (distance = typeof _ === "function" ? _ : constant$1(+_), initializeDistance(), force) : distance;
573
+ };
574
+
575
+ return force;
576
+ }
577
+
578
+ function x$1(d) {
579
+ return d.x;
580
+ }
581
+
582
+ function y$1(d) {
583
+ return d.y;
584
+ }
585
+
586
+ var initialRadius = 10,
587
+ initialAngle = Math.PI * (3 - Math.sqrt(5));
588
+
589
+ function simulation(nodes) {
590
+ var simulation,
591
+ alpha = 1,
592
+ alphaMin = 0.001,
593
+ alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
594
+ alphaTarget = 0,
595
+ velocityDecay = 0.6,
596
+ forces = map(),
597
+ stepper = timer(step),
598
+ event = dispatch("tick", "end");
599
+
600
+ if (nodes == null) nodes = [];
601
+
602
+ function step() {
603
+ tick();
604
+ event.call("tick", simulation);
605
+ if (alpha < alphaMin) {
606
+ stepper.stop();
607
+ event.call("end", simulation);
608
+ }
609
+ }
610
+
611
+ function tick(iterations) {
612
+ var i, n = nodes.length, node;
613
+
614
+ if (iterations === undefined) iterations = 1;
615
+
616
+ for (var k = 0; k < iterations; ++k) {
617
+ alpha += (alphaTarget - alpha) * alphaDecay;
618
+
619
+ forces.each(function (force) {
620
+ force(alpha);
621
+ });
622
+
623
+ for (i = 0; i < n; ++i) {
624
+ node = nodes[i];
625
+ if (node.fx == null) node.x += node.vx *= velocityDecay;
626
+ else node.x = node.fx, node.vx = 0;
627
+ if (node.fy == null) node.y += node.vy *= velocityDecay;
628
+ else node.y = node.fy, node.vy = 0;
629
+ }
630
+ }
631
+
632
+ return simulation;
633
+ }
634
+
635
+ function initializeNodes() {
636
+ for (var i = 0, n = nodes.length, node; i < n; ++i) {
637
+ node = nodes[i], node.index = i;
638
+ if (node.fx != null) node.x = node.fx;
639
+ if (node.fy != null) node.y = node.fy;
640
+ if (isNaN(node.x) || isNaN(node.y)) {
641
+ var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
642
+ node.x = radius * Math.cos(angle);
643
+ node.y = radius * Math.sin(angle);
644
+ }
645
+ if (isNaN(node.vx) || isNaN(node.vy)) {
646
+ node.vx = node.vy = 0;
647
+ }
648
+ }
649
+ }
650
+
651
+ function initializeForce(force) {
652
+ if (force.initialize) force.initialize(nodes);
653
+ return force;
654
+ }
655
+
656
+ initializeNodes();
657
+
658
+ return simulation = {
659
+ tick: tick,
660
+
661
+ restart: function() {
662
+ return stepper.restart(step), simulation;
663
+ },
664
+
665
+ stop: function() {
666
+ return stepper.stop(), simulation;
667
+ },
668
+
669
+ nodes: function(_) {
670
+ return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
671
+ },
672
+
673
+ alpha: function(_) {
674
+ return arguments.length ? (alpha = +_, simulation) : alpha;
675
+ },
676
+
677
+ alphaMin: function(_) {
678
+ return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
679
+ },
680
+
681
+ alphaDecay: function(_) {
682
+ return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
683
+ },
684
+
685
+ alphaTarget: function(_) {
686
+ return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
687
+ },
688
+
689
+ velocityDecay: function(_) {
690
+ return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
691
+ },
692
+
693
+ force: function(name, _) {
694
+ return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
695
+ },
696
+
697
+ find: function(x, y, radius) {
698
+ var i = 0,
699
+ n = nodes.length,
700
+ dx,
701
+ dy,
702
+ d2,
703
+ node,
704
+ closest;
705
+
706
+ if (radius == null) radius = Infinity;
707
+ else radius *= radius;
708
+
709
+ for (i = 0; i < n; ++i) {
710
+ node = nodes[i];
711
+ dx = x - node.x;
712
+ dy = y - node.y;
713
+ d2 = dx * dx + dy * dy;
714
+ if (d2 < radius) closest = node, radius = d2;
715
+ }
716
+
717
+ return closest;
718
+ },
719
+
720
+ on: function(name, _) {
721
+ return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
722
+ }
723
+ };
724
+ }
725
+
726
+ function manyBody() {
727
+ var nodes,
728
+ node,
729
+ alpha,
730
+ strength = constant$1(-30),
731
+ strengths,
732
+ distanceMin2 = 1,
733
+ distanceMax2 = Infinity,
734
+ theta2 = 0.81;
735
+
736
+ function force(_) {
737
+ var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
738
+ for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
739
+ }
740
+
741
+ function initialize() {
742
+ if (!nodes) return;
743
+ var i, n = nodes.length, node;
744
+ strengths = new Array(n);
745
+ for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
746
+ }
747
+
748
+ function accumulate(quad) {
749
+ var strength = 0, q, c, weight = 0, x, y, i;
750
+
751
+ // For internal nodes, accumulate forces from child quadrants.
752
+ if (quad.length) {
753
+ for (x = y = i = 0; i < 4; ++i) {
754
+ if ((q = quad[i]) && (c = Math.abs(q.value))) {
755
+ strength += q.value, weight += c, x += c * q.x, y += c * q.y;
756
+ }
757
+ }
758
+ quad.x = x / weight;
759
+ quad.y = y / weight;
760
+ }
761
+
762
+ // For leaf nodes, accumulate forces from coincident quadrants.
763
+ else {
764
+ q = quad;
765
+ q.x = q.data.x;
766
+ q.y = q.data.y;
767
+ do strength += strengths[q.data.index];
768
+ while (q = q.next);
769
+ }
770
+
771
+ quad.value = strength;
772
+ }
773
+
774
+ function apply(quad, x1, _, x2) {
775
+ if (!quad.value) return true;
776
+
777
+ var x = quad.x - node.x,
778
+ y = quad.y - node.y,
779
+ w = x2 - x1,
780
+ l = x * x + y * y;
781
+
782
+ // Apply the Barnes-Hut approximation if possible.
783
+ // Limit forces for very close nodes; randomize direction if coincident.
784
+ if (w * w / theta2 < l) {
785
+ if (l < distanceMax2) {
786
+ if (x === 0) x = jiggle(), l += x * x;
787
+ if (y === 0) y = jiggle(), l += y * y;
788
+ if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
789
+ node.vx += x * quad.value * alpha / l;
790
+ node.vy += y * quad.value * alpha / l;
791
+ }
792
+ return true;
793
+ }
794
+
795
+ // Otherwise, process points directly.
796
+ else if (quad.length || l >= distanceMax2) return;
797
+
798
+ // Limit forces for very close nodes; randomize direction if coincident.
799
+ if (quad.data !== node || quad.next) {
800
+ if (x === 0) x = jiggle(), l += x * x;
801
+ if (y === 0) y = jiggle(), l += y * y;
802
+ if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
803
+ }
804
+
805
+ do if (quad.data !== node) {
806
+ w = strengths[quad.data.index] * alpha / l;
807
+ node.vx += x * w;
808
+ node.vy += y * w;
809
+ } while (quad = quad.next);
810
+ }
811
+
812
+ force.initialize = function(_) {
813
+ nodes = _;
814
+ initialize();
815
+ };
816
+
817
+ force.strength = function(_) {
818
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : strength;
819
+ };
820
+
821
+ force.distanceMin = function(_) {
822
+ return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
823
+ };
824
+
825
+ force.distanceMax = function(_) {
826
+ return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
827
+ };
828
+
829
+ force.theta = function(_) {
830
+ return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
831
+ };
832
+
833
+ return force;
834
+ }
835
+
836
+ function radial(radius, x, y) {
837
+ var nodes,
838
+ strength = constant$1(0.1),
839
+ strengths,
840
+ radiuses;
841
+
842
+ if (typeof radius !== "function") radius = constant$1(+radius);
843
+ if (x == null) x = 0;
844
+ if (y == null) y = 0;
845
+
846
+ function force(alpha) {
847
+ for (var i = 0, n = nodes.length; i < n; ++i) {
848
+ var node = nodes[i],
849
+ dx = node.x - x || 1e-6,
850
+ dy = node.y - y || 1e-6,
851
+ r = Math.sqrt(dx * dx + dy * dy),
852
+ k = (radiuses[i] - r) * strengths[i] * alpha / r;
853
+ node.vx += dx * k;
854
+ node.vy += dy * k;
855
+ }
856
+ }
857
+
858
+ function initialize() {
859
+ if (!nodes) return;
860
+ var i, n = nodes.length;
861
+ strengths = new Array(n);
862
+ radiuses = new Array(n);
863
+ for (i = 0; i < n; ++i) {
864
+ radiuses[i] = +radius(nodes[i], i, nodes);
865
+ strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
866
+ }
867
+ }
868
+
869
+ force.initialize = function(_) {
870
+ nodes = _, initialize();
871
+ };
872
+
873
+ force.strength = function(_) {
874
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : strength;
875
+ };
876
+
877
+ force.radius = function(_) {
878
+ return arguments.length ? (radius = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : radius;
879
+ };
880
+
881
+ force.x = function(_) {
882
+ return arguments.length ? (x = +_, force) : x;
883
+ };
884
+
885
+ force.y = function(_) {
886
+ return arguments.length ? (y = +_, force) : y;
887
+ };
888
+
889
+ return force;
890
+ }
891
+
892
+ function x(x) {
893
+ var strength = constant$1(0.1),
894
+ nodes,
895
+ strengths,
896
+ xz;
897
+
898
+ if (typeof x !== "function") x = constant$1(x == null ? 0 : +x);
899
+
900
+ function force(alpha) {
901
+ for (var i = 0, n = nodes.length, node; i < n; ++i) {
902
+ node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
903
+ }
904
+ }
905
+
906
+ function initialize() {
907
+ if (!nodes) return;
908
+ var i, n = nodes.length;
909
+ strengths = new Array(n);
910
+ xz = new Array(n);
911
+ for (i = 0; i < n; ++i) {
912
+ strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
913
+ }
914
+ }
915
+
916
+ force.initialize = function(_) {
917
+ nodes = _;
918
+ initialize();
919
+ };
920
+
921
+ force.strength = function(_) {
922
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : strength;
923
+ };
924
+
925
+ force.x = function(_) {
926
+ return arguments.length ? (x = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : x;
927
+ };
928
+
929
+ return force;
930
+ }
931
+
932
+ function y(y) {
933
+ var strength = constant$1(0.1),
934
+ nodes,
935
+ strengths,
936
+ yz;
937
+
938
+ if (typeof y !== "function") y = constant$1(y == null ? 0 : +y);
939
+
940
+ function force(alpha) {
941
+ for (var i = 0, n = nodes.length, node; i < n; ++i) {
942
+ node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
943
+ }
944
+ }
945
+
946
+ function initialize() {
947
+ if (!nodes) return;
948
+ var i, n = nodes.length;
949
+ strengths = new Array(n);
950
+ yz = new Array(n);
951
+ for (i = 0; i < n; ++i) {
952
+ strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
953
+ }
954
+ }
955
+
956
+ force.initialize = function(_) {
957
+ nodes = _;
958
+ initialize();
959
+ };
960
+
961
+ force.strength = function(_) {
962
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : strength;
963
+ };
964
+
965
+ force.y = function(_) {
966
+ return arguments.length ? (y = typeof _ === "function" ? _ : constant$1(+_), initialize(), force) : y;
967
+ };
968
+
969
+ return force;
970
+ }
971
+
972
+ function constant(x) {
973
+ return function() {
974
+ return x;
975
+ };
976
+ }
977
+
978
+ function ZoomEvent(target, type, transform) {
979
+ this.target = target;
980
+ this.type = type;
981
+ this.transform = transform;
982
+ }
983
+
984
+ function nopropagation() {
985
+ event.stopImmediatePropagation();
986
+ }
987
+
988
+ function noevent() {
989
+ event.preventDefault();
990
+ event.stopImmediatePropagation();
991
+ }
992
+
993
+ // Ignore right-click, since that should open the context menu.
994
+ function defaultFilter() {
995
+ return !event.ctrlKey && !event.button;
996
+ }
997
+
998
+ function defaultExtent() {
999
+ var e = this;
1000
+ if (e instanceof SVGElement) {
1001
+ e = e.ownerSVGElement || e;
1002
+ if (e.hasAttribute("viewBox")) {
1003
+ e = e.viewBox.baseVal;
1004
+ return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
1005
+ }
1006
+ return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
1007
+ }
1008
+ return [[0, 0], [e.clientWidth, e.clientHeight]];
1009
+ }
1010
+
1011
+ function defaultTransform() {
1012
+ return this.__zoom || identity;
1013
+ }
1014
+
1015
+ function defaultWheelDelta() {
1016
+ return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002);
1017
+ }
1018
+
1019
+ function defaultTouchable() {
1020
+ return navigator.maxTouchPoints || ("ontouchstart" in this);
1021
+ }
1022
+
1023
+ function defaultConstrain(transform, extent, translateExtent) {
1024
+ var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
1025
+ dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
1026
+ dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
1027
+ dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
1028
+ return transform.translate(
1029
+ dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
1030
+ dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
1031
+ );
1032
+ }
1033
+
1034
+ function zoom() {
1035
+ var filter = defaultFilter,
1036
+ extent = defaultExtent,
1037
+ constrain = defaultConstrain,
1038
+ wheelDelta = defaultWheelDelta,
1039
+ touchable = defaultTouchable,
1040
+ scaleExtent = [0, Infinity],
1041
+ translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
1042
+ duration = 250,
1043
+ interpolate = interpolateZoom,
1044
+ listeners = dispatch("start", "zoom", "end"),
1045
+ touchstarting,
1046
+ touchending,
1047
+ touchDelay = 500,
1048
+ wheelDelay = 150,
1049
+ clickDistance2 = 0;
1050
+
1051
+ function zoom(selection) {
1052
+ selection
1053
+ .property("__zoom", defaultTransform)
1054
+ .on("wheel.zoom", wheeled)
1055
+ .on("mousedown.zoom", mousedowned)
1056
+ .on("dblclick.zoom", dblclicked)
1057
+ .filter(touchable)
1058
+ .on("touchstart.zoom", touchstarted)
1059
+ .on("touchmove.zoom", touchmoved)
1060
+ .on("touchend.zoom touchcancel.zoom", touchended)
1061
+ .style("touch-action", "none")
1062
+ .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1063
+ }
1064
+
1065
+ zoom.transform = function(collection, transform, point) {
1066
+ var selection = collection.selection ? collection.selection() : collection;
1067
+ selection.property("__zoom", defaultTransform);
1068
+ if (collection !== selection) {
1069
+ schedule(collection, transform, point);
1070
+ } else {
1071
+ selection.interrupt().each(function() {
1072
+ gesture(this, arguments)
1073
+ .start()
1074
+ .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
1075
+ .end();
1076
+ });
1077
+ }
1078
+ };
1079
+
1080
+ zoom.scaleBy = function(selection, k, p) {
1081
+ zoom.scaleTo(selection, function() {
1082
+ var k0 = this.__zoom.k,
1083
+ k1 = typeof k === "function" ? k.apply(this, arguments) : k;
1084
+ return k0 * k1;
1085
+ }, p);
1086
+ };
1087
+
1088
+ zoom.scaleTo = function(selection, k, p) {
1089
+ zoom.transform(selection, function() {
1090
+ var e = extent.apply(this, arguments),
1091
+ t0 = this.__zoom,
1092
+ p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
1093
+ p1 = t0.invert(p0),
1094
+ k1 = typeof k === "function" ? k.apply(this, arguments) : k;
1095
+ return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
1096
+ }, p);
1097
+ };
1098
+
1099
+ zoom.translateBy = function(selection, x, y) {
1100
+ zoom.transform(selection, function() {
1101
+ return constrain(this.__zoom.translate(
1102
+ typeof x === "function" ? x.apply(this, arguments) : x,
1103
+ typeof y === "function" ? y.apply(this, arguments) : y
1104
+ ), extent.apply(this, arguments), translateExtent);
1105
+ });
1106
+ };
1107
+
1108
+ zoom.translateTo = function(selection, x, y, p) {
1109
+ zoom.transform(selection, function() {
1110
+ var e = extent.apply(this, arguments),
1111
+ t = this.__zoom,
1112
+ p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
1113
+ return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
1114
+ typeof x === "function" ? -x.apply(this, arguments) : -x,
1115
+ typeof y === "function" ? -y.apply(this, arguments) : -y
1116
+ ), e, translateExtent);
1117
+ }, p);
1118
+ };
1119
+
1120
+ function scale(transform, k) {
1121
+ k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
1122
+ return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
1123
+ }
1124
+
1125
+ function translate(transform, p0, p1) {
1126
+ var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
1127
+ return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
1128
+ }
1129
+
1130
+ function centroid(extent) {
1131
+ return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
1132
+ }
1133
+
1134
+ function schedule(transition, transform, point) {
1135
+ transition
1136
+ .on("start.zoom", function() { gesture(this, arguments).start(); })
1137
+ .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
1138
+ .tween("zoom", function() {
1139
+ var that = this,
1140
+ args = arguments,
1141
+ g = gesture(that, args),
1142
+ e = extent.apply(that, args),
1143
+ p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
1144
+ w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
1145
+ a = that.__zoom,
1146
+ b = typeof transform === "function" ? transform.apply(that, args) : transform,
1147
+ i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
1148
+ return function(t) {
1149
+ if (t === 1) t = b; // Avoid rounding error on end.
1150
+ else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
1151
+ g.zoom(null, t);
1152
+ };
1153
+ });
1154
+ }
1155
+
1156
+ function gesture(that, args, clean) {
1157
+ return (!clean && that.__zooming) || new Gesture(that, args);
1158
+ }
1159
+
1160
+ function Gesture(that, args) {
1161
+ this.that = that;
1162
+ this.args = args;
1163
+ this.active = 0;
1164
+ this.extent = extent.apply(that, args);
1165
+ this.taps = 0;
1166
+ }
1167
+
1168
+ Gesture.prototype = {
1169
+ start: function() {
1170
+ if (++this.active === 1) {
1171
+ this.that.__zooming = this;
1172
+ this.emit("start");
1173
+ }
1174
+ return this;
1175
+ },
1176
+ zoom: function(key, transform) {
1177
+ if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
1178
+ if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
1179
+ if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
1180
+ this.that.__zoom = transform;
1181
+ this.emit("zoom");
1182
+ return this;
1183
+ },
1184
+ end: function() {
1185
+ if (--this.active === 0) {
1186
+ delete this.that.__zooming;
1187
+ this.emit("end");
1188
+ }
1189
+ return this;
1190
+ },
1191
+ emit: function(type) {
1192
+ customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
1193
+ }
1194
+ };
1195
+
1196
+ function wheeled() {
1197
+ if (!filter.apply(this, arguments)) return;
1198
+ var g = gesture(this, arguments),
1199
+ t = this.__zoom,
1200
+ k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
1201
+ p = mouse(this);
1202
+
1203
+ // If the mouse is in the same location as before, reuse it.
1204
+ // If there were recent wheel events, reset the wheel idle timeout.
1205
+ if (g.wheel) {
1206
+ if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
1207
+ g.mouse[1] = t.invert(g.mouse[0] = p);
1208
+ }
1209
+ clearTimeout(g.wheel);
1210
+ }
1211
+
1212
+ // If this wheel event won’t trigger a transform change, ignore it.
1213
+ else if (t.k === k) return;
1214
+
1215
+ // Otherwise, capture the mouse point and location at the start.
1216
+ else {
1217
+ g.mouse = [p, t.invert(p)];
1218
+ interrupt(this);
1219
+ g.start();
1220
+ }
1221
+
1222
+ noevent();
1223
+ g.wheel = setTimeout(wheelidled, wheelDelay);
1224
+ g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
1225
+
1226
+ function wheelidled() {
1227
+ g.wheel = null;
1228
+ g.end();
1229
+ }
1230
+ }
1231
+
1232
+ function mousedowned() {
1233
+ if (touchending || !filter.apply(this, arguments)) return;
1234
+ var g = gesture(this, arguments, true),
1235
+ v = d3Select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
1236
+ p = mouse(this),
1237
+ x0 = event.clientX,
1238
+ y0 = event.clientY;
1239
+
1240
+ dragDisable(event.view);
1241
+ nopropagation();
1242
+ g.mouse = [p, this.__zoom.invert(p)];
1243
+ interrupt(this);
1244
+ g.start();
1245
+
1246
+ function mousemoved() {
1247
+ noevent();
1248
+ if (!g.moved) {
1249
+ var dx = event.clientX - x0, dy = event.clientY - y0;
1250
+ g.moved = dx * dx + dy * dy > clickDistance2;
1251
+ }
1252
+ g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
1253
+ }
1254
+
1255
+ function mouseupped() {
1256
+ v.on("mousemove.zoom mouseup.zoom", null);
1257
+ yesdrag(event.view, g.moved);
1258
+ noevent();
1259
+ g.end();
1260
+ }
1261
+ }
1262
+
1263
+ function dblclicked() {
1264
+ if (!filter.apply(this, arguments)) return;
1265
+ var t0 = this.__zoom,
1266
+ p0 = mouse(this),
1267
+ p1 = t0.invert(p0),
1268
+ k1 = t0.k * (event.shiftKey ? 0.5 : 2),
1269
+ t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
1270
+
1271
+ noevent();
1272
+ if (duration > 0) d3Select(this).transition().duration(duration).call(schedule, t1, p0);
1273
+ else d3Select(this).call(zoom.transform, t1);
1274
+ }
1275
+
1276
+ function touchstarted() {
1277
+ if (!filter.apply(this, arguments)) return;
1278
+ var touches = event.touches,
1279
+ n = touches.length,
1280
+ g = gesture(this, arguments, event.changedTouches.length === n),
1281
+ started, i, t, p;
1282
+
1283
+ nopropagation();
1284
+ for (i = 0; i < n; ++i) {
1285
+ t = touches[i], p = touch(this, touches, t.identifier);
1286
+ p = [p, this.__zoom.invert(p), t.identifier];
1287
+ if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
1288
+ else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
1289
+ }
1290
+
1291
+ if (touchstarting) touchstarting = clearTimeout(touchstarting);
1292
+
1293
+ if (started) {
1294
+ if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
1295
+ interrupt(this);
1296
+ g.start();
1297
+ }
1298
+ }
1299
+
1300
+ function touchmoved() {
1301
+ if (!this.__zooming) return;
1302
+ var g = gesture(this, arguments),
1303
+ touches = event.changedTouches,
1304
+ n = touches.length, i, t, p, l;
1305
+
1306
+ noevent();
1307
+ if (touchstarting) touchstarting = clearTimeout(touchstarting);
1308
+ g.taps = 0;
1309
+ for (i = 0; i < n; ++i) {
1310
+ t = touches[i], p = touch(this, touches, t.identifier);
1311
+ if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
1312
+ else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
1313
+ }
1314
+ t = g.that.__zoom;
1315
+ if (g.touch1) {
1316
+ var p0 = g.touch0[0], l0 = g.touch0[1],
1317
+ p1 = g.touch1[0], l1 = g.touch1[1],
1318
+ dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
1319
+ dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
1320
+ t = scale(t, Math.sqrt(dp / dl));
1321
+ p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
1322
+ l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
1323
+ }
1324
+ else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
1325
+ else return;
1326
+ g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
1327
+ }
1328
+
1329
+ function touchended() {
1330
+ if (!this.__zooming) return;
1331
+ var g = gesture(this, arguments),
1332
+ touches = event.changedTouches,
1333
+ n = touches.length, i, t;
1334
+
1335
+ nopropagation();
1336
+ if (touchending) clearTimeout(touchending);
1337
+ touchending = setTimeout(function() { touchending = null; }, touchDelay);
1338
+ for (i = 0; i < n; ++i) {
1339
+ t = touches[i];
1340
+ if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
1341
+ else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
1342
+ }
1343
+ if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
1344
+ if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
1345
+ else {
1346
+ g.end();
1347
+ // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
1348
+ if (g.taps === 2) {
1349
+ var p = d3Select(this).on("dblclick.zoom");
1350
+ if (p) p.apply(this, arguments);
1351
+ }
1352
+ }
1353
+ }
1354
+
1355
+ zoom.wheelDelta = function(_) {
1356
+ return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
1357
+ };
1358
+
1359
+ zoom.filter = function(_) {
1360
+ return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
1361
+ };
1362
+
1363
+ zoom.touchable = function(_) {
1364
+ return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
1365
+ };
1366
+
1367
+ zoom.extent = function(_) {
1368
+ return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
1369
+ };
1370
+
1371
+ zoom.scaleExtent = function(_) {
1372
+ return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
1373
+ };
1374
+
1375
+ zoom.translateExtent = function(_) {
1376
+ return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
1377
+ };
1378
+
1379
+ zoom.constrain = function(_) {
1380
+ return arguments.length ? (constrain = _, zoom) : constrain;
1381
+ };
1382
+
1383
+ zoom.duration = function(_) {
1384
+ return arguments.length ? (duration = +_, zoom) : duration;
1385
+ };
1386
+
1387
+ zoom.interpolate = function(_) {
1388
+ return arguments.length ? (interpolate = _, zoom) : interpolate;
1389
+ };
1390
+
1391
+ zoom.on = function() {
1392
+ var value = listeners.on.apply(listeners, arguments);
1393
+ return value === listeners ? zoom : value;
1394
+ };
1395
+
1396
+ zoom.clickDistance = function(_) {
1397
+ return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
1398
+ };
1399
+
1400
+ return zoom;
1401
+ }
1402
+
1403
+ var Replay = {};
1404
+
1405
+ var _interopRequireDefault = interopRequireDefault.exports;
1406
+
1407
+ var _interopRequireWildcard = interopRequireWildcard.exports;
1408
+
1409
+ Object.defineProperty(Replay, "__esModule", {
1410
+ value: true
1411
+ });
1412
+ var default_1 = Replay.default = void 0;
1413
+
1414
+ var React = _interopRequireWildcard(React__default);
1415
+
1416
+ var _createSvgIcon = _interopRequireDefault(requireCreateSvgIcon());
1417
+
1418
+ var _default = (0, _createSvgIcon.default)( /*#__PURE__*/React.createElement("path", {
1419
+ d: "M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"
1420
+ }), 'Replay');
1421
+
1422
+ default_1 = Replay.default = _default;
1423
+
1424
+ const ResetBtn = _ref => {
1425
+ let {
1426
+ renderSNA
1427
+ } = _ref;
1428
+ return /*#__PURE__*/React__default.createElement("div", {
1429
+ id: "resetBtn"
1430
+ }, /*#__PURE__*/React__default.createElement(Tooltip, {
1431
+ title: "\u56DE\u5230\u539F\u4F86\u4F4D\u7F6E\u8207\u5927\u5C0F"
1432
+ }, /*#__PURE__*/React__default.createElement(IconButton, {
1433
+ onClick: () => renderSNA()
1434
+ }, /*#__PURE__*/React__default.createElement(default_1, null))));
1435
+ };
1436
+ ResetBtn.propTypes = {
1437
+ renderSNA: PropTypes.func.isRequired
1438
+ };
1439
+
1440
+ var css_248z = ".SNA {\n overflow: hidden;\n object-fit: contain;\n position: relative;\n font-size: 0.75rem;\n width: 100%; }\n .SNA--smallSize .node {\n padding-top: 8px;\n font-size: 0.75rem;\n width: 3rem;\n height: 3rem;\n overflow: hidden;\n white-space: pre-wrap;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical; }\n .SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 20px;\n font-weight: 500;\n height: 54px;\n width: 54px;\n padding-top: 15px;\n position: absolute;\n text-align: center;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: grab; }\n .SNA .links line {\n stroke: #c7bfb4;\n stroke-width: 2; }\n .SNA .mainNode {\n fill: #4e3a16; }\n .SNA .person {\n fill: #867b3a; }\n .SNA .publication {\n fill: #825c0d; }\n .SNA .article {\n fill: #afafaf; }\n .SNA .keyword {\n fill: #fcfae8; }\n .SNA .org {\n fill: #000000; }\n .SNA #resetBtn {\n float: right; }\n .SNA #network-graph svg {\n width: 100%;\n height: 100%; }\n\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px; }\n .SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 1px;\n font-weight: 500;\n height: 44px;\n width: 44px;\n padding-top: 12px;\n position: absolute;\n text-align: center;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: grab; } }\n\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px; } }\n";
1441
+ styleInject(css_248z);
1442
+
1443
+ /* eslint-disable indent */
1444
+ var SNA = function SNA(props) {
1445
+ // common
1446
+ var className = props.className,
1447
+ intl = props.intl,
1448
+ exclude = props.exclude,
1449
+ distance = props.distance,
1450
+ SNAData = props.SNAData,
1451
+ handleClickNodeGoto = props.handleClickNodeGoto,
1452
+ DownloadExcel = props.DownloadExcel;
1453
+ // styles
1454
+ var width = props.width,
1455
+ height = props.height,
1456
+ fontColor = props.fontColor,
1457
+ backgroundColor = props.backgroundColor,
1458
+ iconColor = props.iconColor;
1459
+ var g;
1460
+ if (!SNAData || SNAData.nodes.length === 0) {
1461
+ return /*#__PURE__*/React__default.createElement("div", {
1462
+ className: "noData"
1463
+ }, intl ? intl.formatMessage({
1464
+ id: 'common.noData'
1465
+ }) : '暫無資料');
1466
+ }
1467
+ var contentWidth = useMemo(function () {
1468
+ return screen.width > 1050 ? width : screen.width - 80;
1469
+ }, [screen.width]);
1470
+ var contentHeight = useMemo(function () {
1471
+ return screen.width > 1050 ? height : screen.height - 300;
1472
+ }, [screen.width]);
1473
+ var translateType = function translateType(type) {
1474
+ switch (type) {
1475
+ case 'mainNode':
1476
+ // 主要搜尋中心
1477
+ return intl ? intl.formatMessage({
1478
+ id: 'SNA.search.center'
1479
+ }) : '主要搜尋中心';
1480
+ case 'organization':
1481
+ // 組織
1482
+ return intl ? intl.formatMessage({
1483
+ id: 'SNA.organization'
1484
+ }) : '組織';
1485
+ case 'person':
1486
+ // 作家
1487
+ return intl ? intl.formatMessage({
1488
+ id: 'SNA.author'
1489
+ }) : '作家';
1490
+ case 'publication':
1491
+ // 著作
1492
+ return intl ? intl.formatMessage({
1493
+ id: 'SNA.publication'
1494
+ }) : '作家';
1495
+ case 'article':
1496
+ // 單篇作品
1497
+ return intl ? intl.formatMessage({
1498
+ id: 'SNA.article'
1499
+ }) : '單篇作品';
1500
+ case 'keyword':
1501
+ // 關鍵字
1502
+ return intl ? intl.formatMessage({
1503
+ id: 'SNA.keyword'
1504
+ }) : '關鍵字';
1505
+ case 'event':
1506
+ // 事件
1507
+ return intl ? intl.formatMessage({
1508
+ id: 'SNA.event'
1509
+ }) : '事件';
1510
+ default:
1511
+ return '';
1512
+ }
1513
+ };
1514
+ var drag$1 = function drag$1(simulation) {
1515
+ function dragstarted(d) {
1516
+ if (!event.active) simulation.alphaTarget(0.3).restart();
1517
+ d.fx = d.x;
1518
+ d.fy = d.y;
1519
+ }
1520
+ function dragged(d) {
1521
+ d.fx = event.x > contentWidth - 10 || event.x < 20 ? d.x : event.x;
1522
+ d.fy = event.y > contentHeight - 10 || event.y < 20 ? d.y : event.y;
1523
+ }
1524
+ return drag().on('start', dragstarted).on('drag', dragged);
1525
+ };
1526
+ var calculateCurve = function calculateCurve(source, target, curveLen) {
1527
+ var mx = (target.x + source.x) * 0.5;
1528
+ var my = (target.y + source.y) * 0.5;
1529
+ var tsx = target.x - source.x;
1530
+ var tsy = target.y - source.y;
1531
+ var L = Math.pow(Math.pow(tsx, 2) + Math.pow(tsy, 2), 0.5);
1532
+ var qx = mx - tsy * curveLen / L;
1533
+ var qy = my + tsx * curveLen / L;
1534
+ return {
1535
+ qx: qx,
1536
+ qy: qy
1537
+ };
1538
+ };
1539
+ var getLineCurve = function getLineCurve(source, target, curveLen) {
1540
+ var _calculateCurve = calculateCurve(source, target, curveLen),
1541
+ qx = _calculateCurve.qx,
1542
+ qy = _calculateCurve.qy;
1543
+ if (isNaN(qx)) {
1544
+ return "M".concat(source.x, ", ").concat(source.y, " Q0 0 ").concat(target.x, " ").concat(target.y);
1545
+ }
1546
+ return "M".concat(source.x, ", ").concat(source.y, " Q").concat(qx, " ").concat(qy, " ").concat(target.x, " ").concat(target.y);
1547
+ };
1548
+ var init = function init(networkData) {
1549
+ var edgeLabelSize = '10px';
1550
+ var lineRaduis = 30;
1551
+ var nodeStroke = 1.5;
1552
+ var nodeRadius = 10 - nodeStroke;
1553
+ var mainNodeRadius = 15 - nodeStroke;
1554
+ var arrowPercent = 0.8;
1555
+ var arrowViewBox = "-0 -".concat(nodeRadius, " ").concat(nodeRadius * 2, " ").concat(nodeRadius * 2);
1556
+ var arrowPath = "M 0,-".concat(nodeRadius * arrowPercent, " L ").concat(nodeRadius * arrowPercent * 2, " ,0 L 0,").concat(nodeRadius * arrowPercent);
1557
+ var color = ordinal(category10);
1558
+ var links = networkData.links.map(function (d) {
1559
+ return Object.create(d);
1560
+ });
1561
+ var nodes = networkData.nodes.map(function (d) {
1562
+ return Object.create(d);
1563
+ });
1564
+ var simulation$1 = simulation(nodes).force('link', link(links).id(function (d) {
1565
+ return d.index;
1566
+ }).distance(50)).force('charge', manyBody().strength(-200).distanceMax(1000)).force('center', center(contentWidth / 2, contentHeight / 2)).force('collide', collide().radius(function () {
1567
+ return nodeRadius + 5;
1568
+ }).strength(1).iterations(10)).force('x', x(contentWidth / 2)).force('y', y(contentHeight / 2)).force('radial', radial(100, contentWidth / 1.5, contentHeight / 1.5));
1569
+ var svg = d3Select('#sna-graph').append('svg').attr('viewBox', [0, 0, contentWidth, contentHeight]).style('background-color', backgroundColor);
1570
+ svg.append('defs').append('marker').attr('id', 'arrowhead').attr('viewBox', arrowViewBox).attr('refX', nodeRadius * 2 + nodeRadius * arrowPercent).attr('refY', 0).attr('orient', 'auto').attr('markerWidth', nodeRadius * (1 + arrowPercent)).attr('markerHeight', nodeRadius * (1 + arrowPercent)).attr('xoverflow', 'visible').append('svg:path').attr('d', arrowPath).attr('fill', '#999').style('stroke', 'none');
1571
+ // 增加一層g用來包住所有的物件,並對此g加入縮放功能
1572
+ g = svg.append('g');
1573
+ var zoomActions = function zoomActions() {
1574
+ g.attr('transform', event.transform);
1575
+ };
1576
+ var zoomHandler = zoom().scaleExtent([0.5, 20]).extent([[0, 0], [contentWidth, contentHeight]]).on('zoom', zoomActions);
1577
+ zoomHandler(svg);
1578
+ var link$1 = g.append('g').attr('stroke', '#999').attr('stroke-opacity', 0.6).selectAll('line').data(links).join('path').attr('fill', 'none').attr('stroke-dasharray', function (d) {
1579
+ return d.ontology === 'protege' ? '2,5,3' : '';
1580
+ }).attr('key', function (d) {
1581
+ return d.type;
1582
+ });
1583
+ var node = g.append('g').attr('stroke', '#fff').attr('stroke-width', nodeStroke).selectAll('circle').data(nodes).join('circle').attr('r', function (d) {
1584
+ return d.type === 'mainNode' ? mainNodeRadius : nodeRadius;
1585
+ }).attr('fill', function (d) {
1586
+ return color(d.type);
1587
+ }).attr('key', function (d) {
1588
+ return d.type;
1589
+ }).attr('class', function (d) {
1590
+ return "node node-".concat(d.id, " ").concat(d.type && d.type === 'organization' ? 'org' : d.type === 'person' ? 'person' : d.type === 'publication' ? 'publication' : d.type === 'mainNode' ? 'mainNode' : d.type === 'article' ? 'article' : d.type === 'keyword' ? 'keyword' : d.type === 'event' ? 'event' : '');
1591
+ }).on('click', function (d) {
1592
+ return d.hasClick ? handleClickNodeGoto({
1593
+ name: d.name,
1594
+ id: d.id,
1595
+ type: d.type
1596
+ }) : null;
1597
+ }).call(drag$1(simulation$1));
1598
+ node.append('title').text(function (d) {
1599
+ return "".concat(d.name, "-").concat(translateType(d.type));
1600
+ });
1601
+ var nodeLabel = g.append('g').selectAll('text').data(nodes).join('text').attr('fill', fontColor).attr('text-anchor', 'middle').attr('key', function (d) {
1602
+ return d.type;
1603
+ }).style('color', '#fff').style('font-size', '14px').text(function (d) {
1604
+ return d.name;
1605
+ });
1606
+ var edgepaths = g.selectAll('.edgepath').data(links).enter().append('path').attr('class', 'edgepath').attr('fill-opacity', 0).attr('stroke-opacity', 0).attr('id', function (d, i) {
1607
+ return "edgepath".concat(i);
1608
+ }).style('pointer-events', 'none');
1609
+ var edgelabels = g.selectAll('.edgelabel').data(links).enter().append('text').style('pointer-events', 'none').attr('class', 'edgelabel').attr('font-size', edgeLabelSize).attr('fill', '#aaa').attr('visibility', 'visible').attr('key', function (d) {
1610
+ return d.type;
1611
+ }).attr('id', function (d, i) {
1612
+ return "edgelabel".concat(i);
1613
+ });
1614
+ edgelabels.append('textPath').attr('xlink:href', function (d, i) {
1615
+ return "#edgepath".concat(i);
1616
+ }).style('text-anchor', 'middle').style('pointer-events', 'none').attr('startOffset', '50%').text(function (d) {
1617
+ return d.property;
1618
+ });
1619
+ simulation$1.on('tick', function () {
1620
+ nodes.forEach(function (d) {
1621
+ // x軸 超過寬度380,回彈到380座標軸區域位置。 ——作用爲:超出範圍的回彈到視圖寬度範圍內
1622
+ if (d.x >= contentWidth - 20) {
1623
+ d.x = contentWidth - 20;
1624
+ }
1625
+ // y軸 超過高度280,回彈到280座標軸區域位置。 ——作用爲:超出範圍的回彈到視圖高度範圍內
1626
+ if (d.y >= contentHeight - 20) {
1627
+ d.y = contentHeight - 20;
1628
+ }
1629
+ if (d.x <= 20) {
1630
+ d.x = 20;
1631
+ }
1632
+ if (d.y <= 20) {
1633
+ d.y = 20;
1634
+ }
1635
+ });
1636
+ link$1.attr('d', function (d) {
1637
+ return getLineCurve(d.source, d.target, lineRaduis);
1638
+ });
1639
+ node.attr('cx', function (d) {
1640
+ return d.x;
1641
+ }).attr('cy', function (d) {
1642
+ return d.y;
1643
+ });
1644
+ nodeLabel.attr('x', function (d) {
1645
+ return d.x;
1646
+ }).attr('y', function (d) {
1647
+ return d.y - nodeRadius;
1648
+ });
1649
+ edgepaths.attr('d', function (d) {
1650
+ return getLineCurve(d.source, d.target, lineRaduis);
1651
+ });
1652
+ });
1653
+ };
1654
+ var renderSNA = function renderSNA() {
1655
+ if (SNAData && SNAData.nodes && SNAData.nodes.length > 0) {
1656
+ var div = document.getElementById('sna-graph');
1657
+ if (div && div.childNodes[0]) {
1658
+ div.removeChild(div.childNodes[0]);
1659
+ }
1660
+ init(SNAData);
1661
+ }
1662
+ };
1663
+
1664
+ // 資料異動或全螢幕切換,重新渲染網絡圖
1665
+ useEffect(function () {
1666
+ renderSNA();
1667
+ }, [SNAData]);
1668
+ return /*#__PURE__*/React__default.createElement("div", {
1669
+ className: classNames('SNA', {
1670
+ 'SNA--smallSize': distance < 200
1671
+ }, className),
1672
+ style: {
1673
+ contentWidth: contentWidth,
1674
+ contentHeight: contentHeight,
1675
+ backgroundColor: backgroundColor
1676
+ }
1677
+ }, /*#__PURE__*/React__default.createElement(ExtraTools, {
1678
+ intl: intl,
1679
+ data: SNAData,
1680
+ iconColor: iconColor,
1681
+ domToImageId: "sna-graph",
1682
+ FontSizeTargets: ['#sna-graph svg g text'],
1683
+ exclude: exclude,
1684
+ DownloadExcel: DownloadExcel,
1685
+ fullscreenDomId: "sna-graph"
1686
+ }), /*#__PURE__*/React__default.createElement(ResetBtn, {
1687
+ renderSNA: renderSNA
1688
+ }), /*#__PURE__*/React__default.createElement("div", {
1689
+ id: "sna-graph"
1690
+ }));
1691
+ };
1692
+ SNA.defaultProps = {
1693
+ className: undefined,
1694
+ intl: undefined,
1695
+ width: 1050,
1696
+ height: 600,
1697
+ distance: 400,
1698
+ SNAData: null,
1699
+ fontColor: '#000000',
1700
+ backgroundColor: '#FFFFFF',
1701
+ iconColor: '#825c0d',
1702
+ exclude: ['downloadXls', 'downloadTsv'],
1703
+ handleClickNodeGoto: null,
1704
+ DownloadExcel: undefined
1705
+ };
1706
+
1707
+ /* Write props detail information and 'npm run updateStory' will help you generate stories's argTypes */
1708
+ SNA.propTypes = {
1709
+ /** Css Name */
1710
+ className: PropTypes.string,
1711
+ /** 語言 */
1712
+ intl: PropTypes.objectOf(PropTypes.any),
1713
+ /** 寬度 */
1714
+ width: PropTypes.number,
1715
+ /** 高度 */
1716
+ height: PropTypes.number,
1717
+ /** 點跟點之間的距離 */
1718
+ distance: PropTypes.number,
1719
+ /** 資料 */
1720
+ SNAData: PropTypes.objectOf(PropTypes.any),
1721
+ /** 網絡圖文字顏色 */
1722
+ fontColor: PropTypes.string,
1723
+ /** 網絡圖背景顏色 */
1724
+ backgroundColor: PropTypes.string,
1725
+ /** icon顏色 */
1726
+ iconColor: PropTypes.string,
1727
+ /** 不顯示的按鈕 ['share', 'downloadImage', 'downloadTsv', 'downloadXls', 'fullscreen', 'fontSizeChanger'] */
1728
+ exclude: PropTypes.arrayOf(PropTypes.string),
1729
+ /** 按下點後要轉址的功能 */
1730
+ handleClickNodeGoto: PropTypes.func,
1731
+ /** Download元件, 由外部傳入的原因是需要環境設定 */
1732
+ DownloadExcel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
1733
+ };
1734
+
1735
+ export { SNA as default };