11import * 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" ;
38import {
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 ( ) ;
@@ -535,7 +549,22 @@ class NetJSONGraphRender {
535549 }
536550 }
537551
538- if ( self . leaflet . getZoom ( ) < self . config . showLabelsAtZoomLevel ) {
552+ // 4. Resolve label visibility threshold
553+ let { showMapLabelsAtZoom} = self . config ;
554+ if ( showMapLabelsAtZoom === undefined ) {
555+ if ( self . config . showLabelsAtZoomLevel !== undefined ) {
556+ showMapLabelsAtZoom = self . config . showLabelsAtZoomLevel ;
557+ } else {
558+ showMapLabelsAtZoom = 13 ;
559+ }
560+ }
561+
562+ const currentZoom = self . leaflet . getZoom ( ) ;
563+ const showLabel =
564+ typeof showMapLabelsAtZoom === "number" &&
565+ currentZoom >= showMapLabelsAtZoom ;
566+
567+ if ( ! showLabel ) {
539568 self . echarts . setOption ( {
540569 series : [
541570 {
@@ -554,18 +583,18 @@ class NetJSONGraphRender {
554583 }
555584
556585 self . leaflet . on ( "zoomend" , ( ) => {
557- const currentZoom = self . leaflet . getZoom ( ) ;
558- const showLabel = currentZoom >= self . config . showLabelsAtZoomLevel ;
586+ const cZoom = self . leaflet . getZoom ( ) ;
587+ const sLabel = cZoom >= self . config . showLabelsAtZoomLevel ;
559588 self . echarts . setOption ( {
560589 series : [
561590 {
562591 id : "geo-map" ,
563592 label : {
564- show : showLabel ,
593+ show : sLabel ,
565594 } ,
566595 emphasis : {
567596 label : {
568- show : showLabel ,
597+ show : false ,
569598 } ,
570599 } ,
571600 } ,
@@ -580,13 +609,13 @@ class NetJSONGraphRender {
580609 const zoomOut = document . querySelector ( ".leaflet-control-zoom-out" ) ;
581610
582611 if ( zoomIn && zoomOut ) {
583- if ( Math . round ( currentZoom ) >= maxZoom ) {
612+ if ( Math . round ( cZoom ) >= maxZoom ) {
584613 zoomIn . classList . add ( "leaflet-disabled" ) ;
585614 } else {
586615 zoomIn . classList . remove ( "leaflet-disabled" ) ;
587616 }
588617
589- if ( Math . round ( currentZoom ) <= minZoom ) {
618+ if ( Math . round ( cZoom ) <= minZoom ) {
590619 zoomOut . classList . add ( "leaflet-disabled" ) ;
591620 } else {
592621 zoomOut . classList . remove ( "leaflet-disabled" ) ;
@@ -615,22 +644,29 @@ class NetJSONGraphRender {
615644 self . leaflet . getZoom ( ) >= self . config . loadMoreAtZoomLevel &&
616645 self . hasMoreData
617646 ) {
618- const data = await self . utils . getBBoxData . call ( self , self . JSONParam , bounds ) ;
647+ const data = await self . utils . getBBoxData . call (
648+ self ,
649+ self . JSONParam ,
650+ bounds ,
651+ ) ;
619652 self . config . prepareData . call ( self , data ) ;
620653 const dataNodeSet = new Set ( self . data . nodes . map ( ( n ) => n . id ) ) ;
621654 const sourceLinkSet = new Set ( self . data . links . map ( ( l ) => l . source ) ) ;
622655 const targetLinkSet = new Set ( self . data . links . map ( ( l ) => l . target ) ) ;
623656 const nodes = data . nodes . filter ( ( node ) => ! dataNodeSet . has ( node . id ) ) ;
624657 const links = data . links . filter (
625- ( link ) => ! sourceLinkSet . has ( link . source ) && ! targetLinkSet . has ( link . target ) ,
658+ ( link ) =>
659+ ! sourceLinkSet . has ( link . source ) && ! targetLinkSet . has ( link . target ) ,
626660 ) ;
627661 const boundsDataSet = new Set ( data . nodes . map ( ( n ) => n . id ) ) ;
628662 const nonCommonNodes = self . bboxData . nodes . filter (
629663 ( node ) => ! boundsDataSet . has ( node . id ) ,
630664 ) ;
631665 const removableNodes = new Set ( nonCommonNodes . map ( ( n ) => n . id ) ) ;
632666
633- JSONData . nodes = JSONData . nodes . filter ( ( node ) => ! removableNodes . has ( node . id ) ) ;
667+ JSONData . nodes = JSONData . nodes . filter (
668+ ( node ) => ! removableNodes . has ( node . id ) ,
669+ ) ;
634670 self . bboxData . nodes = self . bboxData . nodes . concat ( nodes ) ;
635671 self . bboxData . links = self . bboxData . links . concat ( links ) ;
636672 JSONData = {
@@ -648,7 +684,8 @@ class NetJSONGraphRender {
648684 self . config . clustering &&
649685 self . config . clusteringThreshold < JSONData . nodes . length
650686 ) {
651- let { clusters, nonClusterNodes, nonClusterLinks} = self . utils . makeCluster ( self ) ;
687+ let { clusters, nonClusterNodes, nonClusterLinks} =
688+ self . utils . makeCluster ( self ) ;
652689
653690 // Only show clusters if we're below the disableClusteringAtLevel
654691 if ( self . leaflet . getZoom ( ) > self . config . disableClusteringAtLevel ) {
@@ -676,8 +713,8 @@ class NetJSONGraphRender {
676713 params . data . cluster
677714 ) {
678715 // Zoom into the clicked cluster instead of expanding it
679- const currentZoom = self . leaflet . getZoom ( ) ;
680- const targetZoom = Math . min ( currentZoom + 2 , self . leaflet . getMaxZoom ( ) ) ;
716+ const NewZoom = self . leaflet . getZoom ( ) ;
717+ const targetZoom = Math . min ( NewZoom + 2 , self . leaflet . getMaxZoom ( ) ) ;
681718 self . leaflet . setView (
682719 [ params . data . value [ 1 ] , params . data . value [ 0 ] ] ,
683720 targetZoom ,
@@ -792,7 +829,9 @@ class NetJSONGraphRender {
792829 return true ;
793830 }
794831 if ( existingNodeIds . has ( node . id ) ) {
795- console . warn ( `Duplicate node ID ${ node . id } detected during merge and skipped.` ) ;
832+ console . warn (
833+ `Duplicate node ID ${ node . id } detected during merge and skipped.` ,
834+ ) ;
796835 return false ;
797836 }
798837 return true ;
0 commit comments