dynamic.html
5.42 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PlotKit : Basic Unit Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../PlotKit/MochiKit.js" type="text/javascript"></script>
<script src="../PlotKit/excanvas.js" type="text/javascript"></script>
<script src="../PlotKit/PlotKit_Packed.js" type="text/javascript"></script>
<style type="text/css">
body {
font-family: Lucida Grande, Verdana, Sans;
font-size: small;
}
table#datatable td {
padding: 2px;
}
table#datatable thead td {
border-top: 1px solid #e0e0e0;
background-color: #d0d0d0;
border-bottom: 1px solid #c0c0c0;
padding-left: 10px;
padding-right: 10px;
}
table#datatable tbody input {
border: 1px solid #eee;
padding: 2px;
width: 90px;
}
</style>
<script type="text/javascript">
var dataTable = null;
var layout = null;
var renderer = null;
var options = null;
function initDynamicTable() {
dataTable = $('datatable');
options = PlotKit.Base.officeBlue();
layout = new Layout("line", options);
renderer = new SweetCanvasRenderer($('canvasTest'), layout, options);
}
function newRow() {
var tbody = dataTable.tBodies[0];
var blankRow = TR({}, [
TD({}, INPUT({"class":"xvalue", "size":"6", "type":"text", "value":"0"})),
TD({}, INPUT({"class":"yvalue", "size":"6", "type":"text", "value":"0"}))]);
tbody.appendChild(blankRow);
}
function chartReload() {
var chartStyleSelected = document.forms["options"].chartStyle.selectedIndex;
var chartStyle = document.forms["options"].chartStyle[chartStyleSelected].value;
var colorSchemeSelected = document.forms["options"].colorScheme.selectedIndex;
var colorScheme = document.forms["options"].colorScheme[colorSchemeSelected].value;
// grab values
var getValue = function(row) {
var xElem = MochiKit.DOM.getElementsByTagAndClassName("input", "xvalue", row)[0];
var yElem = MochiKit.DOM.getElementsByTagAndClassName("input", "yvalue", row)[0];
var xVal = xElem.value;
var yVal = yElem.value;
if (xVal.length > 0) {
xVal = parseFloat(xVal);
}
else {
xVal = 0;
}
if (yVal.length > 0) {
yVal = parseFloat(yVal);
}
else {
yVal = 0;
}
return [xVal, yVal];
}
var values = MochiKit.Base.map(getValue, dataTable.tBodies[0].rows);
// setup layout options
var themeName = "office" + colorScheme;
var theme = PlotKit.Base[themeName]();
MochiKit.Base.update(options, theme);
layout.style = chartStyle;
MochiKit.Base.update(layout.options, options);
MochiKit.Base.update(renderer.options, options);
layout.addDataset("data", values);
// update
layout.evaluate();
renderer.clear();
renderer.render();
}
addLoadEvent(initDynamicTable);
</script>
</head>
<body>
<div id="body">
<h2>PlotKit Dynamic Test</h2>
<div style="padding: 20px;">
<form name="options">
Chart Style:
<select id="chartStyle" name="chartStyle" onChange="chartReload();">
<option value="line">Line Chart</option>
<option value="bar">Bar Chart</option>
<option value="pie">Pie Chart</option>
</select>
Colors:
<select id="colorScheme" name="colorScheme" onChange="chartReload();">
<option value="Blue">Blue</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Purple">Purple</option>
<option value="Cyan">Cyan</option>
<option value="Orange">Orange</option>
</select>
</form>
</div>
<div style="float: left; width: 250px;">
<table id="datatable" cellspacing="0" cellpadding="0">
<thead>
<tr><td width="100">X</td><td width="100">Y</td></tr>
</thead>
<tbody>
<tr>
<td><input class="xvalue" size="6" type="text" value="0"/></td>
<td><input class="yvalue" size="6" type="text" value="0"/></td>
</tr>
</tbody>
</table>
<div><a href="#" onclick="newRow(); return false;">add new row</a> <a href="#" onclick="chartReload(); return false;">redraw</a></div>
</div>
<div style="float: left; width: 400px;">
<div><canvas id="canvasTest" width="400" height="400" style="border: 1px solid #eee;"></canvas></div>
</div>
<div style="clear: both;"> </div>
<div class="footer"><a href="http://www.liquidx.net/plotkit/">PlotKit</a></div>
</div>
</body></html>