Rev 16875 | Rev 16894 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
16857 | gmarbeuf | 1 | !!! JsxGraph responsive Version 3 - 23/06/2022 |
16584 | gmarbeuf | 2 | !!! CSS hack padding-bottom instead aspect-ratio because not supported by old browser |
3 | !!! works with jsxgraph 1.4.2 |
||
16857 | gmarbeuf | 4 | !!! options : max-width, min-width, resize (to resize points with the width of the applet), |
16833 | gmarbeuf | 5 | !!! center, nocssjs |
16857 | gmarbeuf | 6 | !!! Automatic research of the board's name if not indicated |
16584 | gmarbeuf | 7 | |
4904 | bpr | 8 | !if $wims_read_parm!=slib_header |
16584 | gmarbeuf | 9 | !goto proc |
4904 | bpr | 10 | !endif |
16584 | gmarbeuf | 11 | |
4904 | bpr | 12 | slib_require=jsxgraph |
16584 | gmarbeuf | 13 | slib_author=Bernadette,Perrin-Riou;Gilles, Marbeuf |
14 | |||
15 | slib_example=jsxbox,[300 x 300,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]);\ |
||
16857 | gmarbeuf | 16 | j1 brd1,[400x400,min=20% max=60% center resize],var brd1 = JXG.JSXGraph.initBoard('j1',{boundingbox: [-2.5, 6.5, 4, -7.5],axis: true,showCopyright: false,keepAspectRatio:true,moveTarget: document,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'});\ |
17 | j2 brd2,[300x200,max=400px],var brd2 = JXG.JSXGraph.initBoard('j2',{boundingbox: [-6, 2, 6, -3],axis: true,showCopyright: false,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();}]); |
||
4904 | bpr | 18 | |
19 | !exit |
||
20 | |||
21 | :proc |
||
22 | |||
16857 | gmarbeuf | 23 | #### PARAM 1 : ID AND BOARD #### |
4904 | bpr | 24 | slib_jsxbox= $(wims_read_parm[1]) |
16857 | gmarbeuf | 25 | !distribute words $slib_jsxbox into slib_jsxbox,slib_board |
16584 | gmarbeuf | 26 | |
16857 | gmarbeuf | 27 | #### PARAM 2: ONLY SIZES OR SIZES AND OPTIONS #### |
16584 | gmarbeuf | 28 | slib_resp=$(wims_read_parm[2]) |
29 | |||
16857 | gmarbeuf | 30 | #### PARAM 3: #### |
31 | slib_script= $(wims_read_parm[3..-1]) |
||
16584 | gmarbeuf | 32 | |
33 | #### TO DETECT OLD (NO RESPONSIVE) AND NEW VERSION (RESPONSIVE) OF THE SLIB #### |
||
34 | slib_char1=!char 1 of $slib_resp |
||
35 | slib_char2=!char -1 of $slib_resp |
||
36 | !if ($slib_char1=[) and ($slib_char2=]) |
||
16862 | bpr | 37 | slib_jsversion=responsive |
16584 | gmarbeuf | 38 | !goto responsive |
39 | !else |
||
16862 | bpr | 40 | slib_jsversion=no_responsive |
16584 | gmarbeuf | 41 | !goto no_responsive |
42 | !endif |
||
43 | |||
44 | :no_responsive |
||
16857 | gmarbeuf | 45 | slib_size=!declosing $slib_resp |
46 | slib_size=!replace internal x by , in $slib_size |
||
47 | slib_width=!nospace $(slib_size[1]) px |
||
48 | slib_height=!nospace $(slib_size[2]) px |
||
49 | !goto result |
||
4904 | bpr | 50 | |
16584 | gmarbeuf | 51 | :responsive |
52 | slib_resp=!declosing $slib_resp |
||
53 | slib_size=$(slib_resp[1]) |
||
54 | slib_size=!replace internal x by , in $slib_size |
||
55 | slib_width=!nospace $(slib_size[1]) |
||
56 | slib_height=!nospace $(slib_size[2]) |
||
57 | slib_ratio=$[$slib_height*100/$slib_width] |
||
58 | |||
16857 | gmarbeuf | 59 | ### AUTOMATIC RESEARCH OF BOARD'S NAME ### |
60 | !if $slib_board=$empty |
||
61 | slib_tempbrd=$slib_script |
||
62 | slib_tempbrd=!replace internal initBoard by $ $@@@@$ $ in $slib_tempbrd |
||
63 | slib_tempbrd=!replace internal . by $ $ in $slib_tempbrd |
||
64 | slib_pos=!positionof word @@@@ in $slib_tempbrd |
||
65 | slib_tempbrd=!replace internal = by in $slib_tempbrd |
||
66 | slib_tempbrd=!words2items $slib_tempbrd |
||
67 | slib_tempbrd=!nonempty item $slib_tempbrd |
||
68 | slib_itempos=!positionof item @@@@ in $slib_tempbrd |
||
69 | slib_board=!item $[$slib_itempos-3] of $slib_tempbrd |
||
70 | !endif |
||
16584 | gmarbeuf | 71 | |
16857 | gmarbeuf | 72 | ### OPTIONS ### |
73 | slib_option=$(slib_resp[2]) |
||
16833 | gmarbeuf | 74 | |
16857 | gmarbeuf | 75 | ## center ## |
16584 | gmarbeuf | 76 | !if center iswordof $slib_option |
16833 | gmarbeuf | 77 | slib_css_jsxwrap=margin:.5rem auto; |
16584 | gmarbeuf | 78 | !else |
16857 | gmarbeuf | 79 | slib_css_jsxwrap= |
16584 | gmarbeuf | 80 | !endif |
81 | |||
16857 | gmarbeuf | 82 | ## min and max width ## |
83 | ## user must add unit like px or % or ...## |
||
84 | slib_minwidth=!getopt min in $slib_option |
||
85 | slib_maxwidth=!getopt max in $slib_option |
||
16833 | gmarbeuf | 86 | |
16857 | gmarbeuf | 87 | !if $(slib_maxwidth) !=$empty |
88 | slib_css_jsxwrap=$slib_css_jsxwrap\ |
||
89 | max-width:$(slib_maxwidth); |
||
16833 | gmarbeuf | 90 | !endif |
16857 | gmarbeuf | 91 | !if $(slib_minwidth) !=$empty |
92 | slib_css_jsxwrap=$slib_css_jsxwrap\ |
||
93 | min-width:$slib_minwidth; |
||
16833 | gmarbeuf | 94 | !endif |
16584 | gmarbeuf | 95 | slib_css_jsxwrap=$slib_css_jsxwrap\ |
96 | height:auto; |
||
97 | |||
16857 | gmarbeuf | 98 | ### nocssjs ### |
99 | !if nocssjs iswordof $slib_option |
||
100 | slib_nocssjs=nocssjs |
||
101 | !endif |
||
102 | |||
103 | ## resize to resize the points with the width of the screen ## |
||
104 | ## REQUIRES THE BOARD'S NAME ## |
||
16584 | gmarbeuf | 105 | !if resize iswordof $slib_option |
16857 | gmarbeuf | 106 | slib_js_resizePt=if (theWidth < 400){\ |
107 | cellSize = theWidth/100;\ |
||
16584 | gmarbeuf | 108 | for (elt in $slib_board.objects) {\ |
109 | if (JXG.isPoint($slib_board.objects[elt])) {\ |
||
16857 | gmarbeuf | 110 | $slib_board.objects[elt].setAttribute({ size: cellSize.toFixed(0) });\ |
16584 | gmarbeuf | 111 | }\ |
112 | };\ |
||
16857 | gmarbeuf | 113 | } |
16584 | gmarbeuf | 114 | !else |
16857 | gmarbeuf | 115 | slib_js_resizePt= |
16584 | gmarbeuf | 116 | !endif |
117 | !goto result |
||
118 | |||
119 | :result |
||
120 | |||
16833 | gmarbeuf | 121 | !if $slib_nocssjs= |
122 | slib_out=<link rel="stylesheet" href="scripts/js/jsxgraph/jsxgraph.css" /> |
||
123 | !endif |
||
16862 | bpr | 124 | !if $slib_jsversion=responsive |
16584 | gmarbeuf | 125 | slib_out=$slib_out\ |
126 | <style>\ |
||
127 | div.jsxwrap_$slib_jsxbox{$slib_css_jsxwrap}\ |
||
128 | div.resp_$slib_jsxbox{\ |
||
129 | height:0;\ |
||
130 | padding-bottom:$slib_ratio%;\ |
||
131 | box-sizing: border-box;\ |
||
16857 | gmarbeuf | 132 | /*width:100%;*/\ |
16584 | gmarbeuf | 133 | }\ |
134 | @media screen and (max-height:500px) {\ |
||
135 | div.resp_$slib_jsxbox{\ |
||
136 | margin:0 auto;\ |
||
137 | width: calc(100vmin - 2em);\ |
||
138 | height: calc(100vmin - 2em);\ |
||
139 | padding:0;\ |
||
140 | }\ |
||
141 | }\ |
||
142 | </style> |
||
143 | !endif |
||
16833 | gmarbeuf | 144 | !if $slib_nocssjs= |
145 | slib_out=$slib_out\ |
||
16860 | gmarbeuf | 146 | <script src="scripts/js/jsxgraph/jsxgraphcore.js" charset="utf-8"></script> |
16833 | gmarbeuf | 147 | !endif |
16862 | bpr | 148 | !if $slib_jsversion=no_responsive |
16584 | gmarbeuf | 149 | slib_out=$slib_out\ |
16883 | obado | 150 | <div class="wims_scrollable jsxwrap">\ |
16857 | gmarbeuf | 151 | <div id="$slib_jsxbox" class="jxgbox" style="width:$slib_width; height:$slib_height"></div>\ |
16584 | gmarbeuf | 152 | </div> |
153 | !else |
||
154 | slib_out=$slib_out\ |
||
16883 | obado | 155 | <div class="jsxwrap_$slib_jsxbox jsxwrap">\ |
156 | <div id="$slib_jsxbox" class="jxgbox resp_$slib_jsxbox"></div>\ |
||
157 | <canvas class="jsxg_placeholder" width="$slib_width" height="1"></canvas>\ |
||
16584 | gmarbeuf | 158 | </div> |
159 | !endif |
||
16862 | bpr | 160 | !if $slib_jsversion=responsive |
16584 | gmarbeuf | 161 | slib_out=$slib_out\ |
162 | <script>\ |
||
163 | function updateSize_$slib_jsxbox() {\ |
||
164 | var myid=document.getElementById("$slib_jsxbox");\ |
||
165 | myid.style.width="";\ |
||
166 | myid.style.height="";\ |
||
167 | var theWidth=myid.getBoundingClientRect().width;\ |
||
168 | var theHeight=myid.getBoundingClientRect().height;\ |
||
169 | $slib_js_resizePt\ |
||
170 | }\ |
||
171 | document.addEventListener('load', updateSize_$slib_jsxbox);\ |
||
172 | window.addEventListener('resize', updateSize_$slib_jsxbox);\ |
||
173 | </script> |
||
174 | !endif |
||
175 | |||
176 | slib_out=$slib_out\ |
||
14207 | bpr | 177 | <script>\ |
6362 | bpr | 178 | /*<![CDATA[*/\ |
4904 | bpr | 179 | $slib_script\ |
6362 | bpr | 180 | /*]]>*/\ |
181 | </script> |
||
16883 | obado | 182 | |
16862 | bpr | 183 | !if $slib_jsversion=no_responsive |
184 | !reset slib_script slib_size slib_width slib_height slib_jsxbox slib_jsversion |
||
16584 | gmarbeuf | 185 | !else |
16862 | bpr | 186 | !reset slib_script slib_size slib_width slib_height slib_jsxbox slib_ratio slib_board slib_jsversion slib_option |
16584 | gmarbeuf | 187 | !endif |