Skip to content

Commit 628db98

Browse files
committed
[qa] Reformat JS code
1 parent 32739da commit 628db98

File tree

9 files changed

+47
-144
lines changed

9 files changed

+47
-144
lines changed

src/js/netjsonWorker.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ const operations = {
4343
const targetNode = JSONData.flatNodes[link.target];
4444
if (sourceNode && targetNode) {
4545
if (sourceNode.id === targetNode.id) {
46-
console.error(
47-
`Link source and target (${sourceNode.id}) are duplicated!`,
48-
);
46+
console.error(`Link source and target (${sourceNode.id}) are duplicated!`);
4947
return;
5048
}
5149

@@ -132,9 +130,7 @@ const operations = {
132130
if (flag) {
133131
copyArr.splice(i, 1);
134132
} else {
135-
const value = ordered
136-
? tempValueArr.join("")
137-
: tempValueArr.sort().join("");
133+
const value = ordered ? tempValueArr.join("") : tempValueArr.sort().join("");
138134
if (tempStack.indexOf(value) !== -1) {
139135
copyArr.splice(i, 1);
140136
} else {

src/js/netjsongraph.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,7 @@ const NetJSONGraphDefaultConfig = {
300300
JSONData.nodes.forEach((node) => {
301301
if (node.properties && node.properties.status) {
302302
const status = node.properties.status.toLowerCase();
303-
if (
304-
status === "ok" ||
305-
status === "problem" ||
306-
status === "critical"
307-
) {
303+
if (status === "ok" || status === "problem" || status === "critical") {
308304
node.category = status;
309305
} else {
310306
// Unrecognized status – leave category undefined to avoid test mismatches

src/js/netjsongraph.core.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ class NetJSONGraph {
128128

129129
if (resParam.length) {
130130
const renderArray = function _renderArray() {
131-
resParam.map((file) =>
132-
this.utils.JSONDataUpdate.call(this, file, false),
133-
);
131+
resParam.map((file) => this.utils.JSONDataUpdate.call(this, file, false));
134132
};
135133
this.JSONParam = [JSONParam];
136134
this.event.once("renderArray", renderArray.bind(this));

src/js/netjsongraph.geojson.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export function geojsonToNetjson(geojson) {
3232
// If the data source specifies an identifier (or label) keep it public,
3333
// otherwise generate an internal id and flag it so UI layers can hide it.
3434
const providedId = baseProps.id || baseProps.node_id || null;
35-
const displayLabel =
36-
baseProps.label || baseProps.name || providedId || null;
35+
const displayLabel = baseProps.label || baseProps.name || providedId || null;
3736

3837
const newId = providedId ? String(providedId) : `gjn_${nodes.length}`;
3938
const generatedIdentity = !providedId;
@@ -80,17 +79,11 @@ export function geojsonToNetjson(geojson) {
8079
createNode(coordinates, {...props, _featureType: "Point"});
8180
break;
8281
case "MultiPoint":
83-
coordinates.forEach((pt) =>
84-
createNode(pt, {...props, _featureType: "Point"}),
85-
);
82+
coordinates.forEach((pt) => createNode(pt, {...props, _featureType: "Point"}));
8683
break;
8784
case "LineString":
8885
// Tag nodes coming from line geometries
89-
processCoordsSeq(
90-
coordinates,
91-
{...props, _featureType: "LineString"},
92-
false,
93-
);
86+
processCoordsSeq(coordinates, {...props, _featureType: "LineString"}, false);
9487
break;
9588
case "MultiLineString":
9689
coordinates.forEach((line) =>
@@ -114,9 +107,7 @@ export function geojsonToNetjson(geojson) {
114107
const baseProps = {
115108
...(feature.properties || {}),
116109
// Preserve original GeoJSON feature id (location primary-key) if present.
117-
...(feature.id !== undefined && feature.id !== null
118-
? {id: feature.id}
119-
: {}),
110+
...(feature.id !== undefined && feature.id !== null ? {id: feature.id} : {}),
120111
};
121112

122113
handleGeometry(feature.geometry, baseProps);
@@ -175,8 +166,7 @@ export function addPolygonOverlays(self) {
175166
...defaultStyle,
176167
...(self.config.geoOptions && self.config.geoOptions.style),
177168
};
178-
if (echartsStyle.areaColor)
179-
leafletStyle.fillColor = echartsStyle.areaColor;
169+
if (echartsStyle.areaColor) leafletStyle.fillColor = echartsStyle.areaColor;
180170
if (echartsStyle.color) leafletStyle.color = echartsStyle.color;
181171
if (typeof echartsStyle.opacity !== "undefined")
182172
leafletStyle.fillOpacity = echartsStyle.opacity;

src/js/netjsongraph.gui.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class NetJSONGraphGUI {
3636
sideBar.classList.toggle("hidden");
3737
const metaInfo = document.querySelector(".njg-metaInfoContainer");
3838
if (
39-
(this.self.config.showMetaOnNarrowScreens ||
40-
this.self.el.clientWidth > 850) &&
39+
(this.self.config.showMetaOnNarrowScreens || this.self.el.clientWidth > 850) &&
4140
metaInfo
4241
) {
4342
metaInfo.style.display = "flex";
@@ -48,10 +47,7 @@ class NetJSONGraphGUI {
4847
}
4948

5049
hideInfoOnNarrowScreen() {
51-
if (
52-
!this.self.config.showMetaOnNarrowScreens &&
53-
this.self.el.clientWidth < 850
54-
) {
50+
if (!this.self.config.showMetaOnNarrowScreens && this.self.el.clientWidth < 850) {
5551
this.metaInfoContainer.style.display = "none";
5652
}
5753

@@ -102,11 +98,8 @@ class NetJSONGraphGUI {
10298
}
10399

104100
getNodeLinkInfo(type, data) {
105-
const nodeLinkInfoChildren =
106-
document.querySelectorAll(".njg-infoContainer");
107-
const headerInfoChildren = document.querySelectorAll(
108-
".njg-headerContainer",
109-
);
101+
const nodeLinkInfoChildren = document.querySelectorAll(".njg-infoContainer");
102+
const headerInfoChildren = document.querySelectorAll(".njg-headerContainer");
110103
for (let i = 0; i < nodeLinkInfoChildren.length; i += 1) {
111104
nodeLinkInfoChildren[i].remove();
112105
}
@@ -158,8 +151,7 @@ class NetJSONGraphGUI {
158151
} else {
159152
keyLabel.innerHTML = key;
160153
// Preserve multiline values
161-
const displayVal =
162-
typeof val === "string" ? val.replace(/\n/g, "<br/>") : val;
154+
const displayVal = typeof val === "string" ? val.replace(/\n/g, "<br/>") : val;
163155
valueLabel.innerHTML = displayVal;
164156
}
165157

src/js/netjsongraph.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,17 @@ class NetJSONGraph {
136136
this.echarts.getZr()._backgroundColor;
137137

138138
// Hide Openstreetmap credits in the bottom right corner
139-
document.querySelector(".leaflet-control-attribution").style.display =
140-
"none";
139+
document.querySelector(".leaflet-control-attribution").style.display = "none";
141140
// Hide zoom control buttons in top right corner
142-
document.querySelector(".leaflet-control-zoom").style.display =
143-
"none";
141+
document.querySelector(".leaflet-control-zoom").style.display = "none";
144142
} else {
145143
this.echarts.clear();
146144
this.config.render = this.utils.mapRender;
147145
this.utils.mapRender(this.data, this);
148146
// Show OpenStreetMap credits and zoom control buttons in map mode
149147
document.querySelector(".leaflet-control-attribution").style.display =
150148
"block";
151-
document.querySelector(".leaflet-control-zoom").style.display =
152-
"block";
149+
document.querySelector(".leaflet-control-zoom").style.display = "block";
153150
}
154151
};
155152
}

src/js/netjsongraph.render.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import * as echarts from "echarts/core";
2-
import {
3-
GraphChart,
4-
EffectScatterChart,
5-
LinesChart,
6-
ScatterChart,
7-
} from "echarts/charts";
2+
import {GraphChart, EffectScatterChart, LinesChart, ScatterChart} from "echarts/charts";
83
import {
94
TooltipComponent,
105
TitleComponent,
@@ -161,8 +156,7 @@ class NetJSONGraphRender {
161156

162157
const series = [
163158
Object.assign(configs.graphConfig.series, {
164-
type:
165-
configs.graphConfig.series.type === "graphGL" ? "graphGL" : "graph",
159+
type: configs.graphConfig.series.type === "graphGL" ? "graphGL" : "graph",
166160
layout:
167161
configs.graphConfig.series.type === "graphGL"
168162
? "forceAtlas2"
@@ -229,11 +223,7 @@ class NetJSONGraphRender {
229223
if (!location || !location.lng || !location.lat) {
230224
console.error(`Node ${node.id} position is undefined!`);
231225
} else {
232-
const {nodeEmphasisConfig} = self.utils.getNodeStyle(
233-
node,
234-
configs,
235-
"map",
236-
);
226+
const {nodeEmphasisConfig} = self.utils.getNodeStyle(node, configs, "map");
237227

238228
nodesData.push({
239229
name: typeof node.label === "string" ? node.label : "",
@@ -340,8 +330,7 @@ class NetJSONGraphRender {
340330
: nodeSizeConfig;
341331
}
342332
return (
343-
(configs.mapOptions.nodeConfig &&
344-
configs.mapOptions.nodeConfig.nodeSize) ||
333+
(configs.mapOptions.nodeConfig && configs.mapOptions.nodeConfig.nodeSize) ||
345334
17
346335
);
347336
},
@@ -374,10 +363,7 @@ class NetJSONGraphRender {
374363
*
375364
*/
376365
graphRender(JSONData, self) {
377-
self.utils.echartsSetOption(
378-
self.utils.generateGraphOption(JSONData, self),
379-
self,
380-
);
366+
self.utils.echartsSetOption(self.utils.generateGraphOption(JSONData, self), self);
381367

382368
window.onresize = () => {
383369
self.echarts.resize();
@@ -553,29 +539,22 @@ class NetJSONGraphRender {
553539
self.leaflet.getZoom() >= self.config.loadMoreAtZoomLevel &&
554540
self.hasMoreData
555541
) {
556-
const data = await self.utils.getBBoxData.call(
557-
self,
558-
self.JSONParam,
559-
bounds,
560-
);
542+
const data = await self.utils.getBBoxData.call(self, self.JSONParam, bounds);
561543
self.config.prepareData.call(self, data);
562544
const dataNodeSet = new Set(self.data.nodes.map((n) => n.id));
563545
const sourceLinkSet = new Set(self.data.links.map((l) => l.source));
564546
const targetLinkSet = new Set(self.data.links.map((l) => l.target));
565547
const nodes = data.nodes.filter((node) => !dataNodeSet.has(node.id));
566548
const links = data.links.filter(
567-
(link) =>
568-
!sourceLinkSet.has(link.source) && !targetLinkSet.has(link.target),
549+
(link) => !sourceLinkSet.has(link.source) && !targetLinkSet.has(link.target),
569550
);
570551
const boundsDataSet = new Set(data.nodes.map((n) => n.id));
571552
const nonCommonNodes = self.bboxData.nodes.filter(
572553
(node) => !boundsDataSet.has(node.id),
573554
);
574555
const removableNodes = new Set(nonCommonNodes.map((n) => n.id));
575556

576-
JSONData.nodes = JSONData.nodes.filter(
577-
(node) => !removableNodes.has(node.id),
578-
);
557+
JSONData.nodes = JSONData.nodes.filter((node) => !removableNodes.has(node.id));
579558
self.bboxData.nodes = self.bboxData.nodes.concat(nodes);
580559
self.bboxData.links = self.bboxData.links.concat(links);
581560
JSONData = {
@@ -593,8 +572,7 @@ class NetJSONGraphRender {
593572
self.config.clustering &&
594573
self.config.clusteringThreshold < JSONData.nodes.length
595574
) {
596-
let {clusters, nonClusterNodes, nonClusterLinks} =
597-
self.utils.makeCluster(self);
575+
let {clusters, nonClusterNodes, nonClusterLinks} = self.utils.makeCluster(self);
598576

599577
// Only show clusters if we're below the disableClusteringAtLevel
600578
if (self.leaflet.getZoom() > self.config.disableClusteringAtLevel) {
@@ -623,10 +601,7 @@ class NetJSONGraphRender {
623601
) {
624602
// Zoom into the clicked cluster instead of expanding it
625603
const currentZoom = self.leaflet.getZoom();
626-
const targetZoom = Math.min(
627-
currentZoom + 2,
628-
self.leaflet.getMaxZoom(),
629-
);
604+
const targetZoom = Math.min(currentZoom + 2, self.leaflet.getMaxZoom());
630605
self.leaflet.setView(
631606
[params.data.value[1], params.data.value[0]],
632607
targetZoom,
@@ -741,9 +716,7 @@ class NetJSONGraphRender {
741716
return true;
742717
}
743718
if (existingNodeIds.has(node.id)) {
744-
console.warn(
745-
`Duplicate node ID ${node.id} detected during merge and skipped.`,
746-
);
719+
console.warn(`Duplicate node ID ${node.id} detected during merge and skipped.`);
747720
return false;
748721
}
749722
return true;

src/js/netjsongraph.update.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class NetJSONGraphUpdate extends NetJSONGraphUtil {
4343

4444
if (
4545
!window.history.state ||
46-
(window.history.state &&
47-
window.history.state.searchValue !== searchValue)
46+
(window.history.state && window.history.state.searchValue !== searchValue)
4847
) {
4948
window.history.pushState({searchValue}, "");
5049
return self.utils.JSONDataUpdate.call(

0 commit comments

Comments
 (0)