@daoyi/nmtl-ui 2.0.1-beta.129 → 2.0.1-beta.130
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/lib/components/SNA.js +32 -5
- package/package.json +1 -1
package/lib/components/SNA.js
CHANGED
|
@@ -1400,10 +1400,18 @@ function zoom() {
|
|
|
1400
1400
|
return zoom;
|
|
1401
1401
|
}
|
|
1402
1402
|
|
|
1403
|
-
var css_248z = ".SNA {\n overflow: hidden;\n object-fit: contain;\n position: relative;\n font-size: 0.75rem;\n width: 100%;\n}\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}\n.SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 1.25rem;\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}\n.SNA .links line {\n stroke: #c7bfb4;\n stroke-width: 2;\n}\n.SNA .mainNode {\n fill: #4e3a16;\n}\n.SNA .person {\n fill: #867b3a;\n}\n.SNA .publication {\n fill: #825c0d;\n}\n.SNA .article {\n fill: #afafaf;\n}\n.SNA .keyword {\n fill: #fcfae8;\n}\n.SNA .org {\n fill: #000000;\n}\n.SNA #network-graph svg {\n width: 100%;\n height: 100%;\n}\n\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px;\n }\n .SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 0.0625rem;\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}\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px;\n }\n}";
|
|
1403
|
+
var css_248z = "@charset \"UTF-8\";\n.SNA {\n overflow: hidden;\n object-fit: contain;\n position: relative;\n font-size: 0.75rem;\n width: 100%;\n /* 效能:MUI CssBaseline 的全域規則 `*, *::before, *::after { box-sizing: inherit }` 用了 inherit,\n Chrome 對帶 inherit 的樣式無法重用快取;模擬每個 tick 改寫上千個 SVG 元素的 cx/cy/x/y/d,\n 每個元素都得完整重算樣式(ra 1,427 節點每格繪製約 2–4 秒)。\n box-sizing 對 SVG 內部元素沒有作用,這裡改成固定值蓋掉 inherit,畫面不變、每格降到約 70 ms(micro-bench 實測) */\n}\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}\n.SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 1.25rem;\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}\n.SNA .links line {\n stroke: #c7bfb4;\n stroke-width: 2;\n}\n.SNA .mainNode {\n fill: #4e3a16;\n}\n.SNA .person {\n fill: #867b3a;\n}\n.SNA .publication {\n fill: #825c0d;\n}\n.SNA .article {\n fill: #afafaf;\n}\n.SNA .keyword {\n fill: #fcfae8;\n}\n.SNA .org {\n fill: #000000;\n}\n.SNA #network-graph svg {\n width: 100%;\n height: 100%;\n}\n.SNA #sna-graph svg * {\n box-sizing: content-box;\n}\n\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px;\n }\n .SNA .node {\n background-color: #4a4e69;\n border-radius: 50%;\n color: #fff;\n font-size: 0.0625rem;\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}\n@media only screen and (max-width: 484px) {\n .SNA {\n margin-left: 0px;\n }\n}";
|
|
1404
1404
|
styleInject(css_248z);
|
|
1405
1405
|
|
|
1406
1406
|
/* eslint-disable indent */
|
|
1407
|
+
|
|
1408
|
+
/* 每張 svg 對應的 force simulation:重設、資料變更、卸載時要停掉,
|
|
1409
|
+
否則舊圖已移除,simulation 仍在背景 tick(原本 renderSNA 從未停止舊的) */
|
|
1410
|
+
var simulations = new WeakMap();
|
|
1411
|
+
var stopSimulation = function stopSimulation(svgNode) {
|
|
1412
|
+
var simulation = svgNode && simulations.get(svgNode);
|
|
1413
|
+
if (simulation) simulation.stop();
|
|
1414
|
+
};
|
|
1407
1415
|
var SNA = function SNA(props) {
|
|
1408
1416
|
// common
|
|
1409
1417
|
var className = props.className,
|
|
@@ -1478,7 +1486,13 @@ var SNA = function SNA(props) {
|
|
|
1478
1486
|
d.fx = event.x > contentWidth - 10 || event.x < 20 ? d.x : event.x;
|
|
1479
1487
|
d.fy = event.y > contentHeight - 10 || event.y < 20 ? d.y : event.y;
|
|
1480
1488
|
}
|
|
1481
|
-
|
|
1489
|
+
|
|
1490
|
+
/* 效能:拖曳結束讓模擬降溫停下(d3 慣例);節點仍固定在放開的位置(fx/fy 不清除,維持原行為)。
|
|
1491
|
+
原本沒有 end:alphaTarget 停在 0.3,拖過一次模擬就永遠不會結束,每個 tick 持續重排整張圖 */
|
|
1492
|
+
function dragended() {
|
|
1493
|
+
if (!event.active) simulation.alphaTarget(0);
|
|
1494
|
+
}
|
|
1495
|
+
return drag().on('start', dragstarted).on('drag', dragged).on('end', dragended);
|
|
1482
1496
|
};
|
|
1483
1497
|
var calculateCurve = function calculateCurve(source, target, curveLen) {
|
|
1484
1498
|
var mx = (target.x + source.x) * 0.5;
|
|
@@ -1526,7 +1540,7 @@ var SNA = function SNA(props) {
|
|
|
1526
1540
|
}).strength(1).iterations(10)).force('x', x(contentWidth / 2)).force('y', y(contentHeight / 2)).force('radial', radial(100, contentWidth / 1.5, contentHeight / 1.5));
|
|
1527
1541
|
|
|
1528
1542
|
/* 效能:SVG 先建在未掛上文件的節點,全部節點/標籤/連線建好後才一次掛進 #sna-graph(見 init 結尾)。
|
|
1529
|
-
Adobe Fonts 動態子集 kit
|
|
1543
|
+
Adobe Fonts 動態子集 kit(目前實際只有 ra 的 index.html 載入)在 body 掛 MutationObserver,
|
|
1530
1544
|
每筆 mutation 都用 TreeWalker 重掃目標整棵子樹收集文字;d3 逐一 append 進 live DOM 時,
|
|
1531
1545
|
每加一個節點就產生一筆以父層 <g> 為目標的紀錄 → O(n²),ra 1,428 個節點首次載入主執行緒凍結 39–73 秒。
|
|
1532
1546
|
離線建好再掛上,kit 只收到一筆紀錄、只掃一次 */
|
|
@@ -1586,10 +1600,16 @@ var SNA = function SNA(props) {
|
|
|
1586
1600
|
/* WCAG 1.4.4 / Freego CS2140401C:SVG 文字字型尺寸改相對單位(14px→0.875rem) */.style('font-size', '0.875rem').text(function (d) {
|
|
1587
1601
|
return d.name;
|
|
1588
1602
|
});
|
|
1589
|
-
|
|
1603
|
+
|
|
1604
|
+
/* 效能:邊標籤(textPath)只為有文字的連線建立。edgepath 的 d 每個 tick 都重寫,瀏覽器就得重排所有參照它的 textPath;
|
|
1605
|
+
各站組出的連線多半沒有 property(ra 預設 1,437 條全空),原本每個 tick 白白重排上千個空標籤 */
|
|
1606
|
+
var labeledLinks = links.filter(function (d) {
|
|
1607
|
+
return d.property !== undefined && d.property !== null && "".concat(d.property).trim() !== '';
|
|
1608
|
+
});
|
|
1609
|
+
var edgepaths = g.selectAll('.edgepath').data(labeledLinks).enter().append('path').attr('class', 'edgepath').attr('fill-opacity', 0).attr('stroke-opacity', 0).attr('id', function (d, i) {
|
|
1590
1610
|
return "edgepath".concat(i);
|
|
1591
1611
|
}).style('pointer-events', 'none');
|
|
1592
|
-
var edgelabels = g.selectAll('.edgelabel').data(
|
|
1612
|
+
var edgelabels = g.selectAll('.edgelabel').data(labeledLinks).enter().append('text').style('pointer-events', 'none').attr('class', 'edgelabel')
|
|
1593
1613
|
/* rem 需以 style 設定(SVG presentation attribute 對 rem 支援不一致) */.style('font-size', edgeLabelSize).attr('fill', '#aaa').attr('visibility', 'visible').attr('key', function (d) {
|
|
1594
1614
|
return d.type;
|
|
1595
1615
|
}).attr('id', function (d, i) {
|
|
@@ -1636,6 +1656,7 @@ var SNA = function SNA(props) {
|
|
|
1636
1656
|
});
|
|
1637
1657
|
|
|
1638
1658
|
// 一次掛上(原因見上方建立 svg 處);simulation 的 tick 由 d3-timer 排在之後的 frame,掛上前不會跑
|
|
1659
|
+
simulations.set(svg.node(), simulation$1);
|
|
1639
1660
|
var container = document.getElementById('sna-graph');
|
|
1640
1661
|
if (container) container.appendChild(svg.node());
|
|
1641
1662
|
};
|
|
@@ -1643,6 +1664,7 @@ var SNA = function SNA(props) {
|
|
|
1643
1664
|
if (SNAData && SNAData.nodes && SNAData.nodes.length > 0) {
|
|
1644
1665
|
var div = document.getElementById('sna-graph');
|
|
1645
1666
|
if (div && div.childNodes[0]) {
|
|
1667
|
+
stopSimulation(div.childNodes[0]);
|
|
1646
1668
|
div.removeChild(div.childNodes[0]);
|
|
1647
1669
|
}
|
|
1648
1670
|
init(SNAData);
|
|
@@ -1652,6 +1674,11 @@ var SNA = function SNA(props) {
|
|
|
1652
1674
|
// 資料異動或全螢幕切換,重新渲染網絡圖
|
|
1653
1675
|
useEffect(function () {
|
|
1654
1676
|
renderSNA();
|
|
1677
|
+
var div = document.getElementById('sna-graph');
|
|
1678
|
+
// 卸載或資料變更前停掉目前這張圖的 simulation(重設按鈕換過的 svg 也在同一個容器內)
|
|
1679
|
+
return function () {
|
|
1680
|
+
return stopSimulation(div && div.firstChild);
|
|
1681
|
+
};
|
|
1655
1682
|
}, [SNAData]);
|
|
1656
1683
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
1657
1684
|
className: classNames('SNA', {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daoyi/nmtl-ui",
|
|
3
3
|
"packageManager": "pnpm@10.34.5",
|
|
4
|
-
"version": "2.0.1-beta.
|
|
4
|
+
"version": "2.0.1-beta.130",
|
|
5
5
|
"description": "This project is to be used as a starter kit for building React component using Storybook and Rollup",
|
|
6
6
|
"author": "daoyi",
|
|
7
7
|
"main": "lib/index.js",
|