source: other-projects/nz-flag-design/trunk/main-form/choose-canvas.html@ 29808

Last change on this file since 29808 was 29808, checked in by davidb, 9 years ago

Further rewording

  • Property svn:executable set to *
File size: 14.5 KB
RevLine 
[29549]1<!DOCTYPE html>
2<html id="story">
[29530]3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
[29781]5
6 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
7 <meta http-equiv="Pragma" content="no-cache" />
8 <meta http-equiv="Expires" content="0" />
9
10<!--
[29549]11 <meta name="viewport" content="width=device-width, initial-scale=1"/>
[29781]12-->
13 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
14 <meta http-equiv="X-UA-Compatible" content="IE=Edge, chrome=1"/>
15 <meta name="apple-mobile-web-app-capable" content="yes"/>
16
17 <script src="css/source-sans-pro.js"></script>
18 <link href="css/styles.css" rel="stylesheet"/>
19 <link href="css/storystyle.css" rel="stylesheet"/>
20
21 <link rel="stylesheet" href="lib-slider/css/jquery.mobile-1.3.0.css"/>
22 <link rel="stylesheet" href="lib-slider/css/jqm-demos.css"/>
23 <link rel="stylesheet" href="lib-slider/css/swipe-page.css"/>
24 <link rel="shortcut icon" href="lib-slider/nzflag-icon64-padded.png"/>
25
26 <!-- jQuery -->
27 <script src="lib/jquery-1.11.1.min.js"></script>
28 <script src="lib/jquery.cookie.js"></script>
29
30 <!-- page swipe -->
31 <script src="lib-slider/js/jquery.mobile.demos.js"></script>
32 <script src="lib-slider/js/jquery.mobile-1.3.0.js"></script>
33 <script src="lib-slider/js/swipe-page.js"></script>
34
35 <!-- accordion bars -->
36 <link href="css/liteaccordion.css" rel="stylesheet" />
37 <script src="js/jquery.easing.1.3.js"></script>
38 <script src="js/liteaccordion-with-resize.jquery.js"></script>
39
40 <!-- canvg library -->
41 <script type="text/javascript" src="lib/canvg/rgbcolor.js"></script>
42 <script type="text/javascript" src="lib/canvg/StackBlur.js"></script>
43 <script type="text/javascript" src="lib/canvg/canvg.js"></script>
44
45 <!-- spectrum for colour palette -->
46 <!-- For documentation see https://bgrins.github.io/spectrum -->
47 <script src='bgrins-spectrum/spectrum.js'></script>
48 <link rel='stylesheet' href='bgrins-spectrum/spectrum.css' />
[29803]49
50 <script src="../similarity-2d/js-lib/Colour.js"></script>
51 <script src="../similarity-2d/flag-processing.js"></script>
52
[29805]53 <scriptXXX src="choose-canvas.js" />
[29781]54
[29805]55 <script type="text/javascript">
[29781]56 // Flag settings - used to initialise the svg canvas to the user's preferences
57 var flagCanvasSettings = { backgroundColor: "#000066", width: 800, height: 400 };
58
[29805]59
60// Variable for the currently selected flag ratio
61var currentRatio = null;
62
63var aspectRatios = null;
64var aspectMaxRatio = 0;
65
66function calcMaxRatio(aspect_ratio_data)
67{
68 // work out the maximum ratio
69 var max_ratio = 0;
70
71 $.each(aspect_ratio_data, function(key, ratio_table) {
72 var ratio_array = key.split(":");
73 var ratio_x = ratio_array[0];
74 var ratio_y = ratio_array[1];
75 var ratio = ratio_y / ratio_x;
76
77 if (ratio > max_ratio) {
78 max_ratio = ratio;
79 }
80 });
81
82 return max_ratio;
83}
84
85function calcCompleteWidth(aspect_ratio_data,scale)
86{
87 // work out the maximum ratio
88 var max_width = 0;
89
90 $.each(aspect_ratio_data, function(key, ratio_table) {
91 var ratio_array = key.split(":");
92 var ratio_x = ratio_array[0];
93 var ratio_y = ratio_array[1];
94 var ratio = ratio_y / ratio_x;
95
96 max_width += (scale*ratio);
97 });
98
99 return max_width;
100}
101
102
103function scaledDivsFitInPage(aspect_ratio_data, scale_to_height, num_of_rows_allowed, la_x_dim)
104{
105 var divs_fit = true;
106
107 var row = 1;
108 var total_row_width = 0;
109 var total_height = 0;
110
111 $.each(aspect_ratio_data, function(key, ratio_table) {
112 var ratio_array = key.split(":");
113 var ratio_x = ratio_array[0];
114 var ratio_y = ratio_array[1];
115 var ratio = ratio_y / ratio_x;
116
117 var scaled_div_width = scale_to_height*ratio;
118 if (total_row_width + scaled_div_width > la_x_dim) {
119 // this div doesn't fit on the current row
120 // => start a new row
121 total_row_width = scaled_div_width;
122 row++;
123
124 if (row>num_of_rows_allowed) {
125 // blow out!
126 divs_fit = false;
127 return false; // jquery.each equivalent to 'break'
128 }
129 }
130 else {
131 total_row_width += scaled_div_width;
132 row++;
133 }
134 });
135
136 return divs_fit;
137}
138
139
140function calcScaleToHeight(aspectRatios,la_x_dim,la_y_dim)
141{
142 // determine scale factor so divs max out (as in, filling in the page) based la_y_dim height,
143
144 var num_of_rows_allowed = 1;
145 var scale_to_height = la_y_dim; // optimized version of true calcuation, la_y_dim / num_of_rows_allowed;
146
147 //var div_width = complete_width_100 * (div_height/100)
148
149 var num_flag_bins = aspectRatios.length;
150
151 while (!scaledDivsFitInPage(aspectRatios,scale_to_height,num_of_rows_allowed,la_x_dim)) {
152
153 num_of_rows_allowed++;
154
155 if (num_of_rows_allowed>num_flag_bins) {
156 // needing more rows than there are flag bins is an indication that things
157 // just don't fit, and so will need to use a scroll bar.
158 // Exiting at this point will naturally achieve this
159 break;
160 }
161
162 scale_to_height = la_y_dim/num_of_rows_allowed;
163
164 // if get to here, then need
165
166 }
167
168 console.log("**** num_of_rows = " + num_of_rows_allowed + ", scale to height = " + scale_to_height);
169 return scale_to_height;
170}
171
172
173$(function() {
174 $.getJSON( "../similarity-2d/flag-aspect-ratios-json.jsp", function(data) {
175
176 aspectRatios = data;
177
178 //var scale_to_y_dim = 130;
179
180 // express scale_to_y_dim to use relative to height of window
181
182 var window_height = $(window).height();
183 var div_top = $('#aspect-ratio-div').offset().top + 20;
184
185 var la_y_dim = (div_top>0) ? window_height - div_top : window_height * 0.6;
186 var la_x_dim = $(window).width() * 0.7;
187
188 //var scale_to_y_dim = la_y_dim/4;
189
190 //console.log("*** scale to y dim = " + la_y_dim);
191
192 //alert("scale_to_y_dim = " + scale_to_y_dim);
193
194
195 aspectMaxRatio = calcMaxRatio(aspectRatios);
196 //var complete_width_100 = calcCompleteWidth(aspectRatios,100); // as if every aspect ratio bin is scaled to 100 pixels high
197
198
199 scale_to_y_dim = calcScaleToHeight(aspectRatios,la_x_dim,la_y_dim);
200
201
202 var items = [];
203
204
205 $.each(data, function(key, ratio_table) {
206 var freq = ratio_table.freq;
207 var ratio_array = key.split(":");
208 var ratio_x = ratio_array[0];
209 var ratio_y = ratio_array[1];
210 var ratio = ratio_y / ratio_x;
211
212 var ratioScale = aspectMaxRatio/ratio;
213
214 var x_dim = Math.round(scale_to_y_dim * ratioScale);
215 var y_dim = scale_to_y_dim;
216
217 var innertext = "<div style='font-size: 180%;'>"+freq + " countries, " + key + "</div>";
218
219 var flags = [];
220
221 var nz_prioritized_flags = ratio_table.flags.sort();
222
223 // Promote NZ flag to start of array, but otherwise keep sorted
224 var p = nz_prioritized_flags.length-1;
225 var found_nz = false;
226
227 while (p>0) {
228 var curr;
229 var curr_title;
230
231 if (!found_nz) {
232 curr = ratio_table.flags[p];
233 curr_title = curr.replace(/^.*\//,"").replace(/\.(.*?)$/,"");
234 }
235
236 if (curr_title == "nz") {
237 found_nz = true;
238
239 // swap with adjacent cell
240 var tmp_m1 = nz_prioritized_flags[p-1];
241 nz_prioritized_flags[p-1] = curr;
242 nz_prioritized_flags[p] = tmp_m1;
243 }
244 p--;
245 }
246
247 $.each(nz_prioritized_flags, function(index, flag_filename) {
248 var title = flag_filename.replace(/^.*\//,"").replace(/\.(.*?)$/,"");
249
250 flags.push("<img src='../similarity-2d/"+flag_filename+"' id='aspect-ratio-"+ title +"' style='height: 70px; padding: 3px; ' title='" + title.toUpperCase() + "'/>");
251 });
252
253 innertext += flags.join("");
254
255 var ratio_id = "ratio-" + key.replace(":","_");
256 if (found_nz) {
257 currentRatio = ratio_id;
258 }
259
260 var id = " id='" + ratio_id + "'";
261
262 var style = "style='width:" + x_dim + "px; height:" + y_dim + "px;";
263 if (found_nz) {
264 style += "border-color:white; border-width:4px;"
265 }
266
267 style += " overflow-y:scroll;";
268 style += "'";
269
270 var onclick = " onclick='updateCanvasDimensions("+ratio_y + "," + ratio_x + ")'";
271
272 items.push( "<div class='ratioDiv'" + id + style + onclick + ">"+ innertext + "</div>" );
273
274 });
275
276 $('#aspect-ratio-div').append("<div class='centredDiv' style='width: 100%'>"+items.join("\n")+"</div>");
277
278
279 // now change the flag tooltip labels into their country names
280 $.getJSON( "../similarity-2d/iso-3166-keyed-by-alpha-2-countrycodes.json", function(data) {
281
282 $.each( data, function( iso2_key, country_name ) {
283 var $img = $('#aspect-ratio-'+iso2_key.toLowerCase());
284 var title = $img.attr("title") + ": " + country_name;
285 $img.attr("title",title);
286 }
287 )
288 });
289
290 });
291});
292
293
294
295$(window).resize(function() {
296 console.log("choose-canvas resize()");
297
298 //console.log("*** aspect ratio div position top = " + $('#aspect-ratio-div').position().top);
299
300 var window_height = $(window).height();
301 var div_top = $('#aspect-ratio-div').offset().top + 20;
302
303 //var top = 0;
304
305 var la_y_dim = window_height - div_top;
306 var la_x_dim = $(window).width() * 0.7;
307
308 var scale_to_y_dim = calcScaleToHeight(aspectRatios,la_x_dim,la_y_dim);
309
310 // (top==0) ? la_y_dim/4 : la_y_dim/2.8;
311
312 //console.log("*** scale to y dim = " + la_y_dim);
313
314 $.each(aspectRatios, function(key, ratio_table) {
315 var freq = ratio_table.freq;
316 var ratio_array = key.split(":");
317 var ratio_x = ratio_array[0];
318 var ratio_y = ratio_array[1];
319 var ratio = ratio_y / ratio_x;
320
321 var ratioScale = aspectMaxRatio/ratio;
322
323 var x_dim = Math.round(scale_to_y_dim * ratioScale);
324 var y_dim = scale_to_y_dim;
325
326 var ratio_id = "ratio-" + key.replace(":","_");
327
328 //console.log("*** ratio_id = " + ratio_id + " xdim = " + x_dim + ", ydim = " + y_dim);
329
330 $('#'+ratio_id).css("width",x_dim + "px");
331 $('#'+ratio_id).css("height",y_dim + "px");
332
333
334 });
335});
336
337
338
339function updateCanvasDimensions(height, width) {
340
341 // Show feedback by highlighting the chosen square
342 document.getElementById(currentRatio).style.borderColor = 'black';
343 document.getElementById(currentRatio).style.borderWidth = '1px';
344 currentRatio = "ratio-" + width + "_" + height;
345 document.getElementById(currentRatio).style.borderColor = 'white';
346 document.getElementById(currentRatio).style.borderWidth = '4px';
347
348 // Changing the value of sizeConstant will change the
349 // size of the svg canvas without affecting the
350 // width/height ratios
351
352 var sizeConstant = 400;
353
354 var h = sizeConstant;
355 var w = (sizeConstant / height) * width;
356
357 if (typeof flagCanvasSettings !== 'undefined') {
358 flagCanvasSettings.width = w;
359 flagCanvasSettings.height = h;
360 }
361}
362
363
364
[29781]365 </script>
[29805]366
[29549]367 <title>Canvas Size</title>
[29781]368
[29530]369 </head>
[29781]370
[29530]371 <body>
[29549]372 <div data-role="page" id="choose-canvas-page"
373 class="demo-page"
374 data-dom-cache="true"
375 data-next="choose-palette">
[29530]376
[29549]377 <div data-role="content">
[29530]378
[29549]379 <div data-role="controlgroup" class="control" data-mini="true">
380 <a href="#" class="next right-button res-fwd" style="right:1%;"></a>
[29781]381<!--
[29549]382 <a href="#" class="prev left-button gen-back" style="left:1%;"></a>
[29781]383-->
[29631]384 </div>
[29781]385
386 <a target="_parent" href="../index.html" class="back-button back-left"></a>
[29530]387
[29549]388 <div class="story-page">
[29530]389
[29549]390 <!-- put custom content here -->
391 <span class="left story-icon idea" ></span>
392 <h2>Canvas Size</h2>
[29631]393
[29787]394 <div class="dialog" id="dialog" title="Flat Aspect Ratio Selection Panel" widthXX="800px">
[29631]395 <br><br>
[29803]396 <h2>Please choose from the following aspect ratios to select the width and height of your flag.</h2>
[29808]397 <style>
398 p { margin: 10px }
399 </style>
400 <p>
401 New Zealand's current aspect ration (2:1) is selected by default. Click on one of the other
402 boxes to choose a different size.
403 </p>
[29781]404 <p>
405 Once chosen, swipe the page or click/press on the right arrow to go onto the next step.
[29803]406 You can swipe/click back to this page at any time to change your selection.
[29781]407 </p>
408
409 <div id="aspect-ratio-div">
410 </div>
411
412
413<!--
[29631]414 <div class="centredDiv">
[29773]415 <div class="ratioDiv flagHover" id="ratio23" onclick="updateCanvasDimensions(2, 3)" title="2:3"></div>
416 <div class="ratioDiv" style="border-width:2px;" id="ratio12" onclick="updateCanvasDimensions(1, 2)" title="1:2"></div>
417 <div class="ratioDiv" id="ratio35" onclick="updateCanvasDimensions(3, 5)" title="3:5"></div>
[29631]418 <div style="clear: both"></div>
419 </div>
420 <p class="optionline">2:3 1:2 3:5</p><br>
421
422 <div class="centredDiv">
[29773]423 <div class="ratioDiv" id="ratio1019" onclick="updateCanvasDimensions(10, 19)" title="10:19"></div>
424 <div class="ratioDiv" id="ratio58" onclick="updateCanvasDimensions(5, 8)" title="5:8"></div>
425 <div class="ratioDiv" id="ratio811" onclick="updateCanvasDimensions(8, 11)" title="8:11"></div>
[29631]426 <div style="clear: both"></div>
427 </div>
428 <p class="optionline">10:19 5:8 8:11</p>
[29781]429-->
[29631]430 </div>
431
[29549]432 <!-- end of putting custom content -->
433
434 </div> <!-- end story-page-->
435
436 </div><!-- /content -->
[29787]437
438<!-- make persistent?
439 <div data-role="footer" style="width:100%;">
440 COSI: Centre of Open Source Innovation @ The University of Waikato.
441 </div>
442-->
[29549]443
444 </div><!-- /page -->
[29530]445
[29549]446 </body>
[29530]447</html>
Note: See TracBrowser for help on using the repository browser.