@@ -22,6 +22,7 @@ HTMLWidgets.widget({
2222 echarts . registerTheme ( x . theme , tcode ) ;
2323 }
2424 }
25+
2526 if ( x . hasOwnProperty ( 'registerMap' ) ) {
2627 for ( let map = 0 ; map < x . registerMap . length ; map ++ ) {
2728 if ( x . registerMap [ map ] . geoJSON )
@@ -33,6 +34,13 @@ HTMLWidgets.widget({
3334 }
3435 }
3536
37+ ecfun . hwid = el . id ;
38+ if ( window . onresize == undefined )
39+ window . onresize = function ( ) {
40+ chart . resize ( ) ;
41+ ecfun . fs = ecfun . IsFullScreen ( ) ; // handle ESC key
42+ }
43+
3644 let eva2 = eva3 = null ;
3745 if ( x . hasOwnProperty ( 'jcode' ) ) {
3846 if ( x . jcode ) {
@@ -69,26 +77,15 @@ HTMLWidgets.widget({
6977 } catch ( err ) { console . log ( 'eva3: ' + err . message ) }
7078 }
7179
72- load = opts . load ;
73- if ( Array . isArray ( load ) ) load = load . join ( ) ;
74- if ( load && load . includes ( 'lottie-parser' ) ) {
75- lottieParser . install ( echarts ) ;
76- // lottie without timeline
77- tmp = chart . getModel ( ) . option . graphic ;
78- if ( tmp ) {
79- tmp = updLGraphic ( tmp ) ;
80+ if ( opts . graphic && lottieParser ) {
81+ tmp = ecfun . lottieGraphic ( opts . graphic ) ;
8082 chart . setOption ( { graphic : tmp } , { replaceMerge : 'graphic' } ) ;
81- }
8283 }
8384
8485 // TODO: timeline to include graphic, etc. (ECUnitOption, OptionManager ?)
8586 // find how to set timeline 'options'...
86- // tmp = chart.getModel()._optionManager._timelineOptions;
87- // if (tmp) {
88- // tmp = updGraphic(tmp);
89- // //tmp.forEach((opt) => { if (opt.graphic) opt.graphic = updGraphic(opt.graphic); });
90- // // chart.setOption({options: tmp}, { replaceMerge: 'graphic'});
91- // }
87+ // tmp = chart.getModel()._optionManager._timelineOptions;
88+ // if (tmp) { }
9289
9390 if ( HTMLWidgets . shinyMode ) { // shiny callbacks
9491
@@ -225,15 +222,15 @@ HTMLWidgets.widget({
225222
226223 ct_filter . on ( 'change' , function ( e ) { // external keys to filter
227224 if ( e . sender == ct_filter ) return ;
228- if ( e . value == undefined ) return ;
225+ if ( e . value == undefined ) e . value = [ ] ; // sent by filter_checkbox ?!
229226 // if (chart.sele.length>0) { // clear selection(s) before new filter
230227 // chart.dispatchAction({type: 'unselect', // works for self only
231228 // seriesIndex: chart.sext, dataIndex: chart.sele });
232229 // chart.sele = [];
233230 // }
234231
235- rexp = '^(' + e . value . join ( '|' ) + ')$' ;
236- if ( e . value . length == chart . akeys . length ) rexp < - '^'
232+ rexp = ( e . value . length == chart . akeys . length ||
233+ e . value . length == 0 ) ? '^' : '^(' + e . value . join ( '|' ) + ')$' ;
237234 opt = chart . getOption ( ) ;
238235 dtf = opt . dataset . find ( x => x . id === 'Xtalk' ) ;
239236 dtf . transform = { type : 'filter' , config :
@@ -263,33 +260,6 @@ HTMLWidgets.widget({
263260 }
264261} ) ;
265262
266- updLGraphic = ( tmp ) => {
267- // transform lottie graphic element
268- if ( tmp == undefined ) return tmp ;
269- for ( i = 0 ; i < tmp . length ; i ++ ) {
270- if ( ! tmp [ i ] . elements ) continue ;
271- grf = tmp [ i ] ;
272- grf . elements . forEach ( ( elem ) => {
273- //if (elem.id && !elem.id.startsWith('lottie')) return;
274- loty = elem ;
275- data = loty . info ; if ( ! data ) return ;
276- delete loty . info ;
277- if ( ! data . v || data . v . search ( '\\d\\.\\d\\.\\d' ) < 0 ) return ;
278- loop = loty . loop ; if ( loop == undefined ) loop = true ;
279- const { elements, width, height } = lottieParser . parse ( data , { loop : loop } ) ;
280- scale = loty . scale ;
281- if ( scale ) {
282- delete loty . scale ;
283- const sfactor = scale / Math . min ( width , height ) ;
284- loty . scaleX = sfactor ; loty . scaleY = sfactor ;
285- }
286- loty . type = 'group' ; loty . children = elements ;
287- elem = loty ;
288- } ) ;
289- } ;
290- return tmp ;
291- }
292-
293263function get_e_charts ( id ) {
294264
295265 let htmlWidgetsObj = HTMLWidgets . find ( "#" + id ) ;
@@ -321,6 +291,80 @@ function get_e_charts_opts(id){
321291function distinct ( value , index , self ) {
322292 return self . indexOf ( value ) === index ;
323293}
294+
295+ // extra functions
296+ ecfun = {
297+ IsFullScreen : function ( ) {
298+ var full_screen_element = document . fullscreenElement || document . webkitFullscreenElement || document . mozFullScreenElement || document . msFullscreenElement || null ;
299+ if ( full_screen_element === null )
300+ return false ;
301+ else
302+ return true ;
303+ } ,
304+
305+ fs : false , // fullscreen flag Y/N
306+ fscreen : function ( ) {
307+ // see also window.onresize
308+ function GoInFullscreen ( element ) {
309+ if ( element . requestFullscreen )
310+ element . requestFullscreen ( ) ;
311+ else if ( element . mozRequestFullScreen )
312+ element . mozRequestFullScreen ( ) ;
313+ else if ( element . webkitRequestFullscreen )
314+ element . webkitRequestFullscreen ( ) ;
315+ else if ( element . msRequestFullscreen )
316+ element . msRequestFullscreen ( ) ;
317+ }
318+ function GoOutFullscreen ( ) {
319+ if ( document . exitFullscreen )
320+ document . exitFullscreen ( ) ;
321+ else if ( document . mozCancelFullScreen )
322+ document . mozCancelFullScreen ( ) ;
323+ else if ( document . webkitExitFullscreen )
324+ document . webkitExitFullscreen ( ) ;
325+ else if ( document . msExitFullscreen )
326+ document . msExitFullscreen ( ) ;
327+ }
328+
329+ if ( this . fs ) {
330+ if ( this . IsFullScreen ( ) )
331+ GoOutFullscreen ( ) ;
332+ }
333+ else {
334+ tmp = document . getElementById ( ecfun . hwid ) ;
335+ GoInFullscreen ( tmp )
336+ }
337+ this . fs = ! this . fs ;
338+ } ,
339+
340+ lottieGraphic : function ( vv ) {
341+ // transform lottie graphic element
342+ if ( vv == undefined ) return vv ;
343+ if ( vv . length ) return vv ;
344+ if ( ! vv . elements ) return vv ;
345+ vv . elements . forEach ( ( elem ) => {
346+ loty = elem ;
347+ data = loty . info ;
348+ if ( ! data ) return ;
349+ delete loty . info ;
350+ if ( ! data . v || data . v . search ( '\\d\\.\\d\\.\\d' ) < 0 ) return ; // not a lottie
351+ if ( lottieParser == undefined ) return ;
352+ lottieParser . install ( echarts ) ;
353+ loop = loty . loop ; if ( loop == undefined ) loop = true ;
354+ const { elements, width, height } = lottieParser . parse ( data , { loop : loop } ) ;
355+ scale = loty . scale ;
356+ if ( scale ) {
357+ delete loty . scale ;
358+ const sfactor = scale / Math . min ( width , height ) ;
359+ loty . scaleX = sfactor ; loty . scaleY = sfactor ;
360+ }
361+ loty . type = 'group' ; loty . children = elements ;
362+ elem = loty ;
363+ } ) ;
364+ return vv ;
365+ }
366+
367+ } ;
324368
325369if ( HTMLWidgets . shinyMode ) {
326370
0 commit comments