@@ -25,6 +25,7 @@ import {
2525 initSide ,
2626 setLocale ,
2727 expandNode ,
28+ refresh ,
2829} from './interact'
2930import {
3031 processPrimaryNode ,
@@ -43,8 +44,6 @@ import mobileMenu from './plugin/mobileMenu'
4344import Bus from './utils/pubsub'
4445
4546import './index.less'
46- import './plugin/toolBar.less'
47- import './plugin/mobileMenu.less'
4847
4948import './iconfont/iconfont.js'
5049
@@ -109,10 +108,20 @@ export interface MindElixirInstance {
109108 primaryNodeVerticalGap : number ,
110109 mobileMenu : boolean ,
111110
111+ container : HTMLElement ,
112+ map : HTMLElement ,
113+ root : HTMLElement ,
114+ box : HTMLElement ,
115+ svg2nd : SVGElement ,
116+ linkController :SVGElement ,
117+ P2 : HTMLElement ,
118+ P3 : HTMLElement ,
119+ line1 :SVGElement ,
120+ line2 :SVGElement ,
121+ linkSvgGroup :SVGElement ,
112122}
113123export interface Options {
114124 el : string | Element ,
115- data : MindElixirData ,
116125 direction ?: number ,
117126 locale ?: string ,
118127 draggable ?: boolean ,
@@ -134,7 +143,6 @@ export interface Options {
134143const $d = document
135144function MindElixir ( this : MindElixirInstance , {
136145 el,
137- data,
138146 direction,
139147 locale,
140148 draggable,
@@ -156,8 +164,6 @@ function MindElixir(this: MindElixirInstance, {
156164 }
157165 if ( ! box ) return new Error ( 'MindElixir: el is not a valid element' )
158166 this . mindElixirBox = box
159- this . nodeData = data . nodeData
160- this . linkData = data . linkData || { }
161167 this . locale = locale
162168 this . toolBar = toolBar === undefined ? true : toolBar
163169 this . keypress = keypress === undefined ? true : keypress
@@ -194,6 +200,52 @@ function MindElixir(this: MindElixirInstance, {
194200 // console.log(operation, this.history)
195201 }
196202 } )
203+
204+ console . log ( 'ME_version ' + MindElixir . version )
205+ this . mindElixirBox . className += ' mind-elixir'
206+ this . mindElixirBox . innerHTML = ''
207+
208+ this . container = $d . createElement ( 'div' ) // map container
209+ this . container . className = 'map-container'
210+
211+ if ( this . overflowHidden ) this . container . style . overflow = 'hidden'
212+
213+ this . map = $d . createElement ( 'div' ) // map-canvas Element
214+ this . map . className = 'map-canvas'
215+ this . map . setAttribute ( 'tabindex' , '0' )
216+ this . container . appendChild ( this . map )
217+ this . mindElixirBox . appendChild ( this . container )
218+ this . root = $d . createElement ( 'root' )
219+
220+ this . box = $d . createElement ( 'children' )
221+ this . box . className = 'box'
222+
223+ // infrastructure
224+
225+ this . svg2nd = createLinkSvg ( 'svg2nd' ) // main link container
226+
227+ this . linkController = createLinkSvg ( 'linkcontroller' ) // bezier controller container
228+ this . P2 = $d . createElement ( 'div' ) // bezier P2
229+ this . P3 = $d . createElement ( 'div' ) // bezier P3
230+ this . P2 . className = this . P3 . className = 'circle'
231+ this . line1 = createLine ( 0 , 0 , 0 , 0 ) // bezier auxiliary line1
232+ this . line2 = createLine ( 0 , 0 , 0 , 0 ) // bezier auxiliary line2
233+ this . linkController . appendChild ( this . line1 )
234+ this . linkController . appendChild ( this . line2 )
235+
236+ this . linkSvgGroup = createLinkSvg ( 'topiclinks' ) // storage user custom link svg
237+
238+ this . map . appendChild ( this . root )
239+ this . map . appendChild ( this . box )
240+ this . map . appendChild ( this . svg2nd )
241+ this . map . appendChild ( this . linkController )
242+ this . map . appendChild ( this . linkSvgGroup )
243+ this . map . appendChild ( this . P2 )
244+ this . map . appendChild ( this . P3 )
245+
246+ if ( this . overflowHidden ) {
247+ this . container . style . overflow = 'hidden'
248+ } else initMouseEvent ( this )
197249}
198250
199251MindElixir . prototype = {
@@ -226,60 +278,11 @@ MindElixir.prototype = {
226278 initSide,
227279 setLocale,
228280 expandNode,
281+ refresh,
229282
230- init : function ( ) {
231- /**
232- * @function
233- * @global
234- * @name E
235- * @param {string } id Node id.
236- * @return {TargetElement } Target element.
237- * @example
238- * E('bd4313fbac40284b')
239- */
240- addParentLink ( this . nodeData )
241- console . log ( 'ME_version ' + MindElixir . version )
242- this . mindElixirBox . className += ' mind-elixir'
243- this . mindElixirBox . innerHTML = ''
244-
245- this . container = $d . createElement ( 'div' ) // map container
246- this . container . className = 'map-container'
247-
248- if ( this . overflowHidden ) this . container . style . overflow = 'hidden'
249-
250- this . map = $d . createElement ( 'div' ) // map-canvas Element
251- this . map . className = 'map-canvas'
252- this . map . setAttribute ( 'tabindex' , '0' )
253- this . container . appendChild ( this . map )
254- this . mindElixirBox . appendChild ( this . container )
255- this . root = $d . createElement ( 'root' )
256-
257- this . box = $d . createElement ( 'children' )
258- this . box . className = 'box'
259-
260- // infrastructure
261-
262- this . svg2nd = createLinkSvg ( 'svg2nd' ) // main link container
263-
264- this . linkController = createLinkSvg ( 'linkcontroller' ) // bezier controller container
265- this . P2 = $d . createElement ( 'div' ) // bezier P2
266- this . P3 = $d . createElement ( 'div' ) // bezier P3
267- this . P2 . className = this . P3 . className = 'circle'
268- this . line1 = createLine ( 0 , 0 , 0 , 0 ) // bezier auxiliary line1
269- this . line2 = createLine ( 0 , 0 , 0 , 0 ) // bezier auxiliary line2
270- this . linkController . appendChild ( this . line1 )
271- this . linkController . appendChild ( this . line2 )
272-
273- this . linkSvgGroup = createLinkSvg ( 'topiclinks' ) // storage user custom link svg
274-
275- this . map . appendChild ( this . root )
276- this . map . appendChild ( this . box )
277- this . map . appendChild ( this . svg2nd )
278- this . map . appendChild ( this . linkController )
279- this . map . appendChild ( this . linkSvgGroup )
280- this . map . appendChild ( this . P2 )
281- this . map . appendChild ( this . P3 )
282-
283+ init : function ( data :MindElixirData ) {
284+ this . nodeData = data . nodeData
285+ this . linkData = data . linkData || { }
283286 // plugin
284287 this . toolBar && toolBar ( this )
285288
@@ -289,10 +292,10 @@ MindElixir.prototype = {
289292 this . contextMenu && contextMenu ( this , this . contextMenuOption )
290293 }
291294
295+ addParentLink ( this . nodeData )
292296 this . toCenter ( )
293297 this . layout ( )
294298 this . linkDiv ( )
295- if ( ! this . overflowHidden ) initMouseEvent ( this )
296299 } ,
297300}
298301
0 commit comments