-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshiftSpeedChart.js
287 lines (275 loc) · 9.23 KB
/
shiftSpeedChart.js
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// shift.html - speed range chart
//
// Copyright (c) 2004-2010 Michael Sherman. All rights reserved.
//
// LICENSE: LGPL
//
// see shift.js for revision history
function speedRangeTableG()
{
var rowheight = 8; // height of each row - keep it an even number
var topline = 25; // top line of grid - pixels from top of canvas
var leftedge = 0; // left edge of grid - pixels from left of canvas - FIXME - scaling error if not 0
var canvas = 800; // width of canvas
var line = 25; // the line we are working on - grid drawn top to bottom, then data drawn bottom to top
var minspeed = 0; // lowest speed displayed - mph - LEAVE IT AT ZERO
var maxspeed = 0; // highest speed displayed - mph
var mmaxspeed = 0; // highest speed displayed - kph
var speedgrid = 5; // vert grid spacing - mph
var spdgrdspace = 0; // spacing of speed grid lines
var lowposition = 0; // canvas position for low speed
var speedlen = 0; // length of the speed bar
var fastest = 0; // fastest speed we need to display
var l; // gear size values
var j;
var i2; // for sorting
var j2;
speedrtbl.setPrintable(true);
speedrtbl.clear();
speedrtbl.setColor(textcolor);
speedrtbl.setStroke(1);
speedrtbl.setFont("arial", "14px", Font.PLAIN);
with(Math)
document.mainForm.lRPM.value = lRPM // update display
document.mainForm.hRPM.value = hRPM
// check the selected speed table type ---------------------
if ( document.mainForm.speedRangeButton[0].checked == true )
{
speedRangeType = 0; // mph
//document.mainForm.debugarea.value = "speed in mph"
} else {
speedRangeType = 1; // kph
//document.mainForm.debugarea.value = "speed in kph"
}
// find the fastest speed -----------------------------------
for (j=0; j<numRings; j++) // for each ring
{
if (rings[j] > 0 && rings[j] < 999 ){ // if we have a ring
for ( i=numCogs-1; i>-1; i-- ) // for each cog
{
if (Phspeed[(j*numCogs)+i] > fastest)
{
fastest = Phspeed[(j*numCogs)+i];
}
}
}
}
maxspeed = 10 * (Math.round(fastest / 10));
if (maxspeed < fastest)
{
maxspeed = maxspeed + speedgrid;
}
//document.mainForm.debugarea.value="fastest = " + fastest + " - maxspeed = " + maxspeed;
// scale the grid
pixpermph = Math.round((canvas - leftedge)/(maxspeed - minspeed));
// draw the grid -------------------------------------------
// draw horizontal lines -----------------------------------
line = topline;
speedrtbl.setStroke(1);
speedrtbl.drawLine(leftedge,line,canvas,line); // top
for (j=0; j<numRings; j++)
{
for ( i=numCogs-1; i>-1; i-- ){ // for each cog
line = line + rowheight;
if (showgrid != "hide")
{
speedrtbl.drawLine(leftedge,line,canvas,line); // one for each gear
}
}
}
line = line + rowheight;
speedrtbl.drawLine(leftedge,line,canvas,line); // bottom
// draw vertical grid -----------------------------------
// left side of grid
speedrtbl.drawLine(leftedge,topline,leftedge, topline+(numRings*numCogs*rowheight)+rowheight);
j = minspeed; // should be 0
speedrtbl.drawString (j, leftedge-5, 0); // label
// draw the vertical (speed) lines
if (speedRangeType == 0) // mph
{
//spdgrdspace = Math.round(((canvas-leftedge)/(maxspeed-minspeed)) * speedgrid);
spdgrdspace = Math.round(pixpermph * speedgrid);
} else { // km/h
spdgrdspace = Math.round(((canvas-leftedge)/(((maxspeed * 1.609344)*10)/10)) * speedgrid);
//mmaxspeed = (maxspeed * 1.609344)*10)/10;
}
j = j + speedgrid;
l = leftedge + spdgrdspace;
while (l < canvas) // km/h - mph lines
{
speedrtbl.drawLine(l,topline,l,topline+(numRings*numCogs*rowheight)+rowheight);
speedrtbl.drawString (j, l-10, 0); // label
l = l + spdgrdspace;
j = j + speedgrid;
}
speedrtbl.drawString (j, l-15, 0); // label - on kph usually hangs off the edge - should I remove?
// right side of grid
speedrtbl.drawLine(canvas,topline,canvas,topline+(numRings*numCogs*rowheight)+rowheight);
// now draw the bars -----------------------------------
line = line - rowheight; // back up to bottom line
if(sortgears == "no") // unsorted display
{
// for each chainring
for (j=0; j<numRings; j++) // for each ring
{
if (rings[j] > 0 && rings[j] < 999 ) // if we have a ring
{
for ( i=numCogs-1; i>-1; i-- ) // for each cog
{
with(Math)
lowposition = Math.round(Plspeed[(j*numCogs)+i] * pixpermph); // x position for low speed end of bar
speedlen = Math.round(Phspeed[(j*numCogs)+i] * pixpermph)-lowposition; // len of bar
if (j==0) // first row - small chainring - red
{
if (i == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(red);
}
speedrtbl.fillRect(lowposition,(line-(rowheight/2))+1,speedlen,rowheight-2);
speedrtbl.drawString (cogs[i], lowposition-20,line-rowheight-5); // label
}
if (j==1) // second row - black
{
if (i == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(black);
}
speedrtbl.fillRect(lowposition,(line-(rowheight/2))+1,speedlen,rowheight-2);
speedrtbl.drawString (cogs[i], lowposition-20,line-rowheight-5); // label
}
if (j==2) // third row - was orange
{
if (i == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(blue);
}
speedrtbl.fillRect(lowposition,(line-(rowheight/2))+1,speedlen,rowheight-2);
speedrtbl.drawString (cogs[i], lowposition-20,line-rowheight-5); // label
}
line = line - rowheight;
} // end of for each cog
} // end of if we have a ring
} // end of for each ring
} // end of unsorted display
else
{ // start of sorted display
j = 0; // smallest ring on triple, or only ring
if (numRings == 1 || numRings == 3 ) // if there are 3 rings only sort the largest two
{
for ( i=numCogs-1; i>-1; i-- ) // for each cog
{
with(Math)
lowposition = Math.round(Plspeed[(j*numCogs)+i] * pixpermph); // x position for low speed end of bar
speedlen = Math.round(Phspeed[(j*numCogs)+i] * pixpermph)-lowposition; // len of bar
if (i == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(red);
}
speedrtbl.fillRect(lowposition,(line-(rowheight/2))+1,speedlen,rowheight-2);
speedrtbl.drawString (cogs[i], lowposition-20,line-rowheight-5); // label
line = line - rowheight;
}
j++;
}
if (numRings == 2 || numRings == 3 ) // for 2 and 3 chainrings
{
// now the two main rings
j2 = j+1; // big ring
i = numCogs-1; // pointer to speeds on small ring
i2 = i; // pointer to speeds on big ring
while (i2 > -1) // while we're not done with the cog for the big ring
{
// while gears on small ring lower than next large ring gear
while ((Plspeed[(j*numCogs)+i] <= Plspeed[(j2*numCogs)+i2]) && i >= 0)
{
// display cogs from smaller ring
with(Math)
lowposition = Math.round(Plspeed[(j*numCogs)+i] * pixpermph); // x position for low speed end of bar
speedlen = Math.round(Phspeed[(j*numCogs)+i] * pixpermph)-lowposition; // len of bar
if (numRings > 2) // with 3 chain rings, smaller one is black
{
if (i == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(black);
}
}
else // with 2 chain rings, the smaller one is black
{
if (i == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(red);
}
}
speedrtbl.fillRect(lowposition,(line-(rowheight/2))+1,speedlen,rowheight-2);
speedrtbl.drawString (cogs[i], lowposition-20,line-rowheight-5); // label
line = line - rowheight;
if (i > -1) // not to end of this group of cogs
{
i--;
}
}
while ( (Plspeed[(j2*numCogs)+i2] < Plspeed[(j*numCogs)+i]) || ( i == -1 && i2 > -1) )
{
// display cogs from larger (3rd) ring, it is blue
with(Math)
lowposition = Math.round(Plspeed[(j2*numCogs)+i2] * pixpermph); // x position for low speed end of bar
speedlen = Math.round(Phspeed[(j2*numCogs)+i2] * pixpermph)-lowposition; // len of bar
if (numRings > 2)
{
if (i2 == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(blue);
}
}
else
{
if (i2 == highlightGear)
{
speedrtbl.setColor(highlight2); // highlight cog
}
else
{
speedrtbl.setColor(black);
}
}
speedrtbl.fillRect(lowposition,(line-(rowheight/2))+1,speedlen,rowheight-2);
speedrtbl.drawString (cogs[i2], lowposition-20,line-rowheight-5); // label
line = line - rowheight;
if ( i2 > -1 )
{
i2--;
}
}
} // end of while
} // end of else not 3 or 1 chain rings
} // end of sorted display
speedrtbl.paint();
}