|
28
|
1 |
// .................................................................... |
|
|
2 |
// Bar Chart Plug In |
|
|
3 |
// .................................................................... |
|
|
4 |
(function($){ |
|
|
5 |
|
|
|
6 |
var VisualSedimentation = function(element,options){ |
|
|
7 |
|
|
|
8 |
var elem = $(element); |
|
|
9 |
var self = this; |
|
|
10 |
|
|
|
11 |
var world; |
|
|
12 |
var nBodies = []; |
|
|
13 |
var B2D; |
|
|
14 |
var canvas; |
|
|
15 |
var b2Vec2 = Box2D.Common.Math.b2Vec2 |
|
|
16 |
, b2AABB = Box2D.Collision.b2AABB |
|
|
17 |
, b2BodyDef = Box2D.Dynamics.b2BodyDef |
|
|
18 |
, b2Body = Box2D.Dynamics.b2Body |
|
|
19 |
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef |
|
|
20 |
, b2Fixture = Box2D.Dynamics.b2Fixture |
|
|
21 |
, b2World = Box2D.Dynamics.b2World |
|
|
22 |
, b2MassData = Box2D.Collision.Shapes.b2MassData |
|
|
23 |
, b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape |
|
|
24 |
, b2CircleShape = Box2D.Collision.Shapes.b2CircleShape |
|
|
25 |
, b2DebugDraw = Box2D.Dynamics.b2DebugDraw |
|
|
26 |
, b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef |
|
|
27 |
, b2Shape = Box2D.Collision.Shapes.b2Shape |
|
|
28 |
, b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef |
|
|
29 |
, b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef |
|
|
30 |
, b2Joint = Box2D.Dynamics.Joints.b2Joint |
|
|
31 |
, b2PrismaticJointDef= Box2D.Dynamics.Joints.b2PrismaticJointDef |
|
|
32 |
, b2ContactListener = Box2D.Dynamics.b2ContactListener |
|
|
33 |
, b2Settings = Box2D.Common.b2Settings; |
|
|
34 |
|
|
|
35 |
|
|
|
36 |
// Default options |
|
|
37 |
var defaultSettings = { |
|
|
38 |
width:500, |
|
|
39 |
height:440, |
|
|
40 |
layout:'StackedAreaChart',// AxisLabelLayout, AxisLayout, CircleLayout, CollapsedStackLayout, GridLayout, StackedAreaChart |
|
|
41 |
data:{initial:[{label:'Label A',value:20}, |
|
|
42 |
{label:'Label B',value:10}, |
|
|
43 |
{label:'Label C',value:10}], |
|
|
44 |
stream:{provider:"generator", |
|
|
45 |
frequency:1000/60 |
|
|
46 |
}, |
|
|
47 |
} |
|
|
48 |
, |
|
|
49 |
sedimentation:{ |
|
|
50 |
token:{size:20}, // fill color, shape, |
|
|
51 |
flocullate:{ |
|
|
52 |
limit:5, // object size limit before floculate = 2pixels |
|
|
53 |
animation:"collective", // [step,group,bySet] |
|
|
54 |
action:"buffer", // [buffer,continue] |
|
|
55 |
startegy:"Size", // [BufferSize, Time, AcummulationAreaHeight, Fps, Manual] |
|
|
56 |
bufferSize:50, // number of token to make floculation |
|
|
57 |
bufferTime:10000, // time buffer to make flocullation |
|
|
58 |
bufferHeight:50, // height (pixel) to make floculation |
|
|
59 |
bufferFrameRate:25 // if the computer is to slow floculate |
|
|
60 |
}, |
|
|
61 |
suspension:{height:null,incomming:'top'}, // pixel,pourcent,adaptative |
|
|
62 |
accumulation:{height:null}, // pixel,pourcent,adaptative |
|
|
63 |
agregation:{height:300}, // pixel,pourcent,adaptative |
|
|
64 |
}, |
|
|
65 |
options:{spacer:10, |
|
|
66 |
wallColor:"rgba(230,230,230,0)", |
|
|
67 |
label:true, |
|
|
68 |
panel:true, |
|
|
69 |
refresh:1000/1000, |
|
|
70 |
panel:false |
|
|
71 |
} |
|
|
72 |
} |
|
|
73 |
// Merge options with defaults |
|
|
74 |
this.settings = $.extend(defaultSettings, options || {}); |
|
|
75 |
|
|
|
76 |
// Public method |
|
|
77 |
this.publicMethod = function(){ |
|
|
78 |
console.log('publicMethod() called!'); |
|
|
79 |
}; |
|
|
80 |
|
|
|
81 |
// Initialisation - Private method |
|
|
82 |
this.init = function(){ |
|
|
83 |
console.log(this.settings) |
|
|
84 |
console.log('Initialisation'); |
|
|
85 |
//console.log(defaultSettings); |
|
|
86 |
// Create the physical simulation |
|
|
87 |
world = new b2World( |
|
|
88 |
new b2Vec2(0, 10) //gravity |
|
|
89 |
, true //allow sleep |
|
|
90 |
); |
|
|
91 |
|
|
|
92 |
// Create container and canvas for physical simulation drawing |
|
|
93 |
var container = element.appendChild(document.createElement("div")); |
|
|
94 |
container.id = "boxsediviz" |
|
|
95 |
canvas = container.appendChild(document.createElement("canvas")); |
|
|
96 |
canvas.id = "canvas"; |
|
|
97 |
canvas.width = this.settings.width; // TOFIX |
|
|
98 |
canvas.height = this.settings.height; |
|
|
99 |
console.log(element) |
|
|
100 |
|
|
|
101 |
//Update the physical simulation |
|
|
102 |
window.setInterval(update, 1000 / 60); |
|
|
103 |
}; |
|
|
104 |
|
|
|
105 |
var update = function () { |
|
|
106 |
world.Step(1 / 60, 10, 10); |
|
|
107 |
world.DrawDebugData(); |
|
|
108 |
world.ClearForces(); |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
var drawInit = function(){ |
|
|
112 |
ctx = canvas.getContext("2d"); |
|
|
113 |
ctx.fillStyle = "rgb(200,0,0)"; |
|
|
114 |
ctx.font = "14pt Calibri,Geneva,Arial"; |
|
|
115 |
ctx.fillText("Canvas ready for Visual Sedimentation ", 10, 20); |
|
|
116 |
window.setInterval( |
|
|
117 |
$.fn.vs.draw.refresh(ctx,world,this.settings) |
|
|
118 |
, this.settings.options.refresh); |
|
|
119 |
console.log("draw Init ") |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
this.stream = $.fn.vs.stream; |
|
|
123 |
this.draw = $.fn.vs.draw; |
|
|
124 |
this.tokens = $.fn.vs.tokens; |
|
|
125 |
this.decay = $.fn.vs.decay; |
|
|
126 |
this.flocculate = $.fn.vs.flocculate; |
|
|
127 |
|
|
|
128 |
|
|
|
129 |
this.init(); |
|
|
130 |
//drawInit(); |
|
|
131 |
|
|
|
132 |
this.stream.test(); |
|
|
133 |
}; |
|
|
134 |
|
|
|
135 |
visualSedimentation.fn = VisualSedimentation.prototype = { |
|
|
136 |
// API Methods |
|
|
137 |
hide: function() { |
|
|
138 |
this.node.style.display = 'none'; |
|
|
139 |
return this; |
|
|
140 |
}, |
|
|
141 |
|
|
|
142 |
/* gr:function(){ |
|
|
143 |
console.log("test ....") |
|
|
144 |
}*/ |
|
|
145 |
// More methods here, each using 'return this', to enable chaining |
|
|
146 |
}; |
|
|
147 |
|
|
|
148 |
|
|
|
149 |
visualSedimentation.fn.gr= function(){ |
|
|
150 |
console.log("ici VsBarChart.fn.draw") |
|
|
151 |
}; |
|
|
152 |
|
|
|
153 |
$.fn.visualSedimentation = VisualSedimentation; |
|
|
154 |
|
|
|
155 |
$.fn.vs = function(f,options){ |
|
|
156 |
console.log(this); |
|
|
157 |
return this.each(function(){ |
|
|
158 |
var element = $(this); |
|
|
159 |
// Return early if this element already has a plugin instance |
|
|
160 |
if (element.data('VisualSedimentation')) return; |
|
|
161 |
var visualSedimentation = new VisualSedimentation(this,options); |
|
|
162 |
// Store plugin object in this element's data |
|
|
163 |
element.data('visualSedimentation', visualSedimentation); |
|
|
164 |
//visualSedimentation.test(); |
|
|
165 |
}); |
|
|
166 |
}; |
|
|
167 |
$.fn.visualSedimentation.vs = VisualSedimentation; |
|
|
168 |
|
|
|
169 |
})(jQuery); |
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
|