1+ /* eslint-disable no-undef */
12import NetJSONGraphCore from "./netjsongraph.core" ;
2- import { NetJSONGraphRender , echarts , L } from "./netjsongraph.render" ;
3- import registerLeafletSystem from "../../lib/js/echarts-leaflet/index" ;
3+ import { NetJSONGraphRender , echarts } from "./netjsongraph.render" ;
44import NetJSONGraphGUI from "./netjsongraph.gui" ;
55import attachClientsOverlay from "./netjsongraph.clients" ;
66
7+ let L ;
8+ let registerLeafletSystem ;
9+ if ( typeof __INCLUDE_LEAFLET__ !== "undefined" && __INCLUDE_LEAFLET__ ) {
10+ // eslint-disable-next-line import/no-dynamic-require,global-require
11+ const renderModule = require ( "./netjsongraph.render" ) ;
12+ // eslint-disable-next-line import/no-dynamic-require,global-require
13+ const leafletModule = require ( "../../lib/js/echarts-leaflet/index" ) ;
14+ L = renderModule . L ;
15+ registerLeafletSystem = leafletModule . default ;
16+ }
17+
718const colorTool = require ( "zrender/lib/tool/color" ) ;
819const { each} = require ( "zrender/lib/core/util" ) ;
920const env = require ( "zrender/lib/core/env" ) ;
@@ -36,12 +47,25 @@ class NetJSONGraph {
3647 * @returns {Object } - The final configuration object.
3748 */
3849 initializeConfig ( config = { } ) {
50+ let renderFunction ;
51+ if ( config . render === "map" ) {
52+ if ( typeof __INCLUDE_LEAFLET__ !== "undefined" && __INCLUDE_LEAFLET__ ) {
53+ renderFunction = NetJSONGraphRender . prototype . mapRender ;
54+ } else {
55+ const buildType =
56+ typeof __BUILD_TYPE__ !== "undefined" ? __BUILD_TYPE__ : "unknown" ;
57+ console . warn (
58+ `Map rendering not available in ${ buildType } bundle. Use complete bundle or chunked build.` ,
59+ ) ;
60+ renderFunction = NetJSONGraphRender . prototype . graphRender ;
61+ }
62+ } else {
63+ renderFunction = NetJSONGraphRender . prototype . graphRender ;
64+ }
65+
3966 return {
4067 ...config ,
41- render :
42- config . render === "map"
43- ? NetJSONGraphRender . prototype . mapRender
44- : NetJSONGraphRender . prototype . graphRender ,
68+ render : renderFunction ,
4569 onInit : this . onInit ,
4670 onRender : this . onRender ,
4771 onUpdate : this . onUpdate ,
@@ -123,33 +147,45 @@ class NetJSONGraph {
123147 this . gui . nodeLinkInfoContainer = this . gui . createNodeLinkInfoContainer ( ) ;
124148 }
125149 if ( this . config . switchMode && this . utils . isNetJSON ( this . data ) ) {
126- this . gui . renderModeSelector . onclick = ( ) => {
127- // Switch from map to graph mode, first clear canvasContainer and then render
128- if ( this . config . render === this . utils . mapRender ) {
129- this . config . render = this . utils . graphRender ;
130- const canvasContainer = this . echarts
131- . getZr ( )
132- . painter . getViewportRoot ( ) . parentNode ;
133- this . echarts . clear ( ) ;
134- this . utils . graphRender ( this . data , this ) ;
135- canvasContainer . style . background =
136- // eslint-disable-next-line no-underscore-dangle
137- this . echarts . getZr ( ) . _backgroundColor ;
138-
139- // Hide Openstreetmap credits in the bottom right corner
140- document . querySelector ( ".leaflet-control-attribution" ) . style . display = "none" ;
141- // Hide zoom control buttons in top right corner
142- document . querySelector ( ".leaflet-control-zoom" ) . style . display = "none" ;
143- } else {
144- this . echarts . clear ( ) ;
145- this . config . render = this . utils . mapRender ;
146- this . utils . mapRender ( this . data , this ) ;
147- // Show OpenStreetMap credits and zoom control buttons in map mode
148- document . querySelector ( ".leaflet-control-attribution" ) . style . display =
149- "block" ;
150- document . querySelector ( ".leaflet-control-zoom" ) . style . display = "block" ;
151- }
152- } ;
150+ if (
151+ typeof __INCLUDE_MAP_SWITCHING__ !== "undefined" &&
152+ __INCLUDE_MAP_SWITCHING__
153+ ) {
154+ this . gui . renderModeSelector . onclick = ( ) => {
155+ // Switch from map to graph mode, first clear canvasContainer and then render
156+ if ( this . config . render === this . utils . mapRender ) {
157+ this . config . render = this . utils . graphRender ;
158+ const canvasContainer = this . echarts
159+ . getZr ( )
160+ . painter . getViewportRoot ( ) . parentNode ;
161+ this . echarts . clear ( ) ;
162+ this . utils . graphRender ( this . data , this ) ;
163+ canvasContainer . style . background =
164+ // eslint-disable-next-line no-underscore-dangle
165+ this . echarts . getZr ( ) . _backgroundColor ;
166+
167+ // Hide Openstreetmap credits in the bottom right corner
168+ document . querySelector ( ".leaflet-control-attribution" ) . style . display =
169+ "none" ;
170+ // Hide zoom control buttons in top right corner
171+ document . querySelector ( ".leaflet-control-zoom" ) . style . display = "none" ;
172+ } else {
173+ this . echarts . clear ( ) ;
174+ this . config . render = this . utils . mapRender ;
175+ this . utils . mapRender ( this . data , this ) ;
176+ // Show OpenStreetMap credits and zoom control buttons in map mode
177+ document . querySelector ( ".leaflet-control-attribution" ) . style . display =
178+ "block" ;
179+ document . querySelector ( ".leaflet-control-zoom" ) . style . display = "block" ;
180+ }
181+ } ;
182+ } else {
183+ const buildType =
184+ typeof __BUILD_TYPE__ !== "undefined" ? __BUILD_TYPE__ : "unknown" ;
185+ console . warn (
186+ `switchMode not available in ${ buildType } bundle - map rendering not included` ,
187+ ) ;
188+ }
153189 }
154190 this . utils . hideLoading . call ( this ) ;
155191
@@ -160,12 +196,17 @@ class NetJSONGraph {
160196 }
161197}
162198
163- registerLeafletSystem ( echarts , L , {
164- colorTool,
165- each,
166- env,
167- } ) ;
199+ if ( typeof __INCLUDE_LEAFLET__ !== "undefined" && __INCLUDE_LEAFLET__ ) {
200+ registerLeafletSystem ( echarts , L , {
201+ colorTool,
202+ each,
203+ env,
204+ } ) ;
205+ window . L = L ;
206+ } else {
207+ const buildType = typeof __BUILD_TYPE__ !== "undefined" ? __BUILD_TYPE__ : "unknown" ;
208+ console . info ( `NetJSONGraph ${ buildType } Bundle loaded - Graph rendering only` ) ;
209+ }
168210
169211window . NetJSONGraph = NetJSONGraph ;
170212window . echarts = echarts ;
171- window . L = L ;
0 commit comments