Skip to content

Commit 2a00df8

Browse files
committed
Grid: add through option; Demo: add connected bar graphs through their legends; Update documentation
1 parent d986306 commit 2a00df8

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed

README.textile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,14 @@ All Raphaël Element Attributes are valid, only listed here are those whith defa
797797
<th>Default value</th>
798798
<th>Description</th>
799799
</tr>
800+
<tr>
801+
<td>through</td>
802+
<td>undefined</td>
803+
<td>true: grid line extends to graph borders</td>
804+
</tr>
800805
<tr>
801806
<td>stroke</td>
802-
<td>'#eee' (grey)</td>
807+
<td>'#eee' (very light grey)</td>
803808
<td>Stroke color</td>
804809
</tr>
805810
<tr>

ico.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,22 @@ var Ico = {
10511051
x = this.x.start + this.x.start_offset * dx,
10521052
y = this.y.start - this.y.start_offset * dy,
10531053
marker = o.marker_size, fx = d.f[0], fy = d.f[1], angle = d.angle,
1054-
paper = this.p.paper, grid = o.grid
1054+
paper = this.p.paper,
1055+
grid = o.grid, grid_len = ( dx ? 'v-' + t.y.len : 'h' + t.x.len ), grid_x = 0, grid_y = 0
10551056
;
1057+
if ( grid && grid.through ) {
1058+
grid_len += d.padding[ 1 ] + 10;
1059+
1060+
var offset = -d.padding[ 0 ] - this.bbox[ 0 ] - marker - 20;
1061+
dx ? grid_y = offset : grid_x = offset;
1062+
}
1063+
10561064
if ( dy ) angle += 90;
10571065
var path = [], grid_path = [];
10581066
this.labels || this.get_labels_bounding_boxes( d );
1059-
this.labels.forEach( function( label ) {
1067+
this.labels.forEach( function( label, i ) {
10601068
marker && path.push( 'M', x, y, dx ? 'v' : 'h-', marker );
1061-
grid && grid_path.push( 'M', x, y, dx ? 'v-' + t.y.len : 'h' + t.x.len );
1069+
grid && grid_path.push( 'M', x + ( d.labels[ i ] ? 0 : grid_x ), y + ( d.labels[ i ] ? 0 : grid_y ), grid_len );
10621070
var x_anchor = x + fx;
10631071
var y_anchor = y + fy;
10641072
// label is already drawn, only anchor then rotate here

index.html

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@
6767
margin: 2px;
6868
}
6969

70+
.clear {
71+
clear: both;
72+
}
73+
74+
.left_6 {
75+
float: left;
76+
width: 160px;
77+
margin: 0px;
78+
padding: 0px;
79+
}
80+
7081
#legend {
7182
text-align: center;
7283
}
@@ -115,7 +126,9 @@
115126
<div id="graph7" class="rightGraph"></div>
116127
<div id="graph8" class="leftGraph"></div>
117128
<div id="graph9" class="rightGraph"></div>
118-
<h2 id='g10' style="color: blue; margin-top: 20px;">A line of two dependent graphs on the same value range and legend</h2>
129+
130+
<div class="clear"></div>
131+
<h2 id='g10' style="color: blue; margin-top: 50px;">A line of two dependent graphs on the same value range and legend</h2>
119132
<p>Click legend labels bellow to toggle (show/hide) series:</p>
120133
<p id="legend">
121134
<span id="legend_this_year" class="legend">This Year Performance</span>
@@ -125,8 +138,16 @@ <h2 id='g10' style="color: blue; margin-top: 20px;">A line of two dependent grap
125138
</p>
126139
<div id="graph10" class="leftGraph"></div>
127140
<div id="graph11" class="rightGraph"></div>
128-
<div id="graph12" class="leftGraph"></div>
129-
<div id="graph13" class="rightGraph"></div>
141+
142+
<div class="clear"></div>
143+
<h2 id='g10' style="color: blue; margin-top: 50px;">6 Horinzontal Bar Graphs connected through their grids, the left-most holding only the labels</h2>
144+
<div class="clear"></div>
145+
<div id="graph12" class="left_6"></div>
146+
<div id="graph13" class="left_6"></div>
147+
<div id="graph14" class="left_6"></div>
148+
<div id="graph15" class="left_6"></div>
149+
<div id="graph16" class="left_6"></div>
150+
<div id="graph17" class="left_6"></div>
130151
</div>
131152

132153
<script type="text/javascript">
@@ -409,6 +430,53 @@ <h2 id='g10' style="color: blue; margin-top: 20px;">A line of two dependent grap
409430
set_legend( [g10], [2], $('legend_intermitent') );
410431
set_legend( [g11], [1], $('legend_moving_average') );
411432

433+
var countries = [
434+
"Zimbabwe", "Ireland", "Argentina", "New Zealand", "Sri Lanka", "Finland"
435+
];
436+
437+
var data = [
438+
[ 1500, 1200, 750, 845, 756, 124 ],
439+
[ 45, 78, 21, 102, 51, 87 ],
440+
[ 17, 21, 15, 18, 8, 12 ],
441+
[ 54, 87, 12, 201, 15, 78 ],
442+
[ 51, 21, 57, 548, 657, 421 ]
443+
];
444+
445+
var options = {
446+
labels: {
447+
values: countries, long_values: countries,
448+
marker_size: 0,
449+
font: { fill: 'blue' },
450+
grid: { through: true
451+
, 'stroke-width': 1
452+
, stroke: '#ccc'
453+
}
454+
}
455+
, value_labels: {
456+
marker_size: 3,
457+
font: { fill: 'white' }
458+
}
459+
, units: ''
460+
, color: '#ccccff'
461+
, axis: false
462+
, status_bar : true
463+
, width: 161
464+
, height: 140
465+
, x_padding_left: 20
466+
, x_padding_right: 0
467+
}
468+
469+
new Ico.HorizontalBarGraph( "graph12", [ null ,null ,null ,null ,null ,null ], options );
470+
options.labels.values = [ '', '', '', '', '', '' ];
471+
options.value_labels.font.fill = "black";
472+
options.x_padding_right = 20;
473+
474+
new Ico.HorizontalBarGraph( "graph13", data[ 0 ], options );
475+
new Ico.HorizontalBarGraph( "graph14", data[ 1 ], options );
476+
new Ico.HorizontalBarGraph( "graph15", data[ 2 ], options );
477+
new Ico.HorizontalBarGraph( "graph16", data[ 3 ], options );
478+
new Ico.HorizontalBarGraph( "graph17", data[ 4 ], options );
479+
412480
/*
413481
new Ico.LineGraph(
414482
document.getElementById( 'graph12' )

0 commit comments

Comments
 (0)