class RubyvisCharts::StackedBarTimelineChart
Attributes
bars_colors[R]
bars_padding[R]
Public Class Methods
new( bars_padding: DefaultArguments::BARS_PADDING, bars_colors: DefaultArguments::BARS_COLORS, **other )
click to toggle source
Calls superclass method
RubyvisCharts::AbstractTimelineChart::new
# File lib/rubyvis_charts/stacked_bar_timeline_chart.rb, line 10 def initialize( bars_padding: DefaultArguments::BARS_PADDING, bars_colors: DefaultArguments::BARS_COLORS, **other ) super(other) @bars_padding = bars_padding @bars_colors = bars_colors initialize_bars! end
Protected Instance Methods
values_max()
click to toggle source
# File lib/rubyvis_charts/stacked_bar_timeline_chart.rb, line 25 def values_max @max_value ||= values.transpose.map do |transposed_value| transposed_value.inject(0) {|sum, x| sum + x } end.max end
Private Instance Methods
bars_widths()
click to toggle source
# File lib/rubyvis_charts/stacked_bar_timeline_chart.rb, line 47 def bars_widths @bars_widths ||= Rubyvis::Scale.ordinal(Rubyvis.range(values_max_count)).split_banded(0, timeline_width) end
initialize_bars!()
click to toggle source
# File lib/rubyvis_charts/stacked_bar_timeline_chart.rb, line 33 def initialize_bars! chart = self fill_style_colors = -> { chart.send(:bars_colors_iterator, self.parent.index, self.height, chart.bars_colors) } @layer_timeline.add(Rubyvis::Layout::Stack) .layers(values) .x(-> { chart.send(:bars_widths)[self.index] + chart.bars_padding.left }) .y(->(d) { chart.send(:bars_heights)[d] }) .layer.add(Rubyvis::Bar) .width(bars_widths.range_band - bars_padding.left - bars_padding.right) .fillStyle(fill_style_colors) end