|
28
|
1 |
(function ($) { |
|
|
2 |
|
|
|
3 |
$.fn._vs.chart.StackedAreaChart = function(_this,fn,options) { |
|
|
4 |
var mouseJointTest; |
|
|
5 |
|
|
|
6 |
this.init = function (_this){ |
|
|
7 |
console.log('StackedAreaChart Init') |
|
|
8 |
gravity = new _this.phy.b2Vec2(0.001, 10); |
|
|
9 |
_this.world.m_gravity = gravity; |
|
|
10 |
_this.chartPhySetup = {grounds:[],wall:[]} |
|
|
11 |
this.setupChartPhysics(_this); |
|
|
12 |
//dataFlow(categorys); |
|
|
13 |
}; |
|
|
14 |
|
|
|
15 |
this.setupChartPhysics = function(_this){ |
|
|
16 |
|
|
|
17 |
// Ground |
|
|
18 |
var spacer = _this.settings.chart.spacer; |
|
|
19 |
console.log(_this.settings.chart) |
|
|
20 |
|
|
|
21 |
// Bounds for bar chart |
|
|
22 |
var colSize = (_this.settings.chart.width/_this.settings.data.model.length) |
|
|
23 |
var colBwid = spacer; |
|
|
24 |
var colYpos = _this.settings.chart.height/2+_this.settings.chart.y |
|
|
25 |
|
|
|
26 |
// height of lift |
|
|
27 |
var agreHeight = _this.settings.chart.height - _this.settings.sedimentation.aggregation.height |
|
|
28 |
console.log(agreHeight) |
|
|
29 |
|
|
|
30 |
var tdv = 0; |
|
|
31 |
for (var i = 0; i <_this.settings.data.model.length; i++) { |
|
|
32 |
_this.settings.data.model[i].value=0 |
|
|
33 |
if(typeof(_this.settings.data.strata)!="undefined"){ |
|
|
34 |
if(typeof(_this.settings.data.strata[i])!="undefined"){ |
|
|
35 |
for (var j = 0; j <_this.settings.data.strata[i].length; j++) { |
|
|
36 |
_this.settings.data.model[i].value += _this.settings.data.strata[i][j].value |
|
|
37 |
} |
|
|
38 |
} |
|
|
39 |
} |
|
|
40 |
tdv += _this.settings.data.model[i].value |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
for( var i = 0 ; i<_this.settings.data.model.length+1 ; i++) { |
|
|
45 |
var colXpos = _this.settings.chart.x+(i*colSize); |
|
|
46 |
_this.chartPhySetup.wall[i] = this.createMyChartBox ( |
|
|
47 |
_this, |
|
|
48 |
colXpos, |
|
|
49 |
colYpos, |
|
|
50 |
colBwid, |
|
|
51 |
_this.settings.chart.height/2, |
|
|
52 |
"wall", |
|
|
53 |
_this.settings.chart.wallColor); |
|
|
54 |
|
|
|
55 |
console.log(colXpos,colYpos) |
|
|
56 |
|
|
|
57 |
// Fix incomming points for tokens |
|
|
58 |
if(i<_this.settings.data.model.length){ |
|
|
59 |
_this.settings.sedimentation.incoming.point[i]={ |
|
|
60 |
x:colXpos+(colSize/2), |
|
|
61 |
y:_this.settings.y |
|
|
62 |
} |
|
|
63 |
} |
|
|
64 |
|
|
|
65 |
|
|
|
66 |
// Create lift |
|
|
67 |
if(i<_this.settings.data.model.length){ |
|
|
68 |
_this.chartPhySetup.grounds[i] = this.createMyChartBox ( |
|
|
69 |
_this, |
|
|
70 |
colXpos+(colSize/2), |
|
|
71 |
_this.settings.chart.height+_this.settings.chart.y+_this.settings.sedimentation.aggregation.height, |
|
|
72 |
colSize/2, |
|
|
73 |
_this.settings.chart.height, |
|
|
74 |
"lift", |
|
|
75 |
"rgba(250,250,250,0)"); |
|
|
76 |
|
|
|
77 |
// Move Lift to data |
|
|
78 |
// based on scale (data / all data * height ) |
|
|
79 |
/* |
|
|
80 |
if(_this.settings.data.model[i].value>=0){ |
|
|
81 |
// ????? |
|
|
82 |
var liftPosition = (_this.settings.data.model[i].value/tdv*(_this.settings.chart.height-_this.settings.sedimentation.aggregation.height)) |
|
|
83 |
}else{ |
|
|
84 |
var liftPosition = 0 |
|
|
85 |
}*/ |
|
|
86 |
this.update(_this,{cat:i,y:_this.settings.chart.height}); |
|
|
87 |
} |
|
|
88 |
} |
|
|
89 |
}; |
|
|
90 |
|
|
|
91 |
this.token = function (_this,options){ |
|
|
92 |
//console.log('token query') |
|
|
93 |
var i = options; |
|
|
94 |
var token = { |
|
|
95 |
|
|
|
96 |
x:(_this.settings.sedimentation.incoming.point[i].x+(Math.random()*2)), |
|
|
97 |
y:(_this.settings.sedimentation.incoming.point[i].y+(Math.random()*1)), |
|
|
98 |
t:_this.now(), |
|
|
99 |
size:_this.settings.sedimentation.token.size.original, |
|
|
100 |
category:i, |
|
|
101 |
lineWidth:0, |
|
|
102 |
|
|
|
103 |
} |
|
|
104 |
return token; |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
this.createMyChartBox = function (_this,x,y,w,h,type,color){ |
|
|
108 |
var scale = _this.settings.options.scale |
|
|
109 |
var fixDef = new _this.phy.b2FixtureDef; |
|
|
110 |
fixDef.density = 1.0; |
|
|
111 |
fixDef.friction = 0.5; |
|
|
112 |
fixDef.restitution = 0.2; |
|
|
113 |
|
|
|
114 |
var bodyDef = new _this.phy.b2BodyDef; |
|
|
115 |
//create ground |
|
|
116 |
bodyDef.type = _this.phy.b2Body.b2_staticBody; |
|
|
117 |
fixDef.shape = new _this.phy.b2PolygonShape; |
|
|
118 |
fixDef.shape.SetAsBox(w/scale, h/scale); |
|
|
119 |
bodyDef.position.Set(x/scale,y/scale ); |
|
|
120 |
var box = _this.world.CreateBody(bodyDef).CreateFixture(fixDef); |
|
|
121 |
box.m_userData = {type:type,fillStyle:color,w:w,h:h,x:x,y:y} |
|
|
122 |
//console.log(box) |
|
|
123 |
return box |
|
|
124 |
} |
|
|
125 |
|
|
|
126 |
this.update = function(_this,options){ |
|
|
127 |
var defaultOptions = {cat:0,y:0} |
|
|
128 |
if(_this.chartPhySetup.grounds[options.cat]!=null) { |
|
|
129 |
var myBody = _this.chartPhySetup.grounds[options.cat].GetBody(); |
|
|
130 |
var myPos = myBody.GetWorldCenter(); |
|
|
131 |
myPos.y = (options.y |
|
|
132 |
+ _this.settings.chart.height |
|
|
133 |
+_this.settings.chart.y |
|
|
134 |
+_this.settings.sedimentation.aggregation.height)/ _this.settings.options.scale |
|
|
135 |
myBody.SetPosition(myPos); |
|
|
136 |
//console.log(myBody) |
|
|
137 |
} |
|
|
138 |
} |
|
|
139 |
|
|
|
140 |
|
|
|
141 |
this.getPositionOld = function(_this){ |
|
|
142 |
var result =[] |
|
|
143 |
for (var i = 0; i < _this.chartPhySetup.grounds.length; i++) { |
|
|
144 |
myElement = _this.chartPhySetup.grounds[i] |
|
|
145 |
myBody = myElement.GetBody(); |
|
|
146 |
result.push({ |
|
|
147 |
x:(myBody.GetWorldCenter().x* _this.settings.options.scale), |
|
|
148 |
y:(myBody.GetWorldCenter().y* _this.settings.options.scale), |
|
|
149 |
a:myBody.GetAngle(), |
|
|
150 |
w:myElement.m_userData.w, |
|
|
151 |
h:myElement.m_userData.h, |
|
|
152 |
r:myElement.m_userData.r, |
|
|
153 |
}) |
|
|
154 |
}; |
|
|
155 |
return result |
|
|
156 |
} |
|
|
157 |
|
|
|
158 |
|
|
|
159 |
this.getPosition = function(_this){ |
|
|
160 |
var result =[] |
|
|
161 |
for (var i = 0; i < _this.chartPhySetup.grounds.length; i++) { |
|
|
162 |
myElement = _this.chartPhySetup.grounds[i] |
|
|
163 |
myBody = myElement.GetBody(); |
|
|
164 |
//console.log("myBody.GetWorldCenter().y",myBody.GetWorldCenter().y) |
|
|
165 |
result.push({ |
|
|
166 |
x:(myBody.GetWorldCenter().x* _this.settings.options.scale), |
|
|
167 |
y:(myBody.GetWorldCenter().y* _this.settings.options.scale) |
|
|
168 |
- _this.settings.chart.height |
|
|
169 |
- _this.settings.chart.y |
|
|
170 |
, |
|
|
171 |
a:myBody.GetAngle(), |
|
|
172 |
w:myElement.m_userData.w, |
|
|
173 |
h:myElement.m_userData.h, |
|
|
174 |
r:myElement.m_userData.r, |
|
|
175 |
}) |
|
|
176 |
}; |
|
|
177 |
return result |
|
|
178 |
} |
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
if (typeof(fn)!=undefined){ |
|
|
183 |
var result = this[fn](_this,options); |
|
|
184 |
if (typeof(result)!=undefined){ |
|
|
185 |
return result |
|
|
186 |
} |
|
|
187 |
} |
|
|
188 |
|
|
|
189 |
} |
|
|
190 |
|
|
|
191 |
|
|
|
192 |
})(jQuery); |