Class: Demos::StockDecider::StackedBar
- Inherits:
-
Hokusai::Block
- Object
- Hokusai::Block
- Demos::StockDecider::StackedBar
- Defined in:
- ui/examples/stock.rb
Overview
Expecting a data prop in the form of
Constant Summary collapse
- COLORS =
{ :week_3 => [157, 221, 117], :week_4 => [117, 157, 221], :week_5 => [221, 180, 117] }
Instance Attribute Summary
Attributes inherited from Hokusai::Block
Instance Method Summary collapse
Methods inherited from Hokusai::Block
#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, #initialize, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses
Constructor Details
This class inherits a constructor from Hokusai::Block
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hokusai::Block
Instance Method Details
#render(canvas) {|canvas| ... } ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'ui/examples/stock.rb', line 34 def render(canvas) key, weeks = data theight = canvas.height - 50 draw do weeks.reject(&:nil?).sort { |a, b| b <=> a }.each_with_index do |percent, idx| color = COLORS["week_#{idx + 3}".to_sym] height = (theight * percent) / 100 y = canvas.y + theight - height rect(canvas.x, y , 150, height) do |command| command.color = Hokusai::Color.convert(color) command.outline = Hokusai::Outline.convert("4,4, 0, 0") command.outline_color = Hokusai::Color.convert("0,0,0,110") end text("Week #{idx + 3} (#{percent.round(2)})", canvas.x + 2, y + 10) do |command| command.size = 12 end end text(symbol, canvas.x + 12, theight + 5) do |command| command.size = 25 command.color = Hokusai::Color.new(233,233,233,255) end end canvas.x -= 100 yield canvas end |
#symbol ⇒ Object
30 31 32 |
# File 'ui/examples/stock.rb', line 30 def symbol data[0] end |