Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunOnce if refresh_interval is 0 #43

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ description.
padding = the kind of padding you need
title = box title
label_formatter = and a formatter, as before.

asInfinite = [2, 'myEvent'] pick the 3rd (index:2) series and the series labelled 'myEvent' and draw it [as infinite](http://graphite.readthedocs.org/en/1.0/functions.html#graphite.render.functions.drawAsInfinite)

# Visuals

Expand Down
44 changes: 31 additions & 13 deletions app/js/graphene.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Graphene
@is_demo = true
build: (json)=>
_.each _.keys(json), (k)=>
console.log "building [#{k}]"
#console.log "building [#{k}]"
if @is_demo
klass = Graphene.DemoTimeSeries
else
Expand All @@ -20,7 +20,7 @@ class Graphene

_.each json[k], (opts, view)->
klass = eval("Graphene.#{view}View")
console.log _.extend({ model: ts }, opts)
#console.log _.extend({ model: ts }, opts)
new klass(_.extend({ model: ts }, opts))
ts.start()

Expand Down Expand Up @@ -56,8 +56,10 @@ class Graphene.GraphiteModel extends Backbone.Model

start: ()=>
@refresh()
console.log("Starting to poll at #{@get('refresh_interval')}")
@t_index = setInterval(@refresh, @get('refresh_interval'))
#RunOnce if refresh_interval is set as 0
if 0 != @refresh_interval
#console.log("Starting to poll at #{@get('refresh_interval')}")
@t_index = setInterval(@refresh, @get('refresh_interval'))

stop: ()=>
clearInterval(@t_index)
Expand All @@ -73,7 +75,7 @@ class Graphene.GraphiteModel extends Backbone.Model
dataType: 'json'
jsonp: 'jsonp'
success: (js) =>
console.log("got data.")
#console.log("got data.")
@process_data(js)
$.ajax options

Expand Down Expand Up @@ -150,7 +152,7 @@ class Graphene.DemoTimeSeries extends Backbone.Model

class Graphene.BarChart extends Graphene.GraphiteModel
process_data: (js)=>
console.log 'process data barchart'
#console.log 'process data barchart'
data = _.map js, (dp)->
min = d3.min(dp.datapoints, (d) -> d[0])
return null unless min != undefined
Expand Down Expand Up @@ -225,7 +227,7 @@ class Graphene.GaugeGadgetView extends Backbone.View
@gauge.render()

@model.bind('change', @render)
console.log("GG view ")
#console.log("GG view ")


by_type:(d)=>
Expand All @@ -236,7 +238,7 @@ class Graphene.GaugeGadgetView extends Backbone.View
else d.points[0][0]

render: ()=>
console.log("rendering.")
#console.log("rendering.")
data = @model.get('data')
datum = if data && data.length > 0 then data[0] else { ymax: @null_value, ymin: @null_value, points: [[@null_value, 0]] }

Expand Down Expand Up @@ -267,7 +269,7 @@ class Graphene.GaugeLabelView extends Backbone.View
.text(@title)

@model.bind('change', @render)
console.log("GL view ")
#console.log("GL view ")


by_type:(d)=>
Expand All @@ -279,7 +281,7 @@ class Graphene.GaugeLabelView extends Backbone.View

render: ()=>
data = @model.get('data')
console.log data
#console.log data
datum = if data && data.length > 0 then data[0] else { ymax: @null_value, ymin: @null_value, points: [[@null_value, 0]] }


Expand Down Expand Up @@ -320,6 +322,7 @@ class Graphene.TimeSeriesView extends Backbone.View
@firstrun = true
@parent = @options.parent || '#parent'
@null_value = 0
@asInfinite = @options.asInfinite || []

@vis = d3.select(@parent).append("svg")
.attr("class", "tsview")
Expand All @@ -332,11 +335,11 @@ class Graphene.TimeSeriesView extends Backbone.View
@value_format = d3.format(@value_format)

@model.bind('change', @render)
console.log("TS view: #{@width}x#{@height} padding:#{@padding} animate: #{@animate_ms} labels: #{@num_labels}")
#console.log("TS view: #{@width}x#{@height} padding:#{@padding} animate: #{@animate_ms} labels: #{@num_labels}")


render: ()=>
console.log("rendering.")
#console.log("rendering.")
data = @model.get('data')

data = if data && data.length > 0 then data else [{ ymax: @null_value, ymin: @null_value, points: [[@null_value, 0],[@null_value, 0]] }]
Expand Down Expand Up @@ -372,6 +375,21 @@ class Graphene.TimeSeriesView extends Backbone.View
line = d3.svg.line().x((d) -> x(d[1])).y((d) -> y(d[0]))
area = d3.svg.area().x((d) -> x(d[1])).y0(@height - 1).y1((d) -> y(d[0]))

#
# post-processing
# data transofrmation for view purposes
#
# 1. DrawAsInfinite: if a series is marked as such, we'll transform
# a > 0 value to infinity (here the max value in graph) or 0 otherwise.
#
di = 0
if @asInfinite
_.each data, (d)=>
if _.include(@asInfinite, di) || _.include(@asInfinite, d.label)
_.each d.points, (p) =>
p[0] = if p[0] > 0 then dmax.ymax else 0
di += 1

#
# get first X labels
#
Expand Down Expand Up @@ -569,4 +587,4 @@ class Graphene.BarChartView extends Backbone.View
vis.transition().ease("linear").duration(@animate_ms).select(".x.axis").call(xAxis)
vis.select(".y.axis").call(yAxis)

console.log "done drawing"
#console.log "done drawing"
536 changes: 524 additions & 12 deletions build/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion example/dashboard-autodiscover.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

</div>

<script type="text/javascript" src="/vendor/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/build/index.js"></script>
<script type="text/javascript">
$(function(){
Expand Down
1 change: 0 additions & 1 deletion example/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ <h2>A <a href="">D3.js</a>, <a href="">Backbone.js</a> based <a
</div>
</div>

<script type="text/javascript" src="/vendor/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/build/index.js"></script>
<script type="text/javascript" src="example-dash.js"></script>

Expand Down
43 changes: 43 additions & 0 deletions tools/compile-source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python2.7

import httplib, urllib, sys, os
import subprocess

#Change the script's working directory to the script's own directory
abspath = os.path.abs_path(__file__)
script_dir = os.path.dirname(abspath)
os.chdir(script_dir)

with open('../app/js/d3.gauge.js') as graphene_gauge_file:
graphene_gauge = graphene_gauge_file.read()

p = subprocess.Popen(['/usr/bin/coffee', '-cp', '../app/js/graphene.coffee'],stdout=subprocess.PIPE)
graphene_data = p.communicate()[0]

params = urllib.urlencode([
('code_url', 'http://code.jquery.com/jquery-1.8.0.min.js'), # jquery
('code_url', 'http://underscorejs.org/underscore-min.js'), # underscore
('code_url', 'http://backbonejs.org/backbone-min.js'), # backbone
('code_url', 'http://d3js.org/d3.v3.min.js'), # d3
('js_code', graphene_gauge),
('js_code', graphene_data),
('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
('output_format','text'),
('output_info','compiled_code'),
])

headers = {
"Content-Type": "application/x-www-form-urlencoded",
}

conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST','/compile',params,headers)
response = conn.getresponse()
data = response.read()

f = open('../build/index.js','w')
f.write(data)

print "Done."

conn.close()