examples/bar_chart/bar_chart.rb
#--------------------------------------------------------------------------------------
# Adds a single bar to the chart. The @dataset was already updated
#--------------------------------------------------------------------------------------
Adds a single bar to the chart. The @dataset was already updated
Adds a single bar to the chart . The @dataset was already updated
def add_bar
    @svg.selectAll("rect")
      .data(@dataset) { |d| d[:key] }
      .enter(nil)
      .append("rect")
      .on("mouseover") { $d3.select(@this).attr("fill", "orange") }
      .on("mouseout") { |d| $d3.select(@this)
                          .transition(nil)
                          .duration(500)
                          .attr("fill", "rgb(0, 0, #{(d[:value] * 10).to_i})" )} 
    update_bars
    @svg.selectAll("text")
      .data(@dataset) { |d| d[:key] }
      .enter(nil)
      .append("text")
      .text { |d, i| d[:value] }
    update_labels
  end
def add_bar @svg . selectAll ( "rect" ) . data ( @dataset ) { | d | d [ :key ] } . enter ( nil ) . append ( "rect" ) . on ( "mouseover" ) { $d3 . select ( @this ) . attr ( "fill" , "orange" ) } . on ( "mouseout" ) { | d | $d3 . select ( @this ) . transition ( nil ) . duration ( 500 ) . attr ( "fill" , "rgb(0, 0, #{(d[:value] * 10).to_i})" ) } update_bars @svg . selectAll ( "text" ) . data ( @dataset ) { | d | d [ :key ] } . enter ( nil ) . append ( "text" ) . text { | d , i | d [ :value ] } update_labels end
Adds a single bar to the chart.
Adds a single bar to the chart .
# add the new bar. No need to add attributes as the whole plot will be updated next # add the new label.  Need only to add the text value as all attributes will be set # by update_labels