From 11d443664b7a785b42cbbd5b96347bafa5ad273a Mon Sep 17 00:00:00 2001 From: varac Date: Wed, 13 Jul 2016 20:07:09 +0200 Subject: initial commit, import from pixelated_dashboard --- widgets/graph/graph.coffee | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 widgets/graph/graph.coffee (limited to 'widgets/graph/graph.coffee') diff --git a/widgets/graph/graph.coffee b/widgets/graph/graph.coffee new file mode 100644 index 0000000..a54de08 --- /dev/null +++ b/widgets/graph/graph.coffee @@ -0,0 +1,36 @@ +class Dashing.Graph extends Dashing.Widget + + @accessor 'current', -> + return @get('displayedValue') if @get('displayedValue') + points = @get('points') + if points + points[points.length - 1].y + + ready: -> + container = $(@node).parent() + # Gross hacks. Let's fix this. + width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1) + height = (Dashing.widget_base_dimensions[1] * container.data("sizey")) + @graph = new Rickshaw.Graph( + element: @node + width: width + height: height + renderer: @get("graphtype") + series: [ + { + color: "#fff", + data: [{x:0, y:0}] + } + ] + ) + + @graph.series[0].data = @get('points') if @get('points') + + x_axis = new Rickshaw.Graph.Axis.X(graph: @graph) + y_axis = new Rickshaw.Graph.Axis.Y(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT) + @graph.render() + + onData: (data) -> + if @graph + @graph.series[0].data = data.points + @graph.render() -- cgit v1.2.3