Module: Daytona::Charts

Defined in:
lib/daytona/common/charts.rb

Constant Summary collapse

Chart =
Daytona::Chart
ChartElement =
Daytona::ChartElement
ChartType =
Daytona::ChartType
LineChart =
Daytona::LineChart
ScatterChart =
Daytona::ScatterChart
BarChart =
Daytona::BarChart
PieChart =
Daytona::PieChart
BoxAndWhiskerChart =
Daytona::BoxAndWhiskerChart
CompositeChart =
Daytona::CompositeChart
PointData =
Daytona::PointData
BarData =
Daytona::BarData
PieData =
Daytona::PieData
BoxAndWhiskerData =
Daytona::BoxAndWhiskerData

Class Method Summary collapse

Class Method Details

.map_element(el, chart_type) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/daytona/common/charts.rb', line 104

def self.map_element(el, chart_type)
  case chart_type
  when ChartType::LINE, ChartType::SCATTER
    PointData.new(label: el.label, points: el.points)
  when ChartType::BAR
    BarData.new(label: el.label, value: el.value, group: el.group)
  when ChartType::PIE
    PieData.new(label: el.label, angle: el.angle, radius: el.radius)
  when ChartType::BOX_AND_WHISKER
    BoxAndWhiskerData.new(label: el.label, min: el.min, first_quartile: el.first_quartile,
                          median: el.median, third_quartile: el.third_quartile,
                          max: el.max, outliers: el.outliers)
  else
    el
  end
end

.parse_chart(chart) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/daytona/common/charts.rb', line 77

def self.parse_chart(chart)
  type = chart.type || ChartType::UNKNOWN
  elements = (chart.elements || []).map { |el| map_element(el, type) }
  common = { type: chart.type, title: chart.title, png: chart.png, elements: elements }

  case type
  when ChartType::LINE
    LineChart.new(x_label: chart.x_label, y_label: chart.y_label, x_ticks: chart.x_ticks, y_ticks: chart.y_ticks,
                  x_tick_labels: chart.x_tick_labels, y_tick_labels: chart.y_tick_labels,
                  x_scale: chart.x_scale, y_scale: chart.y_scale, **common)
  when ChartType::SCATTER
    ScatterChart.new(x_label: chart.x_label, y_label: chart.y_label, x_ticks: chart.x_ticks, y_ticks: chart.y_ticks,
                     x_tick_labels: chart.x_tick_labels, y_tick_labels: chart.y_tick_labels,
                     x_scale: chart.x_scale, y_scale: chart.y_scale, **common)
  when ChartType::BAR
    BarChart.new(x_label: chart.x_label, y_label: chart.y_label, **common)
  when ChartType::PIE
    PieChart.new(**common)
  when ChartType::BOX_AND_WHISKER
    BoxAndWhiskerChart.new(x_label: chart.x_label, y_label: chart.y_label, **common)
  when ChartType::COMPOSITE_CHART
    CompositeChart.new(**common)
  else
    Chart.new(**common)
  end
end