Skip to content

Commit

Permalink
Merge pull request #66 from kunalmodi/add-html
Browse files Browse the repository at this point in the history
embed external html charts in widgets
  • Loading branch information
Paul Asmuth committed Apr 21, 2012
2 parents 8a2fd6f + bf4edff commit 689e802
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/fnordmetric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def self.embedded(opts={})
require "fnordmetric/bars_widget"
require "fnordmetric/toplist_widget"
require "fnordmetric/pie_widget"
require "fnordmetric/html_widget"
require "fnordmetric/namespace"
require "fnordmetric/gauge_modifiers"
require "fnordmetric/gauge_calculations"
Expand Down
28 changes: 28 additions & 0 deletions lib/fnordmetric/html_widget.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class FnordMetric::HtmlWidget < FnordMetric::Widget
def data
super.merge(
:html => @opts[:html]
)
end

def add_gauges(gauges)
@gauges = []
@tick = 0

if !gauges.blank?
error! "initializing a html widget with gauges is void"
end
end

def data_gauges
{}
end

def default_range(now=Time.now)
0..0
end

def has_tick?
false
end
end
27 changes: 26 additions & 1 deletion pub/fnordmetric.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,31 @@ var FnordMetric = (function(){

};

var htmlWidget = function(){
function render(opts){

opts.elem.append(
$('<div class="headbar small"></div>').html(opts.title)
).css({
'marginBottom': 20,
'overflow': 'hidden'
});

var container = $('<div></div>')
.addClass('html_container')
.html(opts.html);

opts.elem.append(container);
}

function updateValues(opts){}
function updatedisplay(opts, diff_factor){}

return {
render: render
};
}

var numbersWidget = function(){


Expand Down Expand Up @@ -604,7 +629,6 @@ var FnordMetric = (function(){

};


var pieWidget = function(){

function render(opts){
Expand Down Expand Up @@ -1078,6 +1102,7 @@ var FnordMetric = (function(){
if(widget.klass=='NumbersWidget'){ numbersWidget().render(widget); }
if(widget.klass=='ToplistWidget'){ toplistWidget().render(widget); }
if(widget.klass=='PieWidget'){ pieWidget().render(widget); }
if(widget.klass=="HtmlWidget") { htmlWidget().render(widget); }
};

function resizeWidget(wkey){
Expand Down

0 comments on commit 689e802

Please sign in to comment.