Skip to content

Commit 0d9a30c

Browse files
committed
Bars: add bars_overlap option, update documentation
1 parent f4efe4c commit 0d9a30c

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

README.textile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ h3. Ico.BarGraph and Ico.HorizontalBarGraph options
574574
<td>5 pixels</td>
575575
<td>Padding between bars</td>
576576
</tr>
577+
<tr>
578+
<td>bars_overlap</td>
579+
<td>1/2</td>
580+
<td>Overlapping between bars (unit fraction): 0 -> no overlap, 1/1 -> full overlap</td>
581+
</tr>
577582
</table>
578583

579584
h2. Component Classes

ico.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ var Ico = {
730730
Ico.BaseGraph.prototype.set_defaults.call( this );
731731

732732
this.options.bar_padding = 5;
733+
this.options.bars_overlap = 1 / 2;
733734
},
734735

735736
process_options: function( options ) {
@@ -746,28 +747,35 @@ var Ico = {
746747
};
747748
}
748749
} );
750+
751+
this.options.bars_overlap > 1 && ( this.options.bars_overlap = 1 );
749752
},
750753

751754
calculate: function() {
752755
Ico.BaseGraph.prototype.calculate.call( this );
753756

754-
this.calculate_bars()
757+
this.calculate_bars();
758+
759+
var o = this.bars_overlap = this.options.bars_overlap
760+
, n = this.series.length
761+
, w = this.bars_width = this.bar_width / ( n - ( n - 1 ) * o )
762+
;
763+
764+
this.bars_step = w * ( 1 - o );
755765
},
756766

757767
label_slots_count: function() { return this.data_samples },
758768

759769
draw_value: function( i, x, y, v, serie, set ) {
760770
var a = this.options.series_attributes[serie],
761-
sup = this.series.length + 1,
762-
w = this.bar_width,
763-
width = w * 2 / sup,
764-
base = this.bar_base,
771+
w = this.bars_width,
772+
b = this.bar_base,
765773
bar
766774
;
767-
x += w * serie / sup - w / 2;
775+
x += this.bars_step * serie - this.bar_width / 2;
768776
this.show_label_onmouseover( bar = this.paper.path( Ico.svg_path( this.orientation?
769-
['M', y, x, 'H', base, 'v', width, 'H', y, 'z'] :
770-
['M', x, y, 'V', base, 'h', width, 'V', y, 'z']
777+
['M', y, x, 'H', b, 'v', w, 'H', y, 'z'] :
778+
['M', x, y, 'V', b, 'h', w, 'V', y, 'z']
771779
) ).attr( a ), v, a, serie, i
772780
);
773781
set.push( bar );

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ <h2 id='g10' style="color: blue; margin-top: 20px;">A line of two dependent grap
217217
],
218218
{ font_size: 16
219219
, labels: months
220+
, bars_overlap: 2/3
220221
, font: {
221222
'font-size': 16,
222223
'fill' : 'black',

0 commit comments

Comments
 (0)