Rev 17173 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 17173 | Rev 18587 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | !!! JsxGraph responsive Version |
1 | !!! JsxGraph responsive Version 5 - 23/05/2025 gmarbeuf |
2 | !!! CSS |
2 | !!! CSS use aspect-ratio |
3 | !!! works with jsxgraph 1. |
3 | !!! works with jsxgraph 1.11.1 (3D module) |
4 | !!! options : max-width, min-width, |
4 | !!! options : max-width, min-width, center, nocssjs |
- | 5 | !!! resize is cancelled otherwise option jsxgraph full-screen doesn't work |
|
5 | !!! |
6 | !!! scroll to add a horizontal scrolling bar (class wims_scrollable) |
6 | !!! Automatic research of the board's name if not indicated |
7 | !!! Automatic research of the board's name if not indicated |
7 | !!! New option : scroll to add a horizontal scrolling bar (class wims_scrollable) |
- | |
8 | !!! WARNING : with version 1.4.4 of jsxgraph, javascript updateSize function |
- | |
9 | !!! is needed even the option resize is not called with this line |
- | |
10 | !!! slib_board.resizeContainer(theWidth,theHeight); |
- | |
11 | 8 | ||
12 | !if $wims_read_parm!=slib_header |
9 | !if $wims_read_parm!=slib_header |
13 | !goto proc |
10 | !goto proc |
14 | !endif |
11 | !endif |
15 | 12 | ||
16 | slib_require=jsxgraph |
13 | slib_require=jsxgraph |
17 | slib_author=Bernadette,Perrin-Riou;Gilles, Marbeuf |
14 | slib_author=Bernadette,Perrin-Riou;Gilles, Marbeuf |
18 | 15 | ||
19 | slib_example=jsxbox brd,[ |
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]);\ |
20 | j1 brd1,[400x400,min=20% |
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();}]);\ |
|
21 |
|
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}}); |
22 | 20 | ||
23 | !exit |
21 | !exit |
24 | 22 | ||
25 | :proc |
23 | :proc |
26 | 24 | ||
Line 56... | Line 54... | ||
56 | slib_resp=!declosing $slib_resp |
54 | slib_resp=!declosing $slib_resp |
57 | slib_size=$(slib_resp[1]) |
55 | slib_size=$(slib_resp[1]) |
58 | slib_size=!replace internal x by , in $slib_size |
56 | slib_size=!replace internal x by , in $slib_size |
59 | slib_width=!nospace $(slib_size[1]) |
57 | slib_width=!nospace $(slib_size[1]) |
60 | slib_height=!nospace $(slib_size[2]) |
58 | slib_height=!nospace $(slib_size[2]) |
61 |
|
59 | slib_ratio=$slib_width/$slib_height |
62 | 60 | ||
63 | ### AUTOMATIC RESEARCH OF BOARD'S NAME ### |
61 | ### AUTOMATIC RESEARCH OF BOARD'S NAME ### |
64 | !if $slib_board=$empty |
62 | !if $slib_board=$empty |
65 | slib_tempbrd=$slib_script |
63 | slib_tempbrd=$slib_script |
66 | slib_tempbrd=!replace internal initBoard by $ $@@@@$ $ in $slib_tempbrd |
64 | slib_tempbrd=!replace internal initBoard by $ $@@@@$ $ in $slib_tempbrd |
Line 76... | Line 74... | ||
76 | ### OPTIONS ### |
74 | ### OPTIONS ### |
77 | slib_option=$(slib_resp[2]) |
75 | slib_option=$(slib_resp[2]) |
78 | 76 | ||
79 | ## scroll ## |
77 | ## scroll ## |
80 | !if scroll iswordof $slib_option |
78 | !if scroll iswordof $slib_option |
81 |
|
79 | slib_tagscroll1=<div class="wims_scrollable"> |
- | 80 | slib_tagscroll2=</div> |
|
- | 81 | !else |
|
- | 82 | slib_tagscroll1= |
|
- | 83 | slib_tagscroll2= |
|
82 | !endif |
84 | !endif |
83 | 85 | ||
84 | ## center ## |
86 | ## center ## |
85 | !if center iswordof $slib_option |
87 | !if center iswordof $slib_option |
86 | slib_css_jsxwrap=margin:.5rem auto; |
88 | slib_css_jsxwrap=margin:.5rem auto; |
87 | !else |
89 | !else |
88 | slib_css_jsxwrap= |
90 | slib_css_jsxwrap= |
89 | !endif |
91 | !endif |
90 | 92 | ||
91 | ## min and max width ## |
93 | ## min and max width ## |
92 | ## user must add unit like px or % or ...## |
94 | ## user must add unit like px or % or ...## |
93 | slib_minwidth=!getopt min in $slib_option |
95 | slib_minwidth=!getopt min in $slib_option |
94 | slib_maxwidth=!getopt max in $slib_option |
96 | slib_maxwidth=!getopt max in $slib_option |
95 | 97 | ||
Line 106... | Line 108... | ||
106 | 108 | ||
107 | ### nocssjs ### |
109 | ### nocssjs ### |
108 | !if nocssjs iswordof $slib_option |
110 | !if nocssjs iswordof $slib_option |
109 | slib_nocssjs=nocssjs |
111 | slib_nocssjs=nocssjs |
110 | !endif |
112 | !endif |
111 | - | ||
112 | ## resize to resize the points with the width of the screen ## |
- | |
113 | ## REQUIRES THE BOARD'S NAME ## |
- | |
114 | - | ||
115 | 113 | ||
116 | !goto result |
114 | !goto result |
117 | 115 | ||
118 | :result |
116 | :result |
119 | 117 | ||
Line 123... | Line 121... | ||
123 | !if $slib_jsversion=responsive |
121 | !if $slib_jsversion=responsive |
124 | slib_out=$slib_out\ |
122 | slib_out=$slib_out\ |
125 | <style>\ |
123 | <style>\ |
126 | div.jsxwrap_$slib_jsxbox{$slib_css_jsxwrap}\ |
124 | div.jsxwrap_$slib_jsxbox{$slib_css_jsxwrap}\ |
127 | div.resp_$slib_jsxbox{\ |
125 | div.resp_$slib_jsxbox{\ |
128 | height:0;\ |
- | |
129 |
|
126 | aspect-ratio: $slib_ratio;\ |
130 | box-sizing: border-box;\ |
127 | box-sizing: border-box;\ |
131 | /*width:100%;*/\ |
- | |
132 | }\ |
128 | }\ |
133 | @media screen and (max-height:500px) {\ |
129 | @media screen and (max-height:500px) {\ |
134 | div.resp_$slib_jsxbox{\ |
130 | div.resp_$slib_jsxbox{\ |
135 | margin:0 auto;\ |
131 | margin:0 auto;\ |
136 | width: calc(100vmin - 2em);\ |
132 | width: calc(100vmin - 2em);\ |
Line 149... | Line 145... | ||
149 | <div class="wims_scrollable jsxwrap">\ |
145 | <div class="wims_scrollable jsxwrap">\ |
150 | <div id="$slib_jsxbox" class="jxgbox" style="width:$slib_width; height:$slib_height"></div>\ |
146 | <div id="$slib_jsxbox" class="jxgbox" style="width:$slib_width; height:$slib_height"></div>\ |
151 | </div> |
147 | </div> |
152 | !else |
148 | !else |
153 | slib_out=$slib_out\ |
149 | slib_out=$slib_out\ |
- | 150 | $slib_tagscroll1\ |
|
154 | <div class=" |
151 | <div class="jsxwrap_$slib_jsxbox jsxwrap">\ |
155 | <div id="$slib_jsxbox" class="jxgbox resp_$slib_jsxbox"></div>\ |
152 | <div id="$slib_jsxbox" class="jxgbox resp_$slib_jsxbox"></div>\ |
156 | <canvas class="jsxg_placeholder" width="$slib_width" height="1"></canvas>\ |
- | |
157 | </div> |
153 | </div>\ |
- | 154 | $slib_tagscroll2 |
|
158 | !endif |
155 | !endif |
159 | 156 | ||
160 | slib_out=$slib_out\ |
157 | slib_out=$slib_out\ |
161 | <script>\ |
158 | <script>\ |
162 | /*<![CDATA[*/\ |
159 | /*<![CDATA[*/\ |
163 | $slib_script\ |
160 | $slib_script\ |
164 | /*]]>*/\ |
161 | /*]]>*/\ |
165 | </script> |
162 | </script> |
166 | 163 | ||
167 | !if resize iswordof $slib_option |
- | |
168 | slib_out=$slib_out\ |
- | |
169 | <script>\ |
- | |
170 |
|
164 | !reset slib_script slib_size slib_width slib_height slib_jsxbox |
171 | window.addEventListener('resize', updateSize_$slib_jsxbox);\ |
- | |
172 | window.onload = function() {updateSize_$slib_jsxbox()};\ |
- | |
173 | function updateSize_$slib_jsxbox() {\ |
- | |
174 | var myid=document.getElementById("$slib_jsxbox");\ |
- | |
175 | myid.style.width="";\ |
- | |
176 | myid.style.height="";\ |
- | |
177 | var theWidth=myid.getBoundingClientRect().width;\ |
- | |
178 | var theHeight=myid.getBoundingClientRect().height;\ |
- | |
179 | /*$slib_board.resizeContainer(theWidth,theHeight);*/\ |
- | |
180 | if(theWidth < 400){\ |
- | |
181 | cellSize = theWidth/100;\ |
- | |
182 | for (elt in $slib_board.objects) {\ |
- | |
183 | if (JXG.isPoint($slib_board.objects[elt])) {\ |
- | |
184 | $slib_board.objects[elt].setAttribute({ size: cellSize.toFixed(0) });\ |
- | |
185 | }\ |
- | |
186 | }\ |
- | |
187 | }\ |
- | |
188 | }\ |
- | |
189 | </script> |
- | |
190 | !endif |
- | |
191 | - | ||
192 | !if |
165 | !if $slib_jsversion=responsive |
193 | !reset |
166 | !reset slib_ratio slib_board slib_option slib_tagscroll1 slib_tagscroll2 slib_nocssjs |
194 | !else |
- | |
195 | !reset slib_script slib_size slib_width slib_height slib_jsxbox slib_ratio slib_board slib_jsversion slib_option |
- | |
196 | !endif |
167 | !endif |
- | 168 | !reset slib_jsversion |