examples/bar_chart/bar_chart.rb
#--------------------------------------------------------------------------------------
# updates the bars with new data
#--------------------------------------------------------------------------------------
updates the bars with new data
updates the bars with new data
def update_bars
    @x_scale.domain([*0..@dataset.length])
    y_min, y_max = @dataset.minmax_by { |d| d[:value] }
    @y_scale.update([0, y_max[:value]], [0, @height])
    x_scale, y_scale, height = @x_scale, @y_scale, @height
    svg.selectAll("rect")
      .data(@dataset) { |d| d[:key] }
      .attr({
              "x"=> ->(d, i, z) { x_scale[i] },
              "y"=> ->(d, i, z) {height - y_scale[d[:value]] },
              "width"=> x_scale.scale.rangeBand(nil),
              "height"=> ->(d, i, z) {y_scale[d[:value]]},
              "fill"=> ->(d, i, z) { "rgb(0, 0, #{(d[:value] * 10).to_i})" }})
  end
def update_bars @x_scale . domain ( [ * 0 .. @dataset . length ] ) y_min , y_max = @dataset . minmax_by { | d | d [ :value ] } @y_scale . update ( [ 0 , y_max [ :value ] ] , [ 0 , @height ] ) x_scale , y_scale , height = @x_scale , @y_scale , @height svg . selectAll ( "rect" ) . data ( @dataset ) { | d | d [ :key ] } . attr ( { "x" => -> ( d , i , z ) { x_scale [ i ] } , "y" => -> ( d , i , z ) { height - y_scale [ d [ :value ] ] } , "width" => x_scale . scale . rangeBand ( nil ) , "height" => -> ( d , i , z ) { y_scale [ d [ :value ] ] } , "fill" => -> ( d , i , z ) { "rgb(0, 0, #{(d[:value] * 10).to_i})" } } ) end
updates the bars with new data
updates the bars with new data
# correct the x scale to the new dataset # correct the y scale to the new dataset # Set local variable to their equivalent instance variable so that they are # available inside blocks.  I don´t know if there is a better way of doing # this.  Tried googling for a better solution but without success! #profile_data = JRuby::Profiler.profile do # Having all atributes set inside a single .attr call is more efficient than # having multiple .attr calls #end # .transition(nil) # .delay { |d, i| i * 100 } # .duration(100) =begin    
    my_output_stream = java.io.ByteArrayOutputStream.new
    print_stream = java.io.PrintStream.new(my_output_stream)
    
    profile_printer = JRuby::Profiler::FlatProfilePrinter.new(profile_data)
    profile_printer.printProfile(print_stream)
    result = my_output_stream.toString    
    p result
=end    