Skip to content

Commit a588f58

Browse files
committed
format src/js/netjsongraph.render.js
1 parent 6ee9f8d commit a588f58

File tree

1 file changed

+69
-31
lines changed

1 file changed

+69
-31
lines changed

src/js/netjsongraph.render.js

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as echarts from "echarts/core";
2-
import {GraphChart, EffectScatterChart, LinesChart, ScatterChart} from "echarts/charts";
2+
import {
3+
GraphChart,
4+
EffectScatterChart,
5+
LinesChart,
6+
ScatterChart,
7+
} from "echarts/charts";
38
import {
49
TooltipComponent,
510
TitleComponent,
@@ -200,7 +205,8 @@ class NetJSONGraphRender {
200205
{
201206
...baseGraphSeries,
202207
id: "network-graph",
203-
type: configs.graphConfig.series.type === "graphGL" ? "graphGL" : "graph",
208+
type:
209+
configs.graphConfig.series.type === "graphGL" ? "graphGL" : "graph",
204210
layout:
205211
configs.graphConfig.series.type === "graphGL"
206212
? "forceAtlas2"
@@ -267,7 +273,11 @@ class NetJSONGraphRender {
267273
if (!location || !location.lng || !location.lat) {
268274
console.error(`Node ${node.id} position is undefined!`);
269275
} else {
270-
const {nodeEmphasisConfig} = self.utils.getNodeStyle(node, configs, "map");
276+
const {nodeEmphasisConfig} = self.utils.getNodeStyle(
277+
node,
278+
configs,
279+
"map",
280+
);
271281

272282
let nodeName = "";
273283
if (typeof node.label === "string") {
@@ -384,7 +394,8 @@ class NetJSONGraphRender {
384394
: nodeSizeConfig;
385395
}
386396
return (
387-
(configs.mapOptions.nodeConfig && configs.mapOptions.nodeConfig.nodeSize) ||
397+
(configs.mapOptions.nodeConfig &&
398+
configs.mapOptions.nodeConfig.nodeSize) ||
388399
17
389400
);
390401
},
@@ -418,7 +429,10 @@ class NetJSONGraphRender {
418429
*
419430
*/
420431
graphRender(JSONData, self) {
421-
self.utils.echartsSetOption(self.utils.generateGraphOption(JSONData, self), self);
432+
self.utils.echartsSetOption(
433+
self.utils.generateGraphOption(JSONData, self),
434+
self,
435+
);
422436

423437
window.onresize = () => {
424438
self.echarts.resize();
@@ -427,26 +441,37 @@ class NetJSONGraphRender {
427441
// Enable wheel zoom outside graph area
428442
const dom = self.echarts.getDom && self.echarts.getDom();
429443
if (dom) {
430-
dom.addEventListener("wheel", (e) => {
431-
const rect = dom.getBoundingClientRect();
432-
if (e.clientX < rect.left || e.clientX > rect.right || e.clientY < rect.top || e.clientY > rect.bottom) {
433-
return;
434-
}
435-
e.preventDefault();
436-
const canvas = dom.querySelector('canvas');
437-
if (canvas) {
438-
const r = canvas.getBoundingClientRect();
439-
canvas.dispatchEvent(new WheelEvent('wheel', {
440-
bubbles: true,
441-
cancelable: true,
442-
view: window,
443-
clientX: r.left + r.width / 2,
444-
clientY: r.top + r.height / 2,
445-
deltaY: -e.deltaY,
446-
deltaMode: e.deltaMode,
447-
}));
448-
}
449-
}, {passive: false});
444+
dom.addEventListener(
445+
"wheel",
446+
(e) => {
447+
const rect = dom.getBoundingClientRect();
448+
if (
449+
e.clientX < rect.left ||
450+
e.clientX > rect.right ||
451+
e.clientY < rect.top ||
452+
e.clientY > rect.bottom
453+
) {
454+
return;
455+
}
456+
e.preventDefault();
457+
const canvas = dom.querySelector("canvas");
458+
if (canvas) {
459+
const r = canvas.getBoundingClientRect();
460+
canvas.dispatchEvent(
461+
new WheelEvent("wheel", {
462+
bubbles: true,
463+
cancelable: true,
464+
view: window,
465+
clientX: r.left + r.width / 2,
466+
clientY: r.top + r.height / 2,
467+
deltaY: -e.deltaY,
468+
deltaMode: e.deltaMode,
469+
}),
470+
);
471+
}
472+
},
473+
{passive: false},
474+
);
450475
}
451476

452477
// Toggle labels on zoom threshold crossing
@@ -640,22 +665,29 @@ class NetJSONGraphRender {
640665
self.leaflet.getZoom() >= self.config.loadMoreAtZoomLevel &&
641666
self.hasMoreData
642667
) {
643-
const data = await self.utils.getBBoxData.call(self, self.JSONParam, bounds);
668+
const data = await self.utils.getBBoxData.call(
669+
self,
670+
self.JSONParam,
671+
bounds,
672+
);
644673
self.config.prepareData.call(self, data);
645674
const dataNodeSet = new Set(self.data.nodes.map((n) => n.id));
646675
const sourceLinkSet = new Set(self.data.links.map((l) => l.source));
647676
const targetLinkSet = new Set(self.data.links.map((l) => l.target));
648677
const nodes = data.nodes.filter((node) => !dataNodeSet.has(node.id));
649678
const links = data.links.filter(
650-
(link) => !sourceLinkSet.has(link.source) && !targetLinkSet.has(link.target),
679+
(link) =>
680+
!sourceLinkSet.has(link.source) && !targetLinkSet.has(link.target),
651681
);
652682
const boundsDataSet = new Set(data.nodes.map((n) => n.id));
653683
const nonCommonNodes = self.bboxData.nodes.filter(
654684
(node) => !boundsDataSet.has(node.id),
655685
);
656686
const removableNodes = new Set(nonCommonNodes.map((n) => n.id));
657687

658-
JSONData.nodes = JSONData.nodes.filter((node) => !removableNodes.has(node.id));
688+
JSONData.nodes = JSONData.nodes.filter(
689+
(node) => !removableNodes.has(node.id),
690+
);
659691
self.bboxData.nodes = self.bboxData.nodes.concat(nodes);
660692
self.bboxData.links = self.bboxData.links.concat(links);
661693
JSONData = {
@@ -673,7 +705,8 @@ class NetJSONGraphRender {
673705
self.config.clustering &&
674706
self.config.clusteringThreshold < JSONData.nodes.length
675707
) {
676-
let {clusters, nonClusterNodes, nonClusterLinks} = self.utils.makeCluster(self);
708+
let {clusters, nonClusterNodes, nonClusterLinks} =
709+
self.utils.makeCluster(self);
677710

678711
// Only show clusters if we're below the disableClusteringAtLevel
679712
if (self.leaflet.getZoom() > self.config.disableClusteringAtLevel) {
@@ -702,7 +735,10 @@ class NetJSONGraphRender {
702735
) {
703736
// Zoom into the clicked cluster instead of expanding it
704737
const currentZoom = self.leaflet.getZoom();
705-
const targetZoom = Math.min(currentZoom + 2, self.leaflet.getMaxZoom());
738+
const targetZoom = Math.min(
739+
currentZoom + 2,
740+
self.leaflet.getMaxZoom(),
741+
);
706742
self.leaflet.setView(
707743
[params.data.value[1], params.data.value[0]],
708744
targetZoom,
@@ -817,7 +853,9 @@ class NetJSONGraphRender {
817853
return true;
818854
}
819855
if (existingNodeIds.has(node.id)) {
820-
console.warn(`Duplicate node ID ${node.id} detected during merge and skipped.`);
856+
console.warn(
857+
`Duplicate node ID ${node.id} detected during merge and skipped.`,
858+
);
821859
return false;
822860
}
823861
return true;

0 commit comments

Comments
 (0)