-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
executable file
·442 lines (390 loc) · 13.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!DOCTYPE html>
<!--[if lt IE 7]><html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]><html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]><html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
<head>
<title>Visual Viewer</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="../visual.max.js"></script>
<script src="../visual.setup.js"></script>
<script src="../lib/jquery.1.8.3.js"></script>
<script src="setup.js"></script>
</head>
<body>
<h1>Visual Viewer</h1>
<form id="inputs">
<strong>↑ Options</strong>
<div>
<fieldset>
<legend>Header and Footer</legend>
<input title="Title (optional)" type="text" name="title" value="[Title]" />
<input title="Geographic area (optional)" type="text" name="geo" value="[Geographic area]" />
<input title="String or ['line1', 'line2', ...] (optional)" type="text" name="footer" value="[Footer.]" />
<label class="right"><input type="checkbox" name="autoheading" checked="checked" /> autoheading</label>
</fieldset>
<fieldset id="units">
<legend>Units</legend>
<label>decimals <input title="Number of decimals" type="text" name="dec" value="0" style="width:10%;"/></label>
<input title="Unit label or {'x': 'x-label', 'y': 'y-label'} (optional)" type="text" name="label" value="[label]" />
<input title="Unit symbol or {'x': 'x-symbol', 'y': 'y-symbol'} (optional)" type="text" name="symbol" value="[symbol]" />
<select title="Symbol position" name="position" class="right"></select>
</fieldset>
<fieldset>
<legend>Type</legend>
<select name="type">
<option value="bar">bar</option>
<option value="rank">rank</option>
<option value="pie">pie</option>
<option value="pyram">pyram</option>
<option value="tsbar">tsbar</option>
<option value="tsline">tsline</option>
<option value="xy">xy</option>
<option value="cmap">cmap</option>
</select>
<span id="version"></span>
<label class="right">lang
<select name="lang">
<option value="en">en</option>
<option value="ca">ca</option>
<option value="es">es</option>
<option value="fr">fr</option>
</select>
</label>
</fieldset>
<fieldset id="layout">
<legend>Layout</legend>
<label class="tsbar tsline bar pyram rank cmap xy">range <input type="text" name="range" value="" /></label>
<div class="right">
<table class="tsbar tsline bar pyram rank xy">
<tbody>
<tr>
<th></th>
<th>labels</th>
<th>ticks</th>
</tr>
<tr>
<td>
<label class="tsbar tsline bar pyram rank xy"><input type="checkbox" name="x" checked="checked" /> x</label>
</td>
<td>
<input type="checkbox" name="xlabels" checked="checked" />
</td>
<td>
<input type="checkbox" name="xticks" checked="checked" />
</td>
</tr>
<tr>
<td>
<label class="tsbar tsline bar pyram rank xy"><input type="checkbox" name="y" checked="checked" /> y</label>
</td>
<td>
<input type="checkbox" name="ylabels" checked="checked" />
</td>
<td>
<input type="checkbox" name="yticks" checked="checked" />
</td>
</tr>
</tbody>
</table>
</div>
<label class="bar tsbar tsline pyram cmap xy pie"><input type="checkbox" name="legend" checked="checked" /> legend</label>
<label class="tsbar"><input type="checkbox" name="stacked" />stacked</label>
<div class="left">
<label class="tsbar tsline bar pyram rank xy" title="border">Border <input type="number" name="border" value="0" /></label>
<label class="tsline" title="line">Line <input type="number" name="line" value="2" /></label>
<label class="tsline xy" title="point">Point <input type="number" name="point" value="1" /></label>
<label class="tsline" title="shadow">Shadow <input type="number" name="shadow" value="4" /></label>
</div>
</fieldset>
<fieldset id="data">
<legend>tsbar ↓</legend>
<div id="custom"></div>
</fieldset>
</div>
</form>
<div id="dataviz">
<div id="visual" class="visual"></div>
</div>
<div id="code">
<form>
<fieldset>
<legend>Code</legend>
<textarea name="code" spellcheck="false" lang=""></textarea>
</fieldset>
</form>
</div>
<script>
var
last=null,
opened=false,
params={grouped: null},
code=[],
leg=$( "#data legend" )
;
$( "#version" ).html( "Visual v. "+VisualJS.version );
function addCustom(i){
var html="";
for(var j in custom[i]){
if(custom[i][j]!==null){
var s=JSON.stringify(custom[i][j]).replace(/"/g, "'").replace(/^'/, "").replace(/'$/, "");
if(j!=="data"){
if(custom[i][j]!==null){
html+='<input title="'+j+'" type="text" name="'+j+'" value="'+s+'" />';
}
}else{
s=s.replace(/({|\[)/g, "$1\n").replace(/(}|\])/g, "\n$1").replace(/:/g, ": ").replace(/,(\[|\{)/g, ",\n$1").replace(/,/g, ", ");
html+='<textarea title="data" name="data" spellcheck="false" lang="">'+s+'</textarea>';
}
params[j]=custom[i][j];
}else{
params[j]=null;
}
}
$( "#custom" ).html( html );
}
function toPosInt( v ){
if( /^([0-9]+)$/.test( v ) ){
return Number( v );
}
return 0;
}
//s is a string that represents a typeof object
//(object/array)
function jsonify(s){
if(typeof s.val()==="undefined"){
return null;
}
var a=eval("["+s.val()+"]"); //eval knows how to deal with arrays but not with non-array objects
return JSON.parse( JSON.stringify( a[0] ) );
}
function update(){
var input=$( "input" ), aux;
params["type"]=$( "select[name=type]" ).val();
params["lang"]=$( "select[name=lang]" ).val();
if(opened){
leg.html( params["type"]+" ↑" );
}else{
leg.html( params["type"]+" ↓" );
}
$( "#layout ."+params["type"] ).show();
$( "#position label").hide();
$( "#position label."+params["type"] ).show();
$( "#position label.all").show();
$( "#layout label").not( "."+params["type"] ).hide();
$( "#layout table").not( "."+params["type"] ).hide();
//Set position selects
if(last!==params["type"]){
if(params["type"] === "xy"){
$("#units input").each(function(i,el){
$(el).val(title.units.xy[i]);
});
$( "select[name=position]" ).html(
'<option value="start,start">start, start</option>'+
'<option value="start,end">start, end</option>'+
'<option value="end,start">end, start</option>'+
'<option value="end,end" selected>end, end</option>'
);
}else{
$("#units input").each(function(i,el){
$(el).val(title.units.default[i]);
});
$( "select[name=position]" ).html(
'<option value="start">start</option>'+
'<option value="end" selected>end</option>'
);
}
}
//Get position select value
if(params["type"] === "xy"){
aux = $( "select[name=position]" ).val().split(",");
params["position"]={
x: aux[0],
y: aux[1]
};
}else{
params["position"]= $( "select[name=position]" ).val();
}
for(var i=0, len=input.length; i<len; i++){
var
f=input[i],
//FF does not support "number" returns type "text".
type=(f.name==="border" || f.name==="shadow" || f.name==="line" || f.name==="point") ? "number" : f.type
;
switch(type){
case "text":
try{
params[f.name]=JSON.parse(f.value.replace(/'/g,"\"").replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": '));
if(typeof params[f.name]!=="object"){ //time can be an array or a string: when a string parse() can convert to number if possible, but we don't want that
if(f.name==="dec")
params[f.name]=toPosInt( f.value );
else
params[f.name]=(f.name!=="range") ? String(params[f.name]) : params[f.name];
}
}catch(e){
//Real text (or number: rangemin, rangemax [not used anymore])
params[f.name]=( f.value!=="" ) ? f.value : null;
}
break;
case "number": //positive integer
params[f.name]=toPosInt( f.value );
break;
case "anynumber": //not used anymore
params[f.name]=(f.value!=="") ? Number(f.value) : null;
break;
case "checkbox":
params[f.name]=f.checked;
break;
}
}
if(last!==params["type"]){
addCustom(params["type"]);
$("input[name=range]").attr("title", title.range[params["type"]]).val("");
params["range"]="";
last=params["type"];
}
params["data"]=jsonify( $( "textarea[name=data]" ) );
if(params["grouped"]) {
params["grouped"]=jsonify( $( "input[name=grouped]" ) );
}
if(params["by"] && params["by"][0]==="["){
params["by"]=jsonify( $( "input[name=by]" ) );
}
if(params["time"] && params["time"][0]==="["){
params["time"]=jsonify( $( "input[name=time]" ) );
}
$("#visual+iframe").remove();
VisualJS.iframe(
{
id: "visual",
fixed: [700,565],
lang: params["lang"],
title: params["title"],
geo: params["geo"],
footer: params["footer"],
unit: {label: params["label"], symbol: params["symbol"], position: params["position"]},
dec: params["dec"],
autoheading: params["autoheading"],
legend: params["legend"],
stacked: params["stacked"],
grid: { border: params["border"], shadow: params["shadow"], line: params["line"], point: params["point"] },
axis: {
x: params["x"], y: params["y"],
ticks: {
x: params["xticks"], y: params["yticks"]
},
labels: {
x: params["xlabels"], y: params["ylabels"]
}
},
range: params["range"],
grouped: params["grouped"] || {},
type: params["type"],
data: params["data"],
by: params["by"],
time: params["time"]
}
,
"../visual.css"
);
code=[];
//Simple properties
for(var i=0, len=simple.length; i<len; i++){
param(simple[i]);
if(simple[i]==="legend"){
code.push(
"\"axis\": {"+
"\"x\": "+params["x"]+", \"y\": "+params["y"]+","+
"\"ticks\": {"+
"\"x\": "+params["xticks"]+", \"y\": "+params["yticks"]+""+
"},"+
"\"labels\": {"+
"\"x\": "+params["xlabels"]+", \"y\": "+params["ylabels"]+""+
"}"+
"}"
);
}
}
//Composed properties
if(params["border"]!==VisualJS.setup.canvas.grid.border || params["shadow"]!==VisualJS.setup.canvas.grid.shadow || params["line"]!==VisualJS.setup.canvas.grid.line || params["point"]!==VisualJS.setup.canvas.grid.point){
code.push('"grid": {"border": '+params["border"]+', "line": '+params["line"]+', "shadow": '+params["shadow"]+', "point": '+params["point"]+'}');
}
if(params["x"]!==VisualJS.setup.canvas.axis.x || params["y"]!==VisualJS.setup.canvas.axis.y){
code.push('"axis": {"x": '+params["x"]+', "y": '+params["y"]+'}');
}
if(params["label"]!==null || params["symbol"]!==null || params["position"]!==VisualJS.setup.canvas.unit.position){
code.push('"unit": {'+
notnull("label", ",")+
notnull("symbol", ",")+
notnull("position", "")+
'}');
}
$( "#code textarea" ).html( "visual({\n\t"+code.join(",\n\t")+"\n});" );
}
function notnull(key, comma){
return (params[key]!==null) ? '"'+key+'": '+((typeof params[key] !== "string") ? JSON.stringify(params[key]) : '"'+params[key]+'"')+comma : '';
}
//code and params, globals
function param(key){
if(typeof params[key]==="undefined" || params[key]===null || params[key]===""){
return;
}
if(typeof defaults[key]!=="undefined" && defaults[key]===params[key]){
return;
}
if(typeof params[key]==="number" || typeof params[key]==="boolean"){
code.push('"'+key+'": '+params[key]);
}else{
code.push('"'+key+'": '+JSON.stringify(params[key]));
}
}
function open(e){
e.html( params["type"]+" ↑" );
var c=$( "#custom" );
c.animate({height: "toggle"}, 100, function() {
c.show();
});
opened=true;
}
function close(e){
e.html( params["type"]+" ↓" );
var c=$( "#custom" );
c.animate({height: "toggle"}, 100, function() {
c.hide();
});
opened=false;
}
update();
$( "#inputs" ).change(update);
leg.click(function(){
if( opened ){
close(leg);
}else{
open(leg);
}
});
$( "#inputs strong" ).click(function() {
var
h=$( "#inputs strong" ).html().substr(1),
up=String.fromCharCode(8593),
down=String.fromCharCode(8595),
c=( $( "#inputs strong" ).html().substr(0,1)===up ) ? down : up
;
$( "#inputs div" ).toggle(0, function() {
$( "#inputs strong" ).html(c+h);
});
});
$( "#code textarea" ).click(function(){
this.select();
});
/* Emulate readonly="readonly" (iPad won't allow copying) */
$( "#code textarea" ).bind("keyup keydown cut", function(e){
e.preventDefault();
e.stopPropagation();
e.returnValue=false; //old IEs
});
</script>
</body>
</html>