Class: Tiler::Widgets::BarChart

Inherits:
Tiler::Widget show all
Defined in:
lib/tiler/widgets/bar_chart.rb

Instance Attribute Summary

Attributes inherited from Tiler::Widget

#config, #panel

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tiler::Widget

#data, #initialize, #label, #partial, #query_class

Constructor Details

This class inherits a constructor from Tiler::Widget

Class Method Details

.example_configObject



63
64
65
66
# File 'lib/tiler/widgets/bar_chart.rb', line 63

def self.example_config
  { "group_column" => "service", "value_column" => "count",
    "aggregation" => "sum", "limit" => 10 }
end

.example_payloadObject



68
69
70
# File 'lib/tiler/widgets/bar_chart.rb', line 68

def self.example_payload
  { "service" => "api", "count" => 142 }
end

.example_previewObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tiler/widgets/bar_chart.rb', line 75

def self.example_preview
  {
    "labels" => %w[api web worker cron db cdn],
    "datasets" => [
      { "label" => "count",
        "data" => [ 142, 98, 64, 22, 180, 55 ],
        "backgroundColor" => [ "#3b82f6cc", "#10b981cc", "#f59e0bcc",
                               "#ef4444cc", "#8b5cf6cc", "#06b6d4cc" ],
        "borderColor" => [ "#3b82f6", "#10b981", "#f59e0b",
                           "#ef4444", "#8b5cf6", "#06b6d4" ],
        "borderWidth" => 1 }
    ],
    "options" => {}
  }
end

.supports_color_config?Boolean

Returns:

  • (Boolean)


72
# File 'lib/tiler/widgets/bar_chart.rb', line 72

def self.supports_color_config?;   true; end

.supports_palette_config?Boolean

Returns:

  • (Boolean)


73
# File 'lib/tiler/widgets/bar_chart.rb', line 73

def self.supports_palette_config?; true; end

Instance Method Details

#empty?(data) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/tiler/widgets/bar_chart.rb', line 57

def empty?(data)
  return true if super
  data.nil? || data[:labels].blank? || data[:datasets].blank? ||
    data[:datasets].all? { |ds| Array(ds[:data]).all? { |v| v.nil? || v.zero? } }
end