aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/fx/tests/example_easingChart2D.html
blob: fd0d1716312d1cff7ccc0b7929d62e1d843a09d6 (plain)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>visualising dojo._Animation.easing via dojox.charting</title>

	<link rel="stylesheet" type="text/css" media="screen"
		href="../../../dojo/resources/dojo.css">

	<link rel="stylesheet" type="text/css" media="screen"
		href="../../../dijit/themes/tundra/tundra.css">

	<style type="text/css">
	.box { padding:14px; 
		border:1px solid #b7b7b7;
		-moz-border-radius:8pt;
	}
	</style>
	
	<script type="text/javascript" djConfig="isDebug:false, parseOnLoad: true"
		src="../../../dojo/dojo.js"></script>

	<script type="text/javascript">
		// one simple theme, and the charting engine:
		dojo.require("dojox.charting.Chart2D");
		// and easing functions:
		dojo.require("dojox.fx.easing"); 

		var d=0;
		var masterData = {};
		var makeSeries = function(/* string */str, /* Function */ func){
			// make some data by running a 2sec animation with an easing function
			// and adding it to the chart
			var seriesData = [];
			if(str in masterData){
				seriesData=masterData[str];
			}

			if(!seriesData.length){
				var func = func || dojox.fx.easing[str];
				func = (dojo.isFunction(func) ? func : dojo._defaultEasing);

				for(var i=0; i<=120; i++){
					var pct = i/120;
					seriesData.push({ y: 30 * func(pct), x: (pct) * 30});
				}
				if(!str.match(/^dynSeries/)){
					masterData[str] = seriesData;
				}
				chart.addSeries(str,
					seriesData,
					{ stroke: { color: "black", width: 0 }, fill: "rgba(30,0,255,0.10)" }
				).render();
			}else{
				chart.updateSeries(str, seriesData).render();
			}
		};

		var removeSeries = function(str){
			chart.updateSeries(str, []);
			if(!clearAll){ chart.render(); }
		};

		var toggleChart = function(widget, str){
			if(!chart) return;
			if(widget.checked){
				makeSeries(str);
			}else{
				removeSeries(str);
			}
		}

		var chart;
		var clearAll=false;
		
		dojo.addOnLoad(function(){
				
			// setup our chart
			chart = new dojox.charting.Chart2D("easingChart");
			chart.addAxis("x", {
				fixLower: "major",
				fixUpper: "major",
				majorTickStep: 10,
				minorTickStep: 1,
				minorLabels: false,
				htmlLabels: false
			});
			chart.addAxis("y", {
				vertical: true,
				fixLower: "major",
				fixUpper: "major",
				majorTickStep: 10,
				minorTickStep: 1,
				htmlLabels: false
			});
			chart.addPlot("default", {type: "Areas"});
		});
		
		var opt;
		dojo.addOnLoad(function(){
			
			var c = dojo.query(".clone")[0];	
			opt = dojo.byId("select");
			
			for(var i in dojox.fx.easing){
				var n = opt.appendChild(dojo.clone(c));
				n.value = n.innerHTML = i
				// n.innerHTML = i;
			}
		
		    dojo.connect(opt,"onchange",function(e){
				dojo.query("option",opt)
				     // we only want "selected" nodes
				    .filter(function(n){ return n.selected; })
					 // yay, here they are:
					.forEach(function(n){
						console.log(n);
				    });
				makeSeries(opt.value,dojox.fx.easing[opt.value]);
			});
				
			dojo.query(".box").connect("onclick",function(e){
				console.log(opt.value,dojox.fx.easing[opt.value]);	
			});
			
			makeSeries("visible",dojo._defaultEasing);	
				
		});
		
	</script>
</head>
<body class="tundra" style="padding:20px">

	<h1>dojox.fx.easing</h1>
	
	<p>this chart shows time (x axis) vs. position (y axis) for a movement from 0px to 30px modified by easing functions</p>

		<select id="select" multiple="true" size="7" name="easing">
				<option class="clone" value="dojo._defaultEasing">dojo._defaultEasing</option>
		</select>
	
		<div class="box">
			<div id="easingChart" style="height:300px"></div>
		</div>

</body>
</html>