Skip to content

Commit 5087086

Browse files
committed
Fix map label visibility, resolve variable shadowing, and rename config parameter
1 parent 3a5f95d commit 5087086

2 files changed

Lines changed: 49 additions & 20 deletions

File tree

src/js/netjsongraph.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,11 @@ const NetJSONGraphDefaultConfig = {
301301
JSONData.nodes.forEach((node) => {
302302
if (node.properties && node.properties.status) {
303303
const status = node.properties.status.toLowerCase();
304-
if (status === "ok" || status === "problem" || status === "critical") {
304+
if (
305+
status === "ok" ||
306+
status === "problem" ||
307+
status === "critical"
308+
) {
305309
node.category = status;
306310
} else {
307311
// Unrecognized status – leave category undefined to avoid test mismatches
@@ -338,7 +342,7 @@ const NetJSONGraphDefaultConfig = {
338342
this.gui.metaInfoContainer.style.display = "flex";
339343
}
340344
} else {
341-
({ nodeLinkData } = { nodeLinkData: data });
345+
({nodeLinkData} = {nodeLinkData: data});
342346
}
343347

344348
this.gui.getNodeLinkInfo(type, nodeLinkData);
@@ -354,8 +358,8 @@ const NetJSONGraphDefaultConfig = {
354358
*
355359
*/
356360
/* istanbul ignore next */
357-
onReady() { },
361+
onReady() {},
358362
};
359363

360-
export const { prepareData } = NetJSONGraphDefaultConfig;
361-
export default { ...NetJSONGraphDefaultConfig };
364+
export const {prepareData} = NetJSONGraphDefaultConfig;
365+
export default {...NetJSONGraphDefaultConfig};

src/js/netjsongraph.render.js

Lines changed: 40 additions & 15 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();
@@ -547,7 +561,8 @@ class NetJSONGraphRender {
547561

548562
const currentZoom = self.leaflet.getZoom();
549563
const showLabel =
550-
typeof showMapLabelsAtZoom === "number" && currentZoom >= showMapLabelsAtZoom;
564+
typeof showMapLabelsAtZoom === "number" &&
565+
currentZoom >= showMapLabelsAtZoom;
551566

552567
if (!showLabel) {
553568
self.echarts.setOption({
@@ -595,13 +610,13 @@ class NetJSONGraphRender {
595610
const zoomOut = document.querySelector(".leaflet-control-zoom-out");
596611

597612
if (zoomIn && zoomOut) {
598-
if (Math.round(currentZoom) >= maxZoom) {
613+
if (Math.round(cZoom) >= maxZoom) {
599614
zoomIn.classList.add("leaflet-disabled");
600615
} else {
601616
zoomIn.classList.remove("leaflet-disabled");
602617
}
603618

604-
if (Math.round(currentZoom) <= minZoom) {
619+
if (Math.round(cZoom) <= minZoom) {
605620
zoomOut.classList.add("leaflet-disabled");
606621
} else {
607622
zoomOut.classList.remove("leaflet-disabled");
@@ -630,22 +645,29 @@ class NetJSONGraphRender {
630645
self.leaflet.getZoom() >= self.config.loadMoreAtZoomLevel &&
631646
self.hasMoreData
632647
) {
633-
const data = await self.utils.getBBoxData.call(self, self.JSONParam, bounds);
648+
const data = await self.utils.getBBoxData.call(
649+
self,
650+
self.JSONParam,
651+
bounds,
652+
);
634653
self.config.prepareData.call(self, data);
635654
const dataNodeSet = new Set(self.data.nodes.map((n) => n.id));
636655
const sourceLinkSet = new Set(self.data.links.map((l) => l.source));
637656
const targetLinkSet = new Set(self.data.links.map((l) => l.target));
638657
const nodes = data.nodes.filter((node) => !dataNodeSet.has(node.id));
639658
const links = data.links.filter(
640-
(link) => !sourceLinkSet.has(link.source) && !targetLinkSet.has(link.target),
659+
(link) =>
660+
!sourceLinkSet.has(link.source) && !targetLinkSet.has(link.target),
641661
);
642662
const boundsDataSet = new Set(data.nodes.map((n) => n.id));
643663
const nonCommonNodes = self.bboxData.nodes.filter(
644664
(node) => !boundsDataSet.has(node.id),
645665
);
646666
const removableNodes = new Set(nonCommonNodes.map((n) => n.id));
647667

648-
JSONData.nodes = JSONData.nodes.filter((node) => !removableNodes.has(node.id));
668+
JSONData.nodes = JSONData.nodes.filter(
669+
(node) => !removableNodes.has(node.id),
670+
);
649671
self.bboxData.nodes = self.bboxData.nodes.concat(nodes);
650672
self.bboxData.links = self.bboxData.links.concat(links);
651673
JSONData = {
@@ -663,7 +685,8 @@ class NetJSONGraphRender {
663685
self.config.clustering &&
664686
self.config.clusteringThreshold < JSONData.nodes.length
665687
) {
666-
let { clusters, nonClusterNodes, nonClusterLinks } = self.utils.makeCluster(self);
688+
let { clusters, nonClusterNodes, nonClusterLinks } =
689+
self.utils.makeCluster(self);
667690

668691
// Only show clusters if we're below the disableClusteringAtLevel
669692
if (self.leaflet.getZoom() > self.config.disableClusteringAtLevel) {
@@ -691,8 +714,8 @@ class NetJSONGraphRender {
691714
params.data.cluster
692715
) {
693716
// Zoom into the clicked cluster instead of expanding it
694-
const currentZoom = self.leaflet.getZoom();
695-
const targetZoom = Math.min(currentZoom + 2, self.leaflet.getMaxZoom());
717+
const zoomLevel = self.leaflet.getZoom();
718+
const targetZoom = Math.min(zoomLevel + 2, self.leaflet.getMaxZoom());
696719
self.leaflet.setView(
697720
[params.data.value[1], params.data.value[0]],
698721
targetZoom,
@@ -807,7 +830,9 @@ class NetJSONGraphRender {
807830
return true;
808831
}
809832
if (existingNodeIds.has(node.id)) {
810-
console.warn(`Duplicate node ID ${node.id} detected during merge and skipped.`);
833+
console.warn(
834+
`Duplicate node ID ${node.id} detected during merge and skipped.`,
835+
);
811836
return false;
812837
}
813838
return true;

0 commit comments

Comments
 (0)