html5jp_graphs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitigore +2 -0
  2. data/README.rdoc +82 -0
  3. data/Rakefile +22 -0
  4. data/html5jp_graphs.gemspec +17 -0
  5. data/lib/examples/sample_graph_circle_1.html +54 -0
  6. data/lib/examples/sample_graph_circle_2.html +61 -0
  7. data/lib/examples/sample_graph_line_1.html +44 -0
  8. data/lib/examples/sample_graph_line_2.html +53 -0
  9. data/lib/examples/sample_graph_radar_1.html +47 -0
  10. data/lib/examples/sample_graph_radar_2.html +52 -0
  11. data/lib/examples/sample_graph_vbar_1.html +51 -0
  12. data/lib/examples/sample_graph_vbar_2.html +52 -0
  13. data/lib/examples/sample_graph_vbar_3.html +52 -0
  14. data/lib/examples/sample_graph_vbar_4.html +52 -0
  15. data/lib/generators/html5jp_graphs/USAGE +8 -0
  16. data/lib/generators/html5jp_graphs/html5jp_graphs_generator.rb +12 -0
  17. data/lib/generators/html5jp_graphs/templates/excanvas/AUTHORS +10 -0
  18. data/lib/generators/html5jp_graphs/templates/excanvas/COPYING +202 -0
  19. data/lib/generators/html5jp_graphs/templates/excanvas/README +22 -0
  20. data/lib/generators/html5jp_graphs/templates/excanvas/examples/example1.html +93 -0
  21. data/lib/generators/html5jp_graphs/templates/excanvas/examples/example2.html +513 -0
  22. data/lib/generators/html5jp_graphs/templates/excanvas/examples/example3.html +284 -0
  23. data/lib/generators/html5jp_graphs/templates/excanvas/examples/ff.jpg +0 -0
  24. data/lib/generators/html5jp_graphs/templates/excanvas/excanvas-compressed.js +19 -0
  25. data/lib/generators/html5jp_graphs/templates/excanvas/excanvas.js +785 -0
  26. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/arc.html +49 -0
  27. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/linewidth.html +47 -0
  28. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/overflow.html +37 -0
  29. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/quadraticcurve.html +74 -0
  30. data/lib/generators/html5jp_graphs/templates/excanvas/testcases/resizing.html +65 -0
  31. data/lib/generators/html5jp_graphs/templates/graph/circle.js +407 -0
  32. data/lib/generators/html5jp_graphs/templates/graph/line.js +577 -0
  33. data/lib/generators/html5jp_graphs/templates/graph/radar.js +545 -0
  34. data/lib/generators/html5jp_graphs/templates/graph/vbar.js +1156 -0
  35. data/lib/html5jp_graphs.rb +1 -0
  36. data/lib/html5jp_graphs/version.rb +3 -0
  37. data/lib/html5jp_graphs_helper.rb +255 -0
  38. data/tasks/html5jp_graphs_tasks.rake +4 -0
  39. data/test/html5jp_graphs_test.rb +8 -0
  40. metadata +88 -0
@@ -0,0 +1,1156 @@
1
+ // Copyright 2007 futomi http://www.html5.jp/
2
+ // graph_vbar ver 1.0.1 2007-12-17
3
+ // since 2007-10-17
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+
17
+ if( typeof html5jp == 'undefined' ) {
18
+ html5jp = new Object();
19
+ }
20
+ if( typeof html5jp.graph == 'undefined' ) {
21
+ html5jp.graph = new Object();
22
+ }
23
+
24
+ /* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
25
+ * コンストラクタ
26
+ * ---------------------------------------------------------------- */
27
+ html5jp.graph.vbar = function (id) {
28
+ var elm = document.getElementById(id);
29
+ if(! elm) { return; }
30
+ if(elm.nodeName != "CANVAS") { return; }
31
+ if(elm.parentNode.nodeName != "DIV") { return; };
32
+ this.canvas = elm;
33
+ /* CANVAS要素 */
34
+ if ( ! this.canvas ){ return; }
35
+ if ( ! this.canvas.getContext ){ return; }
36
+ /* 2D コンテクストの生成 */
37
+ this.ctx = this.canvas.getContext('2d');
38
+ this.canvas.style.margin = "0";
39
+ this.canvas.parentNode.style.position = "relative";
40
+ this.canvas.parentNode.style.padding = "0";
41
+ };
42
+ /* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
43
+ * 描画
44
+ * ---------------------------------------------------------------- */
45
+ html5jp.graph.vbar.prototype.draw = function(items, inparams) {
46
+ if( ! this.ctx ) {return;}
47
+ this.items = items;
48
+ /* パラメータの初期化 */
49
+ var params = {
50
+ x: [],
51
+ y: [],
52
+ yMax: null,
53
+ yMin: 0,
54
+ backgroundColor: "#ffffff",
55
+ gBackgroundColor: "#dddddd",
56
+ gGradation: true,
57
+ barShape: "square",
58
+ barColors: null,
59
+ _barColors: ["rgb(24,41,206)", "rgb(198,0,148)", "rgb(214,0,0)", "rgb(255,156,0)", "rgb(33,156,0)", "rgb(33,41,107)", "rgb(115,0,90)", "rgb(132,0,0)", "rgb(165,99,0)", "rgb(24,123,0)"],
60
+ barGradation: true,
61
+ barAlpha: 0.7,
62
+ borderAlpha: 0.2,
63
+ xAxisWidth: 1,
64
+ xAxisColor: "#aaaaaa",
65
+ yAxisWidth: 1,
66
+ yAxisColor: "#aaaaaa",
67
+ xScale: true,
68
+ xScaleColor: "#000000",
69
+ xScaleFontSize: "10px",
70
+ xScaleFontFamily: "Arial,sans-serif",
71
+ yScale: true,
72
+ yScaleColor: "#000000",
73
+ yScaleFontSize: "10px",
74
+ yScaleFontFamily: "Arial,sans-serif",
75
+ xCaptionColor: "#000000",
76
+ xCaptionFontSize: "12px",
77
+ xCaptionFontFamily: "Arial,sans-serif",
78
+ yCaptionColor: "#000000",
79
+ yCaptionFontSize: "12px",
80
+ yCaptionFontFamily: "Arial,sans-serif",
81
+ aLineWidth: 1,
82
+ aLineAlpha: 0.2,
83
+ dLabel: true,
84
+ dLabelColor: "#000000",
85
+ dLabelFontSize: "10px",
86
+ dLabelFontFamily: "Arial,sans-serif",
87
+ legend: true,
88
+ legendFontSize: "12px",
89
+ legendFontFamily: "Arial,sans-serif",
90
+ legendColor: "#000000"
91
+ };
92
+ if( inparams && typeof(inparams) == 'object' ) {
93
+ for( var key in inparams ) {
94
+ if( key.match(/^_/) ) { continue; }
95
+ params[key] = inparams[key];
96
+ }
97
+ }
98
+ if( params.barColors != null && params.barColors.length > 0 ) {
99
+ for( var i=0; i<params._barColors.length; i++ ) {
100
+ var c = params.barColors[i];
101
+ var co = this._csscolor2rgb(c);
102
+ if( co == null ) {
103
+ params.barColors[i] = params._barColors[i];
104
+ } else {
105
+ params.barColors[i] = c;
106
+ }
107
+ }
108
+ } else {
109
+ params.barColors = params._barColors;
110
+ }
111
+ this.params = params;
112
+ /* CANVAS要素の横幅が縦幅の1.5倍未満、または縦幅が200未満であれば凡例は強制的に非表示 */
113
+ if(this.canvas.width / this.canvas.height < 1.5 || this.canvas.height < 200) {
114
+ params.legend == false;
115
+ }
116
+ /* 項目の数(最大10個) */
117
+ var item_num = items.length;
118
+ if(item_num > 10) { item_num = 10; }
119
+ /* 最大項目数を算出 */
120
+ var max_n = 0;
121
+ for(var i=0; i<item_num; i++) {
122
+ var n = items[i].length;
123
+ if(n < 2) { continue; }
124
+ if(n - 1 >= max_n) {
125
+ max_n = n - 1;
126
+ }
127
+ }
128
+ params.max_n = max_n;
129
+ if(max_n == 0) {
130
+ throw new Error('no graph item data.' + n);
131
+ }
132
+ /* 最大値を算出 */
133
+ var max_v = 0;
134
+ for(var i=1; i<=max_n; i++) {
135
+ var n = items.length;
136
+ var sum = 0;
137
+ for(var j=0; j<n; j++) {
138
+ var v = items[j][i];
139
+ if( isNaN(v) || v < 0 ) {
140
+ throw new Error('invalid graph item data.' + n);
141
+ }
142
+ sum += v;
143
+ }
144
+ if(sum >= max_v) {
145
+ max_v = sum;
146
+ }
147
+ }
148
+ if( typeof(params.yMin) != "number" ) {
149
+ params.yMin = 0;
150
+ }
151
+ if( typeof(params.yMax) != "number" ) {
152
+ params.yMax = max_v * 1.1
153
+ } else if( params.yMax <= max_v) {
154
+ params.yMax = max_v;
155
+ }
156
+ /* 補助線の位置を自動算出 */
157
+ if( params.y.length < 2 ) {
158
+ params.aLinePositions = this._aline_positions_auto_calc(params.yMin, params.yMax);
159
+ } else {
160
+ params.aLinePositions = params.y.slice(1);
161
+ }
162
+ /* グラフの軸のcanvas内座標 */
163
+ var cpos = {
164
+ x0: this.canvas.width * 0.05,
165
+ y0: this.canvas.height * 0.95,
166
+ x1: this.canvas.width * 0.95,
167
+ y1: this.canvas.height * 0.05
168
+ };
169
+ if(params.legend == true) {
170
+ cpos.x1 = this.canvas.width * 0.7;
171
+ }
172
+ if(params.x.length > 0) {
173
+ var x_caption_text_size = this._getTextBoxSize("あa", params.xCaptionFontSize, params.xCaptionFontFamily);
174
+ cpos.y0 -= x_caption_text_size.h * 1.5;
175
+ cpos.x_caption_y = cpos.y0 + x_caption_text_size.h/2;
176
+ }
177
+ if(params.xScale == true || params.x.length > 1) {
178
+ var x_scale_text_size = this._getTextBoxSize("あa", params.xScaleFontSize, params.xScaleFontFamily);
179
+ cpos.y0 -= x_scale_text_size.h * 1.5;
180
+ cpos.x_scale_y = cpos.y0 + x_scale_text_size.h * 0.7;
181
+ }
182
+ if(params.y.length > 0) {
183
+ var y_caption_text_size = this._getTextBoxSize("あa", params.yCaptionFontSize, params.yCaptionFontFamily);
184
+ cpos.y1 += y_caption_text_size.h * 1.5;
185
+ cpos.y_caption_y = cpos.y1 - y_caption_text_size.h * 1.5;
186
+ }
187
+ if(params.yScale == true || params.y.length > 1) {
188
+ var y_scale_text_size = this._getTextBoxSize(params.aLinePositions[params.aLinePositions.length-1].toString(), params.yScaleFontSize, params.yScaleFontFamily);
189
+ cpos.x0 += y_scale_text_size.w * 1.1;
190
+ }
191
+ cpos.w = cpos.x1 - cpos.x0;
192
+ cpos.h = cpos.y0 - cpos.y1;
193
+ /* 棒の幅の半径を算出 */
194
+ if(params.barShape == "square") {
195
+ cpos.r = 0.6 * cpos.w / max_n / 2;
196
+ } else {
197
+ cpos.r = 0.7 * cpos.w / max_n / 2;
198
+ }
199
+ if(cpos.r < 5 && cpos.r >=3) {
200
+ params.barShape = "line";
201
+ }
202
+ params.cpos = cpos;
203
+ /* */
204
+ this.params = params;
205
+ /* CANVASの背景を塗る */
206
+ this._draw_canvas_background();
207
+ /* グラフの背景を描画 */
208
+ this._draw_graph_background();
209
+ /* 棒グラフを描写 */
210
+ var x_scale_positions = new Array();
211
+ var d_labels = new Array();
212
+ for(var i=1; i<=max_n; i++) {
213
+ var sum = 0;
214
+ /* x軸座標 */
215
+ var x = cpos.x0 + (i - 0.5) * ( cpos.w / max_n );
216
+ x_scale_positions.push(x);
217
+ /* */
218
+ for(var j=0; j<items.length; j++) {
219
+ /* 項目の値 */
220
+ var v = items[j][i];
221
+ /* 棒の底辺の位置 */
222
+ var y = cpos.y0 - sum * cpos.h / params.yMax;
223
+ /* 棒の高さ */
224
+ var h = v * cpos.h / params.yMax;
225
+ /* 棒を描画 */
226
+ if( params.barShape == "line" ) {
227
+ this._draw_vertical_bar_line(this.ctx, x, y, h, cpos.r, params.barColors[j], params.barAlpha);
228
+ } else if( params.barShape == "flat" ) {
229
+ this._draw_vertical_bar_flat(this.ctx, x, y, h, cpos.r, params.barColors[j], params.barAlpha, params.borderAlpha, params.barGradation);
230
+ } else if( params.barShape == "square" ) {
231
+ this._draw_vertical_bar_square(this.ctx, x, y, h, cpos.r, cpos.r/3, params.barColors[j], params.barAlpha, params.borderAlpha, params.barGradation);
232
+ } else if( params.barShape == "cylinder" ) {
233
+ this._draw_vertical_bar_cylinder(this.ctx, x, y, h, cpos.r, cpos.r/3, params.barColors[j], params.barAlpha, params.borderAlpha, params.barGradation);
234
+ }
235
+ /* 値の和を算出 */
236
+ sum += v;
237
+ }
238
+ d_labels.push( { x:x, v:sum } );
239
+ }
240
+ /* データラベルを描画 */
241
+ this._draw_data_label(d_labels);
242
+ /* x軸目盛とキャプションを表示 */
243
+ this._draw_x_scale_label(x_scale_positions);
244
+ /* y軸目盛とキャプションを表示 */
245
+ this._draw_y_scale_label();
246
+ /* 凡例を描画 */
247
+ this._draw_legend();
248
+ };
249
+
250
+ /* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
251
+ * 以下、内部関数
252
+ * ──────────────────────────────── */
253
+
254
+ /* ------------------------------------------------------------------
255
+ データラベルを描画
256
+ * ---------------------------------------------------------------- */
257
+ html5jp.graph.vbar.prototype._draw_data_label = function(labels) {
258
+ var p = this.params;
259
+ if( p.dLabel != true ) { return; }
260
+ var n = labels.length;
261
+ var pos = new Array();
262
+ var max_w = 0;
263
+ for( var i=0; i<n; i++ ) {
264
+ var text = labels[i].v.toString();
265
+ var s = this._getTextBoxSize(text, p.dLabelFontSize, p.dLabelFontFamily);
266
+ max_w = Math.max(s.w, max_w);
267
+ var dx = labels[i].x - s.w / 2;
268
+ var dy = p.cpos.y0 - labels[i].v * p.cpos.h / p.yMax - s.h * 1.3;
269
+ pos.push( { x:dx, y:dy, text:text } );
270
+ }
271
+ if( max_w < p.cpos.w / n ) {
272
+ for( var i=0; i<n; i++ ) {
273
+ this._drawText(pos[i].x, pos[i].y, pos[i].text, p.dLabelFontSize, p.dLabelFontFamily, p.dLabelColor);
274
+ }
275
+ }
276
+ };
277
+ /* ------------------------------------------------------------------
278
+ 凡例を描画
279
+ * ---------------------------------------------------------------- */
280
+ html5jp.graph.vbar.prototype._draw_legend = function() {
281
+ var p = this.params;
282
+ if(p.legend != true) { return; }
283
+ /* DIV要素を仮に挿入してみて高さを調べる(1行分の高さ) */
284
+ var s = this._getTextBoxSize('あTEST', p.legendFontSize, p.legendFontFamily);
285
+ /* 凡例の各種座標を算出 */
286
+ var item_num = this.items.length;
287
+ var lpos = {
288
+ x: Math.round( p.cpos.x1 + this.canvas.width * 0.05 ),
289
+ y: Math.round( ( this.canvas.height - ( s.h * item_num + s.h * 0.2 * (item_num - 1) ) ) / 2 ),
290
+ h: s.h
291
+ };
292
+ lpos.cx = lpos.x + Math.round( lpos.h * 1.5 ); // 文字表示開始位置(x座標)
293
+ lpos.cw = this.canvas.width - lpos.cx; // 文字表示幅
294
+ /* 描画 */
295
+ for(var i=0; i<item_num; i++) {
296
+ /* 文字 */
297
+ this._drawText(lpos.cx, lpos.y, this.items[i][0], p.legendFontSize, p.legendFontFamily, p.legendColor);
298
+ /* 記号(背景) */
299
+ this.ctx.save();
300
+ this._make_path_legend_mark(lpos.x, lpos.y, s.h, s.h);
301
+ this.ctx.fillStyle = p.gBackgroundColor;
302
+ this.ctx.fill();
303
+ this.ctx.restore();
304
+ /* 記号(塗り) */
305
+ this.ctx.save();
306
+ this._make_path_legend_mark(lpos.x, lpos.y, s.h, s.h);
307
+ this.ctx.fillStyle = p.barColors[i];
308
+ this.ctx.globalAlpha = p.barAlpha;
309
+ this.ctx.fill();
310
+ this.ctx.restore();
311
+ /* 枠線 */
312
+ this.ctx.save();
313
+ this._make_path_legend_mark(lpos.x, lpos.y, s.h, s.h);
314
+ this.ctx.strokeStyle = p.barColors[i];
315
+ this.ctx.globalAlpha = p.borderAlpha;
316
+ this.ctx.stroke();
317
+ this.ctx.restore();
318
+ /* グラデーション */
319
+ if( ! document.uniqueID && p.barGradation == true ) {
320
+ this.ctx.save();
321
+ this._make_path_legend_mark(lpos.x, lpos.y, s.h, s.h);
322
+ var grad = this.ctx.createLinearGradient(lpos.x, lpos.y, lpos.x+s.h, lpos.y+s.h);
323
+ grad.addColorStop(0, "rgba(0, 0, 0, 0.1)");
324
+ grad.addColorStop(0.3, "rgba(255, 255, 255, 0.1)");
325
+ grad.addColorStop(1, "rgba(0, 0, 0, 0.4)");
326
+ this.ctx.fillStyle = grad;
327
+ this.ctx.fill();
328
+ this.ctx.restore();
329
+ }
330
+ lpos.y = lpos.y + lpos.h * 1.2;
331
+ }
332
+ };
333
+ html5jp.graph.vbar.prototype._make_path_legend_mark = function(x,y,w,h) {
334
+ this.ctx.beginPath();
335
+ this.ctx.moveTo(x, y);
336
+ this.ctx.lineTo(x+w, y);
337
+ this.ctx.lineTo(x+w, y+h);
338
+ this.ctx.lineTo(x, y+h);
339
+ this.ctx.closePath();
340
+ };
341
+ /* ------------------------------------------------------------------
342
+ 補助線の位置を自動算出
343
+ * ---------------------------------------------------------------- */
344
+ html5jp.graph.vbar.prototype._aline_positions_auto_calc = function(min, max) {
345
+ var range = max - min;
346
+ var power10 = Math.floor( Math.log(range) / Math.log(10) );
347
+ var unit = Math.pow( 10, power10);
348
+ if( (Math.log(range) / Math.log(10)) % 1 == 0 ) {
349
+ unit = unit / 10;
350
+ }
351
+ var keta_age = 1;
352
+ if(unit < 1) {
353
+ keta_age += Math.abs(power10);
354
+ }
355
+ var p = Math.pow(10, keta_age);
356
+ range = range * p;
357
+ unit = unit * p;
358
+ min = min * p;
359
+ max = max * p;
360
+ var array = [min];
361
+ var unum = range / unit;
362
+ if( unum > 5 ) {
363
+ unit = unit * 2;
364
+ } else if( unum <= 2 ) {
365
+ unit = unit * 3 / 10
366
+ }
367
+ var i = 1;
368
+ while(min+unit*i<=max) {
369
+ array.push(min+unit*i);
370
+ i++;
371
+ }
372
+ for(var i=0; i<array.length; i++) {
373
+ array[i] = array[i] / p;
374
+ }
375
+ return array;
376
+ };
377
+ /* ------------------------------------------------------------------
378
+ y軸目盛とキャプションを表示
379
+ * ---------------------------------------------------------------- */
380
+ html5jp.graph.vbar.prototype._draw_y_scale_label = function(pos) {
381
+ var p = this.params;
382
+ if( p.y.length > 0 ) {
383
+ /* y軸キャプションテキスト */
384
+ var text = p.y[0].toString();
385
+ if(text != "") {
386
+ /* y軸キャプションテキスト領域のサイズを算出 */
387
+ var s = this._getTextBoxSize(text, p.yCaptionFontSize, p.yCaptionFontFamily);
388
+ /* y軸キャプションテキストを描画すべき左上端の座標を算出 */
389
+ var x = p.cpos.x0 - s.w/2;
390
+ if(x < this.canvas.width*0.05) {
391
+ x = this.canvas.width*0.05;
392
+ }
393
+ /* y軸キャプションテキストを描画 */
394
+ this._drawText(x, p.cpos.y_caption_y, text, p.yCaptionFontSize, p.yCaptionFontFamily, p.yCaptionColor);
395
+ }
396
+ }
397
+ if( p.yScale == true && p.aLinePositions.length > 0 ) {
398
+ for( var i=0; i<p.aLinePositions.length; i++ ) {
399
+ var v = p.aLinePositions[i];
400
+ if(v > p.yMax) { continue; }
401
+ var text = v.toString();
402
+ var s = this._getTextBoxSize(text, p.yScaleFontSize, p.yScaleFontFamily);
403
+ var x = p.cpos.x0 - p.cpos.r/2 - s.w*1.1;
404
+ var y = p.cpos.y0 - v * p.cpos.h / (p.yMax - p.yMin) - s.h/2;
405
+ if( p.barShape == "cylinder" || p.barShape == "square" ) {
406
+ var d = p.cpos.r / 3;
407
+ y += d;
408
+ }
409
+ this._drawText(x, y, text, p.yScaleFontSize, p.yScaleFontFamily, p.yScaleColor);
410
+ }
411
+ }
412
+ };
413
+ /* ------------------------------------------------------------------
414
+ x軸目盛とキャプションを表示
415
+ * ---------------------------------------------------------------- */
416
+ html5jp.graph.vbar.prototype._draw_x_scale_label = function(pos) {
417
+ var p = this.params;
418
+ if( p.x.length > 0 ) {
419
+ /* x軸キャプションテキスト */
420
+ var text = p.x[0].toString();
421
+ if(text != "") {
422
+ /* x軸キャプションテキスト領域のサイズを算出 */
423
+ var s = this._getTextBoxSize(text, p.xCaptionFontSize, p.xCaptionFontFamily);
424
+ /* x軸キャプションテキストを描画すべき左上端の座標を算出 */
425
+ var x = Math.round( p.cpos.x0 + p.cpos.w/2 - s.w/2 );
426
+ /* x軸キャプションテキストを描画 */
427
+ this._drawText(x, p.cpos.x_caption_y, text, p.xCaptionFontSize, p.xCaptionFontFamily, p.xCaptionColor);
428
+ }
429
+ }
430
+ if( p.xScale == true && p.x.length > 1 ) {
431
+ for(var i=0; i<pos.length; i++) {
432
+ if(i + 1 > p.x.length - 1) { break; }
433
+ /* x軸目盛テキスト */
434
+ var text = p.x[i+1].toString();
435
+ if(text == "") { continue; }
436
+ /* x軸目盛テキスト領域のサイズを算出 */
437
+ var s = this._getTextBoxSize(text, p.xScaleFontSize, p.xScaleFontFamily);
438
+ /* x軸目盛テキストを描画すべき左上端の座標を算出 */
439
+ var x = Math.round( pos[i] - s.w / 2 );
440
+ /* x軸目盛テキストを描画 */
441
+ this._drawText(x, p.cpos.x_scale_y, text, p.xScaleFontSize, p.xScaleFontFamily, p.xScaleColor);
442
+ }
443
+ }
444
+ };
445
+ /* ------------------------------------------------------------------
446
+ グラフの背景を描画
447
+ * ---------------------------------------------------------------- */
448
+ html5jp.graph.vbar.prototype._draw_graph_background = function() {
449
+ var p = this.params;
450
+ var d = p.cpos.r / 3;
451
+ if(p.barShape == "line" || p.barShape == "flat") {
452
+ this._draw_graph_background_back(p.cpos.x0, p.cpos.y0, p.cpos.w, p.cpos.h);
453
+ /* 軸を描画 */
454
+ this._draw_graph_axis(p.cpos.x0, p.cpos.y0, p.cpos.w, p.cpos.h);
455
+ } else {
456
+ /* 背面 */
457
+ this._draw_graph_background_back(p.cpos.x0+d, p.cpos.y0-d, p.cpos.w, p.cpos.h);
458
+ /* 底面 */
459
+ this.ctx.save();
460
+ this.ctx.beginPath();
461
+ this.ctx.moveTo(p.cpos.x0+d, p.cpos.y0-d);
462
+ this.ctx.lineTo(p.cpos.x0+d+p.cpos.w, p.cpos.y0-d);
463
+ this.ctx.lineTo(p.cpos.x0-d+p.cpos.w, p.cpos.y0+d);
464
+ this.ctx.lineTo(p.cpos.x0-d, p.cpos.y0+d);
465
+ this.ctx.closePath();
466
+ this.ctx.fillStyle = p.gBackgroundColor;
467
+ this.ctx.fill();
468
+ this.ctx.restore();
469
+ /* 底面グラデーション(明) */
470
+ this.ctx.save();
471
+ this.ctx.beginPath();
472
+ this.ctx.moveTo(p.cpos.x0+d, p.cpos.y0-d);
473
+ this.ctx.lineTo(p.cpos.x0+d+p.cpos.w, p.cpos.y0-d);
474
+ this.ctx.lineTo(p.cpos.x0-d+p.cpos.w, p.cpos.y0+d);
475
+ this.ctx.lineTo(p.cpos.x0-d, p.cpos.y0+d);
476
+ this.ctx.closePath();
477
+ this.ctx.fillStyle = "rgba(255,255,255,0.3)";
478
+ this.ctx.fill();
479
+ this.ctx.restore();
480
+ /* 側面 */
481
+ this.ctx.save();
482
+ this.ctx.beginPath();
483
+ this.ctx.moveTo(p.cpos.x0+d, p.cpos.y0-d);
484
+ this.ctx.lineTo(p.cpos.x0-d, p.cpos.y0+d);
485
+ this.ctx.lineTo(p.cpos.x0-d, p.cpos.y0+d-p.cpos.h);
486
+ this.ctx.lineTo(p.cpos.x0+d, p.cpos.y0-d-p.cpos.h);
487
+ this.ctx.closePath();
488
+ this.ctx.fillStyle = p.gBackgroundColor;
489
+ this.ctx.fill();
490
+ this.ctx.restore();
491
+ /* 側面補助線 */
492
+ if(p.aLineWidth > 0) {
493
+ this.ctx.save();
494
+ for( var i=0; i<p.aLinePositions.length; i++ ) {
495
+ if(p.aLinePositions[i] > p.yMax) { continue; }
496
+ var aY = p.cpos.y0 - p.cpos.h * p.aLinePositions[i] / ( p.yMax - p.yMin );
497
+ aY = Math.round(aY);
498
+ //
499
+ this.ctx.beginPath();
500
+ this.ctx.strokeStyle = "rgba(0,0,0," + p.aLineAlpha + ")";
501
+ this.ctx.lineWidth = p.aLineWidth;
502
+ this.ctx.moveTo(p.cpos.x0+d, aY-d-p.aLineWidth/2);
503
+ this.ctx.lineTo(p.cpos.x0-d, aY+d-p.aLineWidth/2);
504
+ this.ctx.stroke();
505
+ //
506
+ this.ctx.beginPath();
507
+ this.ctx.strokeStyle = "rgba(255,255,255," + p.aLineAlpha + ")";
508
+ this.ctx.lineWidth = p.aLineWidth;
509
+ this.ctx.moveTo(p.cpos.x0+d, aY-d+p.aLineWidth/2);
510
+ this.ctx.lineTo(p.cpos.x0-d, aY+d+p.aLineWidth/2);
511
+ this.ctx.stroke();
512
+ }
513
+ this.ctx.restore();
514
+ }
515
+ /* 側面グラデーション(暗) */
516
+ this.ctx.save();
517
+ this.ctx.beginPath();
518
+ this.ctx.moveTo(p.cpos.x0+d, p.cpos.y0-d);
519
+ this.ctx.lineTo(p.cpos.x0-d, p.cpos.y0+d);
520
+ this.ctx.lineTo(p.cpos.x0-d, p.cpos.y0+d-p.cpos.h);
521
+ this.ctx.lineTo(p.cpos.x0+d, p.cpos.y0-d-p.cpos.h);
522
+ this.ctx.closePath();
523
+ this.ctx.fillStyle = "rgba(0,0,0,0.1)";
524
+ this.ctx.fill();
525
+ this.ctx.restore();
526
+ /* 軸を描画 */
527
+ this._draw_graph_axis(p.cpos.x0-d, p.cpos.y0+d, p.cpos.w, p.cpos.h);
528
+ }
529
+ };
530
+ html5jp.graph.vbar.prototype._draw_graph_axis = function(x, y, w, h) {
531
+ this.ctx.save();
532
+ var p = this.params;
533
+ /* x軸 */
534
+ this.ctx.beginPath();
535
+ this.ctx.lineWidth = p.xAxisWidth;
536
+ this.ctx.strokeStyle = p.xAxisColor;
537
+ this.ctx.moveTo(x, y);
538
+ this.ctx.lineTo(x+w, y);
539
+ this.ctx.stroke();
540
+ /* y軸 */
541
+ this.ctx.beginPath();
542
+ this.ctx.lineWidth = p.yAxisWidth;
543
+ this.ctx.strokeStyle = p.yAxisColor;
544
+ this.ctx.moveTo(x, y);
545
+ this.ctx.lineTo(x, y-h);
546
+ this.ctx.stroke();
547
+ //
548
+ this.ctx.restore();
549
+ };
550
+ html5jp.graph.vbar.prototype._draw_graph_background_back = function(x, y, w, h) {
551
+ var p = this.params;
552
+ /* 背景 */
553
+ this.ctx.save();
554
+ this.ctx.fillStyle = p.gBackgroundColor;
555
+ this.ctx.fillRect(x, y-h, w, h);
556
+ this.ctx.beginPath();
557
+ this.ctx.moveTo(x, y);
558
+ this.ctx.lineTo(x+w, y);
559
+ this.ctx.lineTo(x+w, y-h);
560
+ this.ctx.lineTo(x, y-h);
561
+ this.ctx.closePath();
562
+ this.ctx.fill();
563
+ this.ctx.restore();
564
+ /* グラデーション */
565
+ if( p.gGradation == true) {
566
+ this.ctx.save();
567
+ var grad = this.ctx.createLinearGradient(x, y-h, x+w, y);
568
+ grad.addColorStop(0, "rgba(0, 0, 0, 0.1)");
569
+ grad.addColorStop(0.3, "rgba(255, 255, 255, 0.2)");
570
+ if(document.uniqueID ) { grad.addColorStop(0.5, "rgba(255, 255, 255, 0.2)"); }
571
+ grad.addColorStop(1, "rgba(0, 0, 0, 0.3)");
572
+ this.ctx.fillStyle = grad;
573
+ this.ctx.beginPath();
574
+ this.ctx.moveTo(x, y);
575
+ this.ctx.lineTo(x+w, y);
576
+ this.ctx.lineTo(x+w, y-h);
577
+ this.ctx.lineTo(x, y-h);
578
+ this.ctx.closePath();
579
+ if(document.uniqueID ) { this.ctx.globalAlpha = 0.3; }
580
+ this.ctx.fill();
581
+ if(document.uniqueID ) { this.ctx.globalAlpha = 1; }
582
+ this.ctx.restore();
583
+ }
584
+ /* 補助線 */
585
+ if(p.aLineWidth > 0) {
586
+ this.ctx.save();
587
+ for( var i=0; i<p.aLinePositions.length; i++ ) {
588
+ if(p.aLinePositions[i] > p.yMax) { continue; }
589
+ var aY = y - h * p.aLinePositions[i] / ( p.yMax - p.yMin );
590
+ aY = Math.round(aY);
591
+ //
592
+ this.ctx.beginPath();
593
+ this.ctx.strokeStyle = "rgba(0,0,0," + p.aLineAlpha + ")";
594
+ this.ctx.lineWidth = p.aLineWidth;
595
+ this.ctx.moveTo(x, aY-p.aLineWidth/2);
596
+ this.ctx.lineTo(x+w, aY-p.aLineWidth/2);
597
+ this.ctx.stroke();
598
+ //
599
+ this.ctx.beginPath();
600
+ this.ctx.strokeStyle = "rgba(255,255,255," + p.aLineAlpha + ")";
601
+ this.ctx.lineWidth = p.aLineWidth;
602
+ this.ctx.moveTo(x, aY+p.aLineWidth/2);
603
+ this.ctx.lineTo(x+w, aY+p.aLineWidth/2);
604
+ this.ctx.stroke();
605
+ }
606
+ this.ctx.restore();
607
+ }
608
+ };
609
+ /* ------------------------------------------------------------------
610
+ CANVASの背景を塗る
611
+ * ---------------------------------------------------------------- */
612
+ html5jp.graph.vbar.prototype._draw_canvas_background = function() {
613
+ var c = this._csscolor2rgb(this.params.backgroundColor);
614
+ if( c != null ) {
615
+ this.ctx.save();
616
+ this.ctx.beginPath();
617
+ this.ctx.fillStyle = this.params.backgroundColor;
618
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
619
+ this.ctx.restore();
620
+ }
621
+ };
622
+
623
+ /* ------------------------------------------------------------------
624
+ 文字列を描画
625
+ * ---------------------------------------------------------------- */
626
+ html5jp.graph.vbar.prototype._drawText = function(x, y, text, font_size, font_family, color) {
627
+ var div = document.createElement('DIV');
628
+ div.appendChild( document.createTextNode(text) );
629
+ div.style.fontSize = font_size;
630
+ div.style.fontFamily = font_family;
631
+ div.style.color = color;
632
+ div.style.margin = "0";
633
+ div.style.padding = "0";
634
+ div.style.position = "absolute";
635
+ div.style.left = x.toString() + "px";
636
+ div.style.top = y.toString() + "px";
637
+ this.canvas.parentNode.appendChild(div);
638
+ }
639
+ /* ------------------------------------------------------------------
640
+ 文字列表示領域のサイズを取得
641
+ * ---------------------------------------------------------------- */
642
+ html5jp.graph.vbar.prototype._getTextBoxSize = function(text, font_size, font_family) {
643
+ var tmpdiv = document.createElement('DIV');
644
+ tmpdiv.appendChild( document.createTextNode(text) );
645
+ tmpdiv.style.fontSize = font_size;
646
+ tmpdiv.style.fontFamily = font_family;
647
+ tmpdiv.style.margin = "0";
648
+ tmpdiv.style.padding = "0";
649
+ tmpdiv.style.visible = "hidden";
650
+ tmpdiv.style.position = "absolute";
651
+ tmpdiv.style.left = "0px";
652
+ tmpdiv.style.top = "0px";
653
+ this.canvas.parentNode.appendChild(tmpdiv);
654
+ var o = {
655
+ w: tmpdiv.offsetWidth,
656
+ h: tmpdiv.offsetHeight
657
+ };
658
+ tmpdiv.parentNode.removeChild(tmpdiv);
659
+ return o;
660
+ }
661
+
662
+ /* ------------------------------------------------------------------
663
+ ブラウザー表示領域左上端を基点とする座標系におけるelmの左上端の座標
664
+ * ---------------------------------------------------------------- */
665
+ html5jp.graph.vbar.prototype._getElementAbsPos = function(elm) {
666
+ var obj = new Object();
667
+ obj.x = elm.offsetLeft;
668
+ obj.y = elm.offsetTop;
669
+ while(elm.offsetParent) {
670
+ elm = elm.offsetParent;
671
+ obj.x += elm.offsetLeft;
672
+ obj.y += elm.offsetTop;
673
+ }
674
+ return obj;
675
+ };
676
+
677
+ /* ------------------------------------------------------------------
678
+ * CSS色文字列をRGBに変換
679
+ * ---------------------------------------------------------------- */
680
+ html5jp.graph.vbar.prototype._csscolor2rgb = function (c) {
681
+ if( ! c ) { return null; }
682
+ var color_map = {
683
+ black: "#000000",
684
+ gray: "#808080",
685
+ silver: "#c0c0c0",
686
+ white: "#ffffff",
687
+ maroon: "#800000",
688
+ red: "#ff0000",
689
+ purple: "#800080",
690
+ fuchsia: "#ff00ff",
691
+ green: "#008000",
692
+ lime: "#00FF00",
693
+ olive: "#808000",
694
+ yellow: "#FFFF00",
695
+ navy: "#000080",
696
+ blue: "#0000FF",
697
+ teal: "#008080",
698
+ aqua: "#00FFFF"
699
+ };
700
+ c = c.toLowerCase();
701
+ var o = new Object();
702
+ if( c.match(/^[a-zA-Z]+$/) && color_map[c] ) {
703
+ c = color_map[c];
704
+ }
705
+ var m = null;
706
+ if( m = c.match(/^\#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i) ) {
707
+ o.r = parseInt(m[1], 16);
708
+ o.g = parseInt(m[2], 16);
709
+ o.b = parseInt(m[3], 16);
710
+ } else if( m = c.match(/^\#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i) ) {
711
+ o.r = parseInt(m[1]+"0", 16);
712
+ o.g = parseInt(m[2]+"0", 16);
713
+ o.b = parseInt(m[3]+"0", 16);
714
+ } else if( m = c.match(/^rgba*\(\s*(\d+),\s*(\d+),\s*(\d+)/i) ) {
715
+ o.r = m[1];
716
+ o.g = m[2];
717
+ o.b = m[3];
718
+ } else if( m = c.match(/^rgba*\(\s*(\d+)\%,\s*(\d+)\%,\s*(\d+)\%/i) ) {
719
+ o.r = Math.round(m[1] * 255 / 100);
720
+ o.g = Math.round(m[2] * 255 / 100);
721
+ o.b = Math.round(m[3] * 255 / 100);
722
+ } else {
723
+ return null;
724
+ }
725
+ return o;
726
+ };
727
+ /* ------------------------------------------------------------------
728
+ * 垂直棒フラフ(角柱)を描画
729
+ * ---------------------------------------------------------------- */
730
+ html5jp.graph.vbar.prototype._draw_vertical_bar_square = function(ctx, x, y, h, xr, yr, color, alpha, balpha, bgradation) {
731
+ if( typeof(alpha) != "number" || alpha < 0 || alpha > 1 ) {
732
+ alpha = 1;
733
+ }
734
+ if( typeof(balpha) != "number" || balpha < 0 || balpha > 1 ) {
735
+ balpha = 1;
736
+ }
737
+ var p = {
738
+ f: {
739
+ tl: { x:x-xr-yr, y:y-h+yr },
740
+ tr: { x:x+xr-yr, y:y-h+yr },
741
+ bl: { x:x-xr-yr, y:y+yr },
742
+ br: { x:x+xr-yr, y:y+yr }
743
+ },
744
+ b: {
745
+ tl: { x:x-xr+yr, y:y-h-yr },
746
+ tr: { x:x+xr+yr, y:y-h-yr },
747
+ bl: { x:x-xr+yr, y:y-yr },
748
+ br: { x:x+xr+yr, y:y-yr }
749
+ }
750
+ }
751
+ /* ------------------------------------------------------
752
+ * 背面の境界線
753
+ * ---------------------------------------------------- */
754
+ ctx.save();
755
+ ctx.strokeStyle = "black";
756
+ ctx.globalAlpha = balpha;
757
+ ctx.lineWidth = 1;
758
+ //
759
+ ctx.beginPath();
760
+ ctx.moveTo(p.f.bl.x, p.f.bl.y);
761
+ ctx.lineTo(p.b.bl.x, p.b.bl.y);
762
+ ctx.lineTo(p.b.br.x, p.b.br.y);
763
+ ctx.stroke();
764
+ //
765
+ ctx.beginPath();
766
+ ctx.moveTo(p.b.bl.x, p.b.bl.y);
767
+ ctx.lineTo(p.b.tl.x, p.b.tl.y);
768
+ ctx.stroke();
769
+ //
770
+ ctx.restore();
771
+ /* ------------------------------------------------------
772
+ * 面塗り
773
+ * ---------------------------------------------------- */
774
+ ctx.save();
775
+ ctx.fillStyle = color;
776
+ ctx.globalAlpha = alpha;
777
+ //
778
+ ctx.beginPath();
779
+ ctx.moveTo(p.f.bl.x, p.f.bl.y);
780
+ ctx.lineTo(p.f.tl.x, p.f.tl.y);
781
+ ctx.lineTo(p.b.tl.x, p.b.tl.y);
782
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
783
+ ctx.lineTo(p.b.br.x, p.b.br.y);
784
+ ctx.lineTo(p.f.br.x, p.f.br.y);
785
+ ctx.closePath();
786
+ ctx.fill();
787
+ //
788
+ ctx.restore();
789
+ /* ------------------------------------------------------
790
+ * 前面の境界線
791
+ * ---------------------------------------------------- */
792
+ ctx.save();
793
+ ctx.strokeStyle = "white";
794
+ ctx.globalAlpha = balpha;
795
+ ctx.lineWidth = 1;
796
+ //
797
+ ctx.beginPath();
798
+ ctx.moveTo(p.f.bl.x, p.f.bl.y);
799
+ ctx.lineTo(p.f.tl.x, p.f.tl.y);
800
+ ctx.lineTo(p.b.tl.x, p.b.tl.y);
801
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
802
+ ctx.lineTo(p.b.br.x, p.b.br.y);
803
+ ctx.lineTo(p.f.br.x, p.f.br.y);
804
+ ctx.closePath();
805
+ ctx.stroke();
806
+ //
807
+ ctx.beginPath();
808
+ ctx.moveTo(p.f.tl.x, p.f.tl.y);
809
+ ctx.lineTo(p.f.tr.x, p.f.tr.y);
810
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
811
+ ctx.stroke();
812
+ //
813
+ ctx.beginPath();
814
+ ctx.moveTo(p.f.tr.x, p.f.tr.y);
815
+ ctx.lineTo(p.f.br.x, p.f.br.y);
816
+ ctx.stroke();
817
+ //
818
+ ctx.restore();
819
+ /* ------------------------------------------------------
820
+ * グラデーション
821
+ * ---------------------------------------------------- */
822
+ if( bgradation == true ) {
823
+ /* 正面 */
824
+ ctx.save();
825
+ var grad = ctx.createLinearGradient(p.f.tl.x, p.f.tl.y, p.f.br.x, p.f.br.y);
826
+ if(document.uniqueID) {
827
+ grad.addColorStop(0, color);
828
+ grad.addColorStop(0.3, "rgba(255, 255, 255, 0.1)");
829
+ grad.addColorStop(1, color);
830
+ } else {
831
+ grad.addColorStop(0, "rgba(0, 0, 0, 0.1)");
832
+ grad.addColorStop(0.3, "rgba(255, 255, 255, 0.1)");
833
+ grad.addColorStop(1, "rgba(0, 0, 0, 0.4)");
834
+ }
835
+ ctx.fillStyle = grad;
836
+ ctx.beginPath();
837
+ ctx.moveTo(p.f.tl.x, p.f.tl.y);
838
+ ctx.lineTo(p.f.tr.x, p.f.tr.y);
839
+ ctx.lineTo(p.f.br.x, p.f.br.y);
840
+ ctx.lineTo(p.f.bl.x, p.f.bl.y);
841
+ ctx.closePath();
842
+ if(document.uniqueID) { ctx.globalAlpha = 0; }
843
+ ctx.fill();
844
+ if(document.uniqueID) { ctx.globalAlpha = 1; }
845
+ ctx.restore();
846
+ /* 右側面 */
847
+ ctx.save();
848
+ if(document.uniqueID ) {
849
+ ctx.fillStyle = "#000000";
850
+ ctx.globalAlpha = 0.4;
851
+ } else {
852
+ var grad3 = ctx.createLinearGradient(p.f.tr.x, p.f.tr.y, p.b.tr.x, p.f.tr.y);
853
+ grad3.addColorStop(0, "rgba(0, 0, 0, 0.3)");
854
+ grad3.addColorStop(1, "rgba(0, 0, 0, 0.5)");
855
+ ctx.fillStyle = grad3;
856
+ }
857
+ ctx.beginPath();
858
+ ctx.moveTo(p.f.tr.x, p.f.tr.y);
859
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
860
+ ctx.lineTo(p.b.br.x, p.b.br.y);
861
+ ctx.lineTo(p.f.br.x, p.f.br.y);
862
+ ctx.closePath();
863
+ ctx.fill();
864
+ ctx.restore();
865
+ /* 上面 */
866
+ ctx.save();
867
+ var grad2 = ctx.createLinearGradient(x-xr/5, y-h+yr, x+xr/5, y-h-yr);
868
+ if(document.uniqueID) {
869
+ grad2.addColorStop(0, "rgba(255, 255, 255, 0.2)");
870
+ grad2.addColorStop(1, color);
871
+ } else {
872
+ grad2.addColorStop(0, "rgba(255, 255, 255, 0.2)");
873
+ grad2.addColorStop(1, "rgba(0, 0, 0, 0.1)");
874
+ }
875
+ ctx.fillStyle = grad2;
876
+ ctx.beginPath();
877
+ ctx.moveTo(p.f.tl.x, p.f.tl.y);
878
+ ctx.lineTo(p.f.tr.x, p.f.tr.y);
879
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
880
+ ctx.lineTo(p.b.tl.x, p.b.tl.y);
881
+ ctx.closePath();
882
+ if(document.uniqueID ) { ctx.globalAlpha = 0.1; }
883
+ ctx.fill();
884
+ if(document.uniqueID ) { ctx.globalAlpha = 1; }
885
+ ctx.restore();
886
+ } else {
887
+ /* 側面 */
888
+ ctx.save();
889
+ ctx.fillStyle = "rgba(0,0,0,0.4)";
890
+ ctx.beginPath();
891
+ ctx.moveTo(p.f.tr.x, p.f.tr.y);
892
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
893
+ ctx.lineTo(p.b.br.x, p.b.br.y);
894
+ ctx.lineTo(p.f.br.x, p.f.br.y);
895
+ ctx.closePath();
896
+ ctx.fill();
897
+ ctx.restore();
898
+ /* 上面 */
899
+ ctx.save();
900
+ ctx.fillStyle = "rgba(255,255,255,0.2)";
901
+ ctx.beginPath();
902
+ ctx.moveTo(p.f.tl.x, p.f.tl.y);
903
+ ctx.lineTo(p.f.tr.x, p.f.tr.y);
904
+ ctx.lineTo(p.b.tr.x, p.b.tr.y);
905
+ ctx.lineTo(p.b.tl.x, p.b.tl.y);
906
+ ctx.closePath();
907
+ ctx.fill();
908
+ ctx.restore();
909
+ }
910
+ };
911
+ /* ------------------------------------------------------------------
912
+ * 垂直棒フラフ(線)を描画
913
+ * ---------------------------------------------------------------- */
914
+ html5jp.graph.vbar.prototype._draw_vertical_bar_line = function(ctx, x, y, h, xr, color, alpha) {
915
+ if( typeof(alpha) != "number" || alpha < 0 || alpha > 1 ) {
916
+ alpha = 1;
917
+ }
918
+ if( typeof(xr) != "number" || xr <= 0 ) {
919
+ xr = 0.5;
920
+ }
921
+ ctx.save();
922
+ ctx.strokeStyle = color;
923
+ ctx.globalAlpha = alpha;
924
+ ctx.lineCap = "butt";
925
+ ctx.lineWidth = Math.round( xr * 2 );
926
+ ctx.beginPath();
927
+ ctx.moveTo(x, y);
928
+ ctx.lineTo(x, y-h);
929
+ ctx.stroke();
930
+ ctx.restore();
931
+ };
932
+ /* ------------------------------------------------------------------
933
+ * 垂直棒フラフ(平坦)を描画
934
+ * ---------------------------------------------------------------- */
935
+ html5jp.graph.vbar.prototype._draw_vertical_bar_flat = function(ctx, x, y, h, xr, color, alpha, balpha, bgradation) {
936
+ if( typeof(alpha) != "number" || alpha < 0 || alpha > 1 ) {
937
+ alpha = 1;
938
+ }
939
+ if( typeof(balpha) != "number" || balpha < 0 || balpha > 1 ) {
940
+ balpha = 1;
941
+ }
942
+ /* ------------------------------------------------------
943
+ * 面塗り
944
+ * ---------------------------------------------------- */
945
+ ctx.save();
946
+ ctx.fillStyle = color;
947
+ ctx.globalAlpha = alpha;
948
+ ctx.beginPath();
949
+ ctx.moveTo(x+xr, y);
950
+ ctx.lineTo(x-xr, y);
951
+ ctx.lineTo(x-xr, y-h);
952
+ ctx.lineTo(x+xr, y-h);
953
+ ctx.closePath();
954
+ ctx.fill();
955
+ ctx.restore();
956
+ /* ------------------------------------------------------
957
+ * 境界線
958
+ * ---------------------------------------------------- */
959
+ ctx.save();
960
+ ctx.globalAlpha = balpha;
961
+ ctx.strokeStyle = "black";
962
+ ctx.lineWidth = 1;
963
+ ctx.beginPath();
964
+ ctx.moveTo(x-xr, y);
965
+ ctx.lineTo(x+xr, y);
966
+ ctx.lineTo(x+xr, y-h);
967
+ ctx.lineTo(x-xr, y-h);
968
+ ctx.closePath();
969
+ ctx.stroke();
970
+ ctx.restore();
971
+ /* ------------------------------------------------------
972
+ * シャドー
973
+ * ---------------------------------------------------- */
974
+ ctx.save();
975
+ ctx.lineWidth = 1;
976
+ ctx.globalAlpha = 0.3;
977
+ //
978
+ ctx.beginPath();
979
+ ctx.strokeStyle = "black";
980
+ ctx.moveTo(x-xr+1, y-1);
981
+ ctx.lineTo(x+xr-1, y-1);
982
+ ctx.lineTo(x+xr-1, y-h+1);
983
+ ctx.stroke();
984
+ //
985
+ ctx.beginPath();
986
+ ctx.strokeStyle = "white";
987
+ ctx.moveTo(x+xr-1, y-h+1);
988
+ ctx.lineTo(x-xr+1, y-h+1);
989
+ ctx.lineTo(x-xr+1, y-1);
990
+ ctx.stroke();
991
+ ctx.restore();
992
+ /* ------------------------------------------------------
993
+ * グラデーション
994
+ * ---------------------------------------------------- */
995
+ if( bgradation == true ) {
996
+ ctx.save();
997
+ ctx.lineWidth = 1;
998
+ var grad = ctx.createLinearGradient(x-xr, y-h, x+xr, y);
999
+ if(document.uniqueID ) {
1000
+ grad.addColorStop(0, color);
1001
+ grad.addColorStop(0.3, "rgba(255, 255, 255, 0.1)");
1002
+ grad.addColorStop(1, color);
1003
+ } else {
1004
+ grad.addColorStop(0, "rgba(0, 0, 0, 0.1)");
1005
+ grad.addColorStop(0.3, "rgba(255, 255, 255, 0.1)");
1006
+ grad.addColorStop(1, "rgba(0, 0, 0, 0.4)");
1007
+ }
1008
+ ctx.fillStyle = grad;
1009
+ ctx.beginPath();
1010
+ ctx.moveTo(x-xr+2, y-2);
1011
+ ctx.lineTo(x+xr-2, y-2);
1012
+ ctx.lineTo(x+xr-2, y-h+2);
1013
+ ctx.lineTo(x-xr+2, y-h+2);
1014
+ ctx.closePath();
1015
+ if(document.uniqueID) { ctx.globalAlpha = 0; }
1016
+ ctx.fill();
1017
+ if(document.uniqueID) { ctx.globalAlpha = 1; }
1018
+ ctx.restore();
1019
+ }
1020
+ };
1021
+ /* ------------------------------------------------------------------
1022
+ * 垂直棒フラフ(円柱)を描画
1023
+ * ---------------------------------------------------------------- */
1024
+ html5jp.graph.vbar.prototype._draw_vertical_bar_cylinder = function(ctx, x, y, h, xr, yr, color, alpha, balpha, bgradation) {
1025
+ if( typeof(alpha) != "number" || alpha < 0 || alpha > 1 ) {
1026
+ alpha = 1;
1027
+ }
1028
+ if( typeof(balpha) != "number" || balpha < 0 || balpha > 1 ) {
1029
+ balpha = 1;
1030
+ }
1031
+ /* ------------------------------------------------------
1032
+ * 境界線(背面)
1033
+ * ---------------------------------------------------- */
1034
+ ctx.save();
1035
+ ctx.strokeStyle = "black";
1036
+ ctx.globalAlpha = balpha;
1037
+ ctx.lineWidth = 1;
1038
+ ctx.beginPath();
1039
+ ctx.moveTo(x-xr, y);
1040
+ ctx.bezierCurveTo(x-xr, y-yr/2, x-xr/2, y-yr, x, y-yr);
1041
+ ctx.bezierCurveTo(x+xr/2, y-yr, x+xr, y-yr/2, x+xr, y);
1042
+ ctx.stroke();
1043
+ ctx.restore();
1044
+ /* ------------------------------------------------------
1045
+ * 面塗り
1046
+ * ---------------------------------------------------- */
1047
+ ctx.save();
1048
+ ctx.fillStyle = color;
1049
+ ctx.globalAlpha = alpha;
1050
+ ctx.beginPath();
1051
+ ctx.moveTo(x-xr, y);
1052
+ ctx.lineTo(x-xr, y-h);
1053
+ ctx.bezierCurveTo(x-xr, y-h-yr/2, x-xr/2, y-h-yr, x, y-h-yr);
1054
+ ctx.bezierCurveTo(x+xr/2, y-h-yr, x+xr, y-h-yr/2, x+xr, y-h);
1055
+ ctx.lineTo(x+xr, y);
1056
+ ctx.bezierCurveTo(x+xr, y+yr/2, x+xr/2, y+yr, x, y+yr);
1057
+ ctx.bezierCurveTo(x-xr/2, y+yr, x-xr, y+yr/2, x-xr, y);
1058
+ ctx.fill();
1059
+ ctx.restore();
1060
+ /* ------------------------------------------------------
1061
+ * 境界線(前面)
1062
+ * ---------------------------------------------------- */
1063
+ ctx.save();
1064
+ ctx.strokeStyle = "white";
1065
+ ctx.globalAlpha = balpha;
1066
+ ctx.lineWidth = 1;
1067
+ /* 底面 */
1068
+ ctx.beginPath();
1069
+ ctx.moveTo(x-xr, y);
1070
+ ctx.bezierCurveTo(x-xr, y+yr/2, x-xr/2, y+yr, x, y+yr);
1071
+ ctx.bezierCurveTo(x+xr/2, y+yr, x+xr, y+yr/2, x+xr, y);
1072
+ ctx.stroke();
1073
+ /* 側面 */
1074
+ ctx.beginPath();
1075
+ ctx.moveTo(x-xr, y);
1076
+ ctx.lineTo(x-xr, y-h);
1077
+ ctx.stroke();
1078
+ ctx.beginPath();
1079
+ ctx.moveTo(x+xr, y);
1080
+ ctx.lineTo(x+xr, y-h);
1081
+ ctx.stroke();
1082
+ /* 上面 */
1083
+ ctx.beginPath();
1084
+ ctx.moveTo(x-xr, y-h);
1085
+ ctx.bezierCurveTo(x-xr, y-h-yr/2, x-xr/2, y-h-yr, x, y-h-yr);
1086
+ ctx.bezierCurveTo(x+xr/2, y-h-yr, x+xr, y-h-yr/2, x+xr, y-h);
1087
+ ctx.bezierCurveTo(x+xr, y-h+yr/2, x+xr/2, y-h+yr, x, y-h+yr);
1088
+ ctx.bezierCurveTo(x-xr/2, y-h+yr, x-xr, y-h+yr/2, x-xr, y-h);
1089
+ ctx.stroke();
1090
+ ctx.restore();
1091
+ /* ------------------------------------------------------
1092
+ * 前面グラデーション
1093
+ * ---------------------------------------------------- */
1094
+ if( bgradation == true ) {
1095
+ /* 側面 */
1096
+ ctx.save();
1097
+ var grad1 = ctx.createLinearGradient(x-xr, y, x+xr, y);
1098
+ if(document.uniqueID) {
1099
+ grad1.addColorStop(0, color);
1100
+ grad1.addColorStop(0.4, "rgba(255, 255, 255, 0.3)");
1101
+ grad1.addColorStop(0.9, color);
1102
+ grad1.addColorStop(1, color);
1103
+ } else {
1104
+ grad1.addColorStop(0, "rgba(0, 0, 0, 0.1)");
1105
+ grad1.addColorStop(0.4, "rgba(255, 255, 255, 0.3)");
1106
+ grad1.addColorStop(1, "rgba(0, 0, 0, 0.3)");
1107
+ }
1108
+ ctx.fillStyle = grad1;
1109
+ ctx.beginPath();
1110
+ ctx.moveTo(x+xr, y);
1111
+ ctx.bezierCurveTo(x+xr, y+yr/2, x+xr/2, y+yr, x, y+yr);
1112
+ ctx.bezierCurveTo(x-xr/2, y+yr, x-xr, y+yr/2, x-xr, y);
1113
+ ctx.lineTo(x-xr, y-h);
1114
+ ctx.bezierCurveTo(x-xr, y-h+yr/2, x-xr/2, y-h+yr, x, y-h+yr);
1115
+ ctx.bezierCurveTo(x+xr/2, y-h+yr, x+xr, y-h+yr/2, x+xr, y-h);
1116
+ ctx.lineTo(x+xr, y);
1117
+ if(document.uniqueID ) { ctx.globalAlpha = 0; }
1118
+ ctx.fill();
1119
+ if(document.uniqueID ) { ctx.globalAlpha = 1; }
1120
+ ctx.restore();
1121
+ /* 上面 */
1122
+ ctx.save();
1123
+ var grad2 = ctx.createLinearGradient(x-xr/5, y-h+yr, x+xr/5, y-h-yr);
1124
+ if(document.uniqueID) {
1125
+ grad2.addColorStop(0, "rgba(255, 255, 255, 0.2)");
1126
+ grad2.addColorStop(1, color);
1127
+ } else {
1128
+ grad2.addColorStop(0, "rgba(255, 255, 255, 0.2)");
1129
+ grad2.addColorStop(1, "rgba(0, 0, 0, 0.1)");
1130
+ }
1131
+ ctx.fillStyle = grad2;
1132
+ ctx.beginPath();
1133
+ ctx.moveTo(x-xr, y-h);
1134
+ ctx.bezierCurveTo(x-xr, y-h-yr/2, x-xr/2, y-h-yr, x, y-h-yr);
1135
+ ctx.bezierCurveTo(x+xr/2, y-h-yr, x+xr, y-h-yr/2, x+xr, y-h);
1136
+ ctx.bezierCurveTo(x+xr, y-h+yr/2, x+xr/2, y-h+yr, x, y-h+yr);
1137
+ ctx.bezierCurveTo(x-xr/2, y-h+yr, x-xr, y-h+yr/2, x-xr, y-h);
1138
+ if(document.uniqueID ) { ctx.globalAlpha = 0; }
1139
+ ctx.fill();
1140
+ if(document.uniqueID ) { ctx.globalAlpha = 1; }
1141
+ ctx.restore();
1142
+ } else {
1143
+ /* 上面 */
1144
+ ctx.save();
1145
+ ctx.globalAlpha = 0.2;
1146
+ ctx.fillStyle = "white";
1147
+ ctx.beginPath();
1148
+ ctx.moveTo(x-xr, y-h);
1149
+ ctx.bezierCurveTo(x-xr, y-h-yr/2, x-xr/2, y-h-yr, x, y-h-yr);
1150
+ ctx.bezierCurveTo(x+xr/2, y-h-yr, x+xr, y-h-yr/2, x+xr, y-h);
1151
+ ctx.bezierCurveTo(x+xr, y-h+yr/2, x+xr/2, y-h+yr, x, y-h+yr);
1152
+ ctx.bezierCurveTo(x-xr/2, y-h+yr, x-xr, y-h+yr/2, x-xr, y-h);
1153
+ ctx.fill();
1154
+ ctx.restore();
1155
+ }
1156
+ };