Class: Trackplot::ChartBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/trackplot/chart_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, **options) ⇒ ChartBuilder

Returns a new instance of ChartBuilder.



8
9
10
11
12
# File 'lib/trackplot/chart_builder.rb', line 8

def initialize(data, **options)
  @data = DataAdapter.normalize(data)
  @options = options
  @components = []
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



6
7
8
# File 'lib/trackplot/chart_builder.rb', line 6

def components
  @components
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/trackplot/chart_builder.rb', line 6

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/trackplot/chart_builder.rb', line 6

def options
  @options
end

Instance Method Details

#area(data_key, **opts) ⇒ Object



24
25
26
27
# File 'lib/trackplot/chart_builder.rb', line 24

def area(data_key, **opts)
  @components << Components::Area.new(data_key, **opts)
  nil
end

#axis(direction, **opts) ⇒ Object



34
35
36
37
# File 'lib/trackplot/chart_builder.rb', line 34

def axis(direction, **opts)
  @components << Components::Axis.new(direction, **opts)
  nil
end

#bar(data_key, **opts) ⇒ Object



19
20
21
22
# File 'lib/trackplot/chart_builder.rb', line 19

def bar(data_key, **opts)
  @components << Components::Bar.new(data_key, **opts)
  nil
end

#brush(**opts) ⇒ Object



89
90
91
92
# File 'lib/trackplot/chart_builder.rb', line 89

def brush(**opts)
  @components << Components::Brush.new(**opts)
  nil
end

#candlestick(**opts) ⇒ Object



69
70
71
72
# File 'lib/trackplot/chart_builder.rb', line 69

def candlestick(**opts)
  @components << Components::Candlestick.new(**opts)
  nil
end

#data_label(**opts) ⇒ Object



84
85
86
87
# File 'lib/trackplot/chart_builder.rb', line 84

def data_label(**opts)
  @components << Components::DataLabel.new(**opts)
  nil
end

#drilldown(key, **opts) ⇒ Object



104
105
106
107
# File 'lib/trackplot/chart_builder.rb', line 104

def drilldown(key, **opts)
  @components << Components::Drilldown.new(key: key, **opts)
  nil
end

#funnel(data_key, **opts) ⇒ Object



74
75
76
77
# File 'lib/trackplot/chart_builder.rb', line 74

def funnel(data_key, **opts)
  @components << Components::Funnel.new(data_key, **opts)
  nil
end

#grid(**opts) ⇒ Object



49
50
51
52
# File 'lib/trackplot/chart_builder.rb', line 49

def grid(**opts)
  @components << Components::Grid.new(**opts)
  nil
end

#heatmap(**opts) ⇒ Object



94
95
96
97
# File 'lib/trackplot/chart_builder.rb', line 94

def heatmap(**opts)
  @components << Components::Heatmap.new(**opts)
  nil
end

#horizontal_bar(data_key, **opts) ⇒ Object



64
65
66
67
# File 'lib/trackplot/chart_builder.rb', line 64

def horizontal_bar(data_key, **opts)
  @components << Components::HorizontalBar.new(data_key, **opts)
  nil
end

#legend(**opts) ⇒ Object



44
45
46
47
# File 'lib/trackplot/chart_builder.rb', line 44

def legend(**opts)
  @components << Components::Legend.new(**opts)
  nil
end

#line(data_key, **opts) ⇒ Object



14
15
16
17
# File 'lib/trackplot/chart_builder.rb', line 14

def line(data_key, **opts)
  @components << Components::Line.new(data_key, **opts)
  nil
end

#pie(data_key, **opts) ⇒ Object



29
30
31
32
# File 'lib/trackplot/chart_builder.rb', line 29

def pie(data_key, **opts)
  @components << Components::Pie.new(data_key, **opts)
  nil
end

#radar(data_key, **opts) ⇒ Object



59
60
61
62
# File 'lib/trackplot/chart_builder.rb', line 59

def radar(data_key, **opts)
  @components << Components::Radar.new(data_key, **opts)
  nil
end

#reference_line(**opts) ⇒ Object



79
80
81
82
# File 'lib/trackplot/chart_builder.rb', line 79

def reference_line(**opts)
  @components << Components::ReferenceLine.new(**opts)
  nil
end

#render(view_context) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/trackplot/chart_builder.rb', line 109

def render(view_context)
  chart_id = options[:id] || "trackplot-#{SecureRandom.hex(8)}"
  config = build_config

  html_options = {
    id: chart_id,
    config: config.to_json,
    style: chart_style,
    class: css_classes
  }

  if options[:title]
    html_options[:role] = "img"
    html_options[:"aria-label"] = options[:title]
  end

  view_context.(
    "trackplot-chart",
    nil,
    html_options
  )
end

#scatter(data_key, **opts) ⇒ Object



54
55
56
57
# File 'lib/trackplot/chart_builder.rb', line 54

def scatter(data_key, **opts)
  @components << Components::Scatter.new(data_key, **opts)
  nil
end

#tooltip(**opts) ⇒ Object



39
40
41
42
# File 'lib/trackplot/chart_builder.rb', line 39

def tooltip(**opts)
  @components << Components::Tooltip.new(**opts)
  nil
end

#treemap(**opts) ⇒ Object



99
100
101
102
# File 'lib/trackplot/chart_builder.rb', line 99

def treemap(**opts)
  @components << Components::Treemap.new(**opts)
  nil
end