-
Notifications
You must be signed in to change notification settings - Fork 0
/
amcharts_per_engine.html
247 lines (230 loc) · 7.14 KB
/
amcharts_per_engine.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
<!DOCTYPE html>
<html>
<head>
<!-- These is our main stylesheet -->
<link rel="stylesheet" type="text/css" href="./assets/build/css/styles.css">
<!-- This script takes care of rendering the chart -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.js" integrity="sha256-1qeNeAAFNi/g6PFChfXQfa6CQ8eXoHXreohinZsoJOQ=" crossorigin="anonymous"></script> -->
<!-- This script takes care of allowing us to write math stuffs -->
<!-- <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script> -->
<!-- This script allows us to get a random color with ease -->
<script src="./rcolor.js"></script>
<!-- Snap.svg, for svg creation -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.4.1/snap.svg.js"></script>
<!-- Latest jQuery 2016-11-25 -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<!-- These are our own scripts, which allow us to organize our project and improve readability and maintainability -->
<script src="./engines.js"></script>
<script src="./stockEngines.js"></script>
<title>NTR Engine Plot</title>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/xy.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
</head>
<body>
<!-- Styles -->
<style>
body {
margin: 0;
padding: 0;
}
#chartdiv {
width: 100vw;
height: 100vh;
}
</style>
<!-- Chart code -->
<script>
// Prepare engines data
var allEngines = engines.concat(stockEngines);
$.each( allEngines, function( k, v ) {
v.twr = v.thrust / ( v.weight * 9.807 );
v.vol = Math.PI * v.diameter / 2 * v.height;
});
data = {};
var i = 0;
$.each( allEngines, function( k0, v0 ) {
$.each( v0, function( k1, v1 ) {
data[ k1+i ] = v1;
});
i++;
});
// Prepare propellants/color data
var color = new RColor;
var propellants = {
"Decane": "#d9152a",
"Methane": "#C8560A",
"Ammonia": "#d9bd15",
"Nitrogen": "#8dd915",
"Water": "#31d915",
"Helium": "#15bfd9",
"Hydrogen": "#1589d9",
"Deuterium": "#9115d9",
"Hydrogen Deuteride": "#d915b0",
};
$.each( allEngines, function( k0, v0 ) {
if ( !propellants.hasOwnProperty( v0.propellant ) ) {
propellants[ v0.propellant ] = color.get(true, 0.9, 0.85);
}
});
// Prepare graphs
var graphs = [];
var baseGraph = {
"bullet": "circle",
// "bullet": "custom",
"bulletBorderAlpha": 0.9,
"bulletAlpha": 0.3,
"lineAlpha": 0,
"fillAlphas": 0,
"maxBulletSize": 100,
"balloonFunction": function( data ) {
// Identify which subIndex we're talking about
var i = 0;
while ( data.dataContext[ 'twr'+i ] != data.values.y ) {
i++;
if ( i > 1000 ) {
console.log( "break!!!" );
break;
}
}
// Now build a table with all the information
var html =
"<table><tr>"+
"<tr><th>Name</th><td>"+
(data.dataContext[ 'label'+i ]||'---')+
"</td></tr>"+
"<tr><th>Propellant</th><td>"+
(data.dataContext[ 'propellant'+i ]||'---')+
"</td></tr>"+
"<tr><th>Author</th><td>"+
(data.dataContext[ 'author'+i ]||'---')+
"</td></tr>"+
"<tr><th>Thrust</th><td>"+
(data.dataContext[ 'thrust'+i ]||'---')+
"</td></tr>"+
"<tr><th>Cost</th><td>"+
(data.dataContext[ 'cost'+i ]||'---')+
"</td></tr>"+
"<tr><th>Gimbal</th><td>"+
(data.dataContext[ 'gimbal'+i ]||'---')+
"</td></tr>"+
"<tr><th>Weight</th><td>"+
(data.dataContext[ 'weight'+i ]||'---')+
"</td></tr>"+
"<tr><th>Diameter</th><td>"+
(data.dataContext[ 'diameter'+i ]||'---')+
"</td></tr>"+
"<tr><th>Height</th><td>"+
(data.dataContext[ 'height'+i ]||'---')+
"</td></tr>"+
"</tr></table>";
// If it's a stock design, make it very visually obvious
if ( data.dataContext[ 'stock'+i ] ) {
html += "<h3 style='text-align:center;'>(This is a Stock Design)</h3>";
}
// Return html
return html;
},
}
g = 0;
var maxSubInd = i;
for ( var i = 0; i < maxSubInd; i++ ) {
g = $.extend( true, {}, baseGraph );
g.lineColor = propellants[ data['propellant'+i] ];
g.valueField = "vol"+i;
g.xField = "thrust"+i;
g.yField = "twr"+i;
graphs.push( g );
}
graphs.push({
});
var chart = AmCharts.makeChart( "chartdiv", {
"type": "xy",
"theme": "light",
"dataProvider": [data],
"mouseWheelZoomEnabled": true,
"balloon": {
"animationDuration": 0,
"fadeOutDuration": 0.1,
"maxWidth": 300,
"textAlign": "left",
"pointerWidth": 0,
"adjustBorderColor": false,
"borderAlpha": 0,
"shadowAlpha": 0,
"fillAlpha": 0.8,
"color": "#FFFFFF",
},
"valueAxes": [
// Bottom is Thrust Power
{
"position": "bottom",
"minimum": 100,
"minMaxMultiplier": 2,
"logarithmic": true,
"autoGridCount": false,
"minorGridEnabled": true,
"gridCount": 10,
"gridAlpha": 0.3,
"gridThickness": 1,
"labelFunction": function( number ) {
if ( number < 1000 ) {
number = number;
mult = "";
} else if ( number < 1000000 ) {
number = number/1000;
mult = "K";
} else if ( number < 1000000000 ) {
number = number/1000000;
mult = "M";
} else {
number = number/1000000000;
mult = "G";
}
return number + mult + "N";
}
},
// Left is Engine Size
{
"position": "left",
"minimum": 1,
"minMaxMultiplier": 2,
"logarithmic": true,
"autoGridCount": false,
"minorGridEnabled": true,
"gridCount": 10,
"gridAlpha": 0.3,
"gridThickness": 1,
"labelFunction": function( number ) {
if ( number < 1000 ) {
number = number;
mult = "";
} else if ( number < 1000000 ) {
number = number/1000;
mult = "K";
} else if ( number < 1000000000 ) {
number = number/1000000;
mult = "M";
} else {
number = number/1000000000;
mult = "G";
}
return number + mult + "g₀";
}
}
],
"graphs": graphs,
"marginTop": 100,
// "chartScrollbar": {
// "autoGridCount": true,
// "oppositeAxis": true,
// },
});
</script>
<!-- HTML -->
<div id="chartdiv"></div>
</body>
</html>