Rev 17173 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
18587 | gmarbeuf | 1 | !!! JsxGraph responsive Version 5 - 23/05/2025 gmarbeuf |
2 | !!! CSS use aspect-ratio |
||
3 | !!! works with jsxgraph 1.11.1 (3D module) |
||
4 | !!! options : max-width, min-width, center, nocssjs |
||
5 | !!! resize is cancelled otherwise option jsxgraph full-screen doesn't work |
||
6 | !!! scroll to add a horizontal scrolling bar (class wims_scrollable) |
||
16857 | gmarbeuf | 7 | !!! Automatic research of the board's name if not indicated |
16584 | gmarbeuf | 8 | |
4904 | bpr | 9 | !if $wims_read_parm!=slib_header |
16584 | gmarbeuf | 10 | !goto proc |
4904 | bpr | 11 | !endif |
16584 | gmarbeuf | 12 | |
4904 | bpr | 13 | slib_require=jsxgraph |
16584 | gmarbeuf | 14 | slib_author=Bernadette,Perrin-Riou;Gilles, Marbeuf |
15 | |||
18587 | gmarbeuf | 16 | slib_example=jsxbox brd,[300x300,min=200px max=400px],var brd=JXG.JSXGraph.initBoard('jsxbox',{axis:true,originX:150,originY:150,unitX:10,unitY:10});p1=brd.create('point',[-2,1]);p2=brd.create('point',[0,function(){return p1.X();}]);brd.create('line',[p1,p2]);\ |
17 | j1 brd1,[400x400,min=20% max=50% center],var brd1=JXG.JSXGraph.initBoard('j1',{boundingbox:[-2.5,6.5,4,-7.5],axis:true,showCopyright:false,keepAspectRatio:true,zoom:{pinchHorizontal:false,pinchVertical:false,pinchSensitivity:7,min:0.5,max:2,wheel:true,needShift:false},pan:{needTwoFingers:true,needShift:false}});var A=brd1.create('point',[2.5,1],{face:'plus',size:10});var B=brd1.create('point',[-1.25,0.5],{face:'cross',size:4});var C=brd1.create('point',[-1,-5],{face:'circle',size:4});var el=brd1.create('hyperbola',[A,B,C]);var el2=brd1.create('circle',[A,B],{strokecolor:'#f0f'});\ |
||
18 | j2 brd2,[300x200,max=400px],var brd2=JXG.JSXGraph.initBoard('j2',{boundingbox:[-6,2,6,-3],axis:true,showCopyright:false,showFullscreen:true,zoom:{pinchHorizontal:false,pinchVertical:false,pinchSensitivity:7,min:0.5,max:2,wheel:true,needShift:false},pan:{needTwoFingers:true,needShift:false}});var s=brd2.create('slider',[[-2,-2],[2,-2],[-6,5,6]]);var graph=brd2.create('functiongraph',[function(x){return Math.sin(Math.pow(x,2));},-2,function(){return s.Value();}]);\ |
||
19 | j3 brd3,[400x400,min=300px max=500px center],var brd3=JXG.JSXGraph.initBoard('j3',{boundingbox:[-8,8,8,-8],pan:{enabled:true,needTwoFingers:true,needShift:true},keepaspectratio:false,axis:false,showFullscreen:true});var view=brd3.create('view3d',[[-6,-3],[8,8],[[-5,5],[-5,5],[-5,5]]],{projection:'parallel',az:{slider:{visible:true,point1:{pos:[5,-4]},point2:{pos:[5,4]},label:{anchorX:'middle'}}},el:{slider:{visible:true,point1:{pos:[6,-5]},point2:{pos:[6,3]},label:{anchorX:'middle'}}}});var A=view.create('point3d',[-5,0,1],{size:5});var B=view.create('point3d',[3,1,2],{size:5});var C=view.create('point3d',[1,-2,3],{size:5});var D=view.create('polygon3d',[A,B,C],{highlight:false,gradient:'linear',gradientSecondColor:'white',fillColor:'blue',borders:{strokecolor:'blue',strokeWidth:1}}); |
||
4904 | bpr | 20 | |
21 | !exit |
||
22 | |||
23 | :proc |
||
24 | |||
16857 | gmarbeuf | 25 | #### PARAM 1 : ID AND BOARD #### |
4904 | bpr | 26 | slib_jsxbox= $(wims_read_parm[1]) |
16857 | gmarbeuf | 27 | !distribute words $slib_jsxbox into slib_jsxbox,slib_board |
16584 | gmarbeuf | 28 | |
16857 | gmarbeuf | 29 | #### PARAM 2: ONLY SIZES OR SIZES AND OPTIONS #### |
16584 | gmarbeuf | 30 | slib_resp=$(wims_read_parm[2]) |
31 | |||
16857 | gmarbeuf | 32 | #### PARAM 3: #### |
33 | slib_script= $(wims_read_parm[3..-1]) |
||
16584 | gmarbeuf | 34 | |
35 | #### TO DETECT OLD (NO RESPONSIVE) AND NEW VERSION (RESPONSIVE) OF THE SLIB #### |
||
36 | slib_char1=!char 1 of $slib_resp |
||
37 | slib_char2=!char -1 of $slib_resp |
||
38 | !if ($slib_char1=[) and ($slib_char2=]) |
||
16862 | bpr | 39 | slib_jsversion=responsive |
16584 | gmarbeuf | 40 | !goto responsive |
41 | !else |
||
16862 | bpr | 42 | slib_jsversion=no_responsive |
16584 | gmarbeuf | 43 | !goto no_responsive |
44 | !endif |
||
45 | |||
46 | :no_responsive |
||
16857 | gmarbeuf | 47 | slib_size=!declosing $slib_resp |
48 | slib_size=!replace internal x by , in $slib_size |
||
49 | slib_width=!nospace $(slib_size[1]) px |
||
50 | slib_height=!nospace $(slib_size[2]) px |
||
51 | !goto result |
||
4904 | bpr | 52 | |
16584 | gmarbeuf | 53 | :responsive |
54 | slib_resp=!declosing $slib_resp |
||
55 | slib_size=$(slib_resp[1]) |
||
56 | slib_size=!replace internal x by , in $slib_size |
||
57 | slib_width=!nospace $(slib_size[1]) |
||
58 | slib_height=!nospace $(slib_size[2]) |
||
18587 | gmarbeuf | 59 | slib_ratio=$slib_width/$slib_height |
16584 | gmarbeuf | 60 | |
16857 | gmarbeuf | 61 | ### AUTOMATIC RESEARCH OF BOARD'S NAME ### |
62 | !if $slib_board=$empty |
||
63 | slib_tempbrd=$slib_script |
||
64 | slib_tempbrd=!replace internal initBoard by $ $@@@@$ $ in $slib_tempbrd |
||
65 | slib_tempbrd=!replace internal . by $ $ in $slib_tempbrd |
||
66 | slib_pos=!positionof word @@@@ in $slib_tempbrd |
||
67 | slib_tempbrd=!replace internal = by in $slib_tempbrd |
||
68 | slib_tempbrd=!words2items $slib_tempbrd |
||
69 | slib_tempbrd=!nonempty item $slib_tempbrd |
||
70 | slib_itempos=!positionof item @@@@ in $slib_tempbrd |
||
71 | slib_board=!item $[$slib_itempos-3] of $slib_tempbrd |
||
72 | !endif |
||
16584 | gmarbeuf | 73 | |
16857 | gmarbeuf | 74 | ### OPTIONS ### |
75 | slib_option=$(slib_resp[2]) |
||
16833 | gmarbeuf | 76 | |
16894 | gmarbeuf | 77 | ## scroll ## |
78 | !if scroll iswordof $slib_option |
||
18587 | gmarbeuf | 79 | slib_tagscroll1=<div class="wims_scrollable"> |
80 | slib_tagscroll2=</div> |
||
81 | !else |
||
82 | slib_tagscroll1= |
||
83 | slib_tagscroll2= |
||
16894 | gmarbeuf | 84 | !endif |
85 | |||
16857 | gmarbeuf | 86 | ## center ## |
16584 | gmarbeuf | 87 | !if center iswordof $slib_option |
16833 | gmarbeuf | 88 | slib_css_jsxwrap=margin:.5rem auto; |
16584 | gmarbeuf | 89 | !else |
16857 | gmarbeuf | 90 | slib_css_jsxwrap= |
16584 | gmarbeuf | 91 | !endif |
92 | |||
16857 | gmarbeuf | 93 | ## min and max width ## |
94 | ## user must add unit like px or % or ...## |
||
95 | slib_minwidth=!getopt min in $slib_option |
||
96 | slib_maxwidth=!getopt max in $slib_option |
||
16833 | gmarbeuf | 97 | |
16857 | gmarbeuf | 98 | !if $(slib_maxwidth) !=$empty |
99 | slib_css_jsxwrap=$slib_css_jsxwrap\ |
||
100 | max-width:$(slib_maxwidth); |
||
16833 | gmarbeuf | 101 | !endif |
16857 | gmarbeuf | 102 | !if $(slib_minwidth) !=$empty |
103 | slib_css_jsxwrap=$slib_css_jsxwrap\ |
||
104 | min-width:$slib_minwidth; |
||
16833 | gmarbeuf | 105 | !endif |
16584 | gmarbeuf | 106 | slib_css_jsxwrap=$slib_css_jsxwrap\ |
107 | height:auto; |
||
108 | |||
16857 | gmarbeuf | 109 | ### nocssjs ### |
110 | !if nocssjs iswordof $slib_option |
||
111 | slib_nocssjs=nocssjs |
||
112 | !endif |
||
113 | |||
16584 | gmarbeuf | 114 | !goto result |
115 | |||
116 | :result |
||
117 | |||
16833 | gmarbeuf | 118 | !if $slib_nocssjs= |
17173 | bpr | 119 | slib_out=<link rel="stylesheet" href="scripts/js/jsxgraph/jsxgraph.css"> |
16833 | gmarbeuf | 120 | !endif |
16862 | bpr | 121 | !if $slib_jsversion=responsive |
16584 | gmarbeuf | 122 | slib_out=$slib_out\ |
123 | <style>\ |
||
124 | div.jsxwrap_$slib_jsxbox{$slib_css_jsxwrap}\ |
||
125 | div.resp_$slib_jsxbox{\ |
||
18587 | gmarbeuf | 126 | aspect-ratio: $slib_ratio;\ |
16584 | gmarbeuf | 127 | box-sizing: border-box;\ |
128 | }\ |
||
129 | @media screen and (max-height:500px) {\ |
||
130 | div.resp_$slib_jsxbox{\ |
||
131 | margin:0 auto;\ |
||
132 | width: calc(100vmin - 2em);\ |
||
133 | height: calc(100vmin - 2em);\ |
||
134 | padding:0;\ |
||
135 | }\ |
||
136 | }\ |
||
137 | </style> |
||
138 | !endif |
||
16833 | gmarbeuf | 139 | !if $slib_nocssjs= |
140 | slib_out=$slib_out\ |
||
16860 | gmarbeuf | 141 | <script src="scripts/js/jsxgraph/jsxgraphcore.js" charset="utf-8"></script> |
16833 | gmarbeuf | 142 | !endif |
16862 | bpr | 143 | !if $slib_jsversion=no_responsive |
16584 | gmarbeuf | 144 | slib_out=$slib_out\ |
16883 | obado | 145 | <div class="wims_scrollable jsxwrap">\ |
16857 | gmarbeuf | 146 | <div id="$slib_jsxbox" class="jxgbox" style="width:$slib_width; height:$slib_height"></div>\ |
16584 | gmarbeuf | 147 | </div> |
148 | !else |
||
149 | slib_out=$slib_out\ |
||
18587 | gmarbeuf | 150 | $slib_tagscroll1\ |
151 | <div class="jsxwrap_$slib_jsxbox jsxwrap">\ |
||
16883 | obado | 152 | <div id="$slib_jsxbox" class="jxgbox resp_$slib_jsxbox"></div>\ |
18587 | gmarbeuf | 153 | </div>\ |
154 | $slib_tagscroll2 |
||
16584 | gmarbeuf | 155 | !endif |
16894 | gmarbeuf | 156 | |
157 | slib_out=$slib_out\ |
||
158 | <script>\ |
||
159 | /*<![CDATA[*/\ |
||
160 | $slib_script\ |
||
161 | /*]]>*/\ |
||
162 | </script> |
||
163 | |||
18587 | gmarbeuf | 164 | !reset slib_script slib_size slib_width slib_height slib_jsxbox |
165 | !if $slib_jsversion=responsive |
||
166 | !reset slib_ratio slib_board slib_option slib_tagscroll1 slib_tagscroll2 slib_nocssjs |
||
16584 | gmarbeuf | 167 | !endif |
18587 | gmarbeuf | 168 | !reset slib_jsversion |