Skip to content

Commit 3bb1ba1

Browse files
committed
1 parent 1471ea1 commit 3bb1ba1

File tree

1 file changed

+35
-4
lines changed
  • vendor/assets/javascripts/dashing/default_widgets

1 file changed

+35
-4
lines changed

vendor/assets/javascripts/dashing/default_widgets/graph.coffee

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@ class Dashing.Graph extends Dashing.Widget
1111
# Gross hacks. Let's fix this.
1212
width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1)
1313
height = (Dashing.widget_base_dimensions[1] * container.data("sizey"))
14+
15+
y_scale_type = @get("yscale")
16+
17+
# If log scale is requested or required, we need to know the range to populate the axis
18+
min = Number.MAX_VALUE
19+
max = Number.MIN_VALUE
20+
data = [ {x:0, y:0} ]
21+
data = @get('points') if @get('points')
22+
23+
for d in data
24+
min = Math.min(min, d.y)
25+
max = Math.max(max, d.y)
26+
27+
if (!y_scale_type)
28+
if ((min>0 && max>0 && max/min>500) || (min<0 && max<0 && min/max>500))
29+
y_scale_type = 'log'
30+
else
31+
y_scale_type = 'linear'
32+
33+
if y_scale_type.match ///log(?:\(((?:\d+(?:\.\d+)?)|e)\))?///
34+
y_base=RegExp.$1 || 10
35+
(y_base=="e") && (y_base=Math.E)
36+
y_scale=d3.scale.log().base(y_base).domain([min, max])
37+
log_y_scale_base=Math.log(y_scale.base())
38+
tickValues=[]
39+
for p in [Math.ceil(Math.log(min)/log_y_scale_base)..Math.floor(Math.log(max)/log_y_scale_base)] by 1
40+
tickValues.push(Math.pow(y_base,p))
41+
else
42+
y_scale=d3.scale.linear()
43+
tickValues=null
44+
1445
@graph = new Rickshaw.Graph(
1546
element: @node
1647
width: width
@@ -19,16 +50,16 @@ class Dashing.Graph extends Dashing.Widget
1950
series: [
2051
{
2152
color: "#fff",
22-
data: [{x:0, y:0}]
53+
data: data
54+
scale: y_scale
2355
}
2456
]
25-
padding: {top: 0.02, left: 0.02, right: 0.02, bottom: 0.02}
2657
)
2758

2859
@graph.series[0].data = @get('points') if @get('points')
2960

30-
x_axis = new Rickshaw.Graph.Axis.Time(graph: @graph)
31-
y_axis = new Rickshaw.Graph.Axis.Y(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
61+
x_axis = new Rickshaw.Graph.Axis.Time(graph: @graph, timeFixture: new Rickshaw.Fixtures.Time.Local())
62+
y_axis = new Rickshaw.Graph.Axis.Y.Scaled(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT, scale:y_scale, tickValues: tickValues)
3263
@graph.render()
3364

3465
onData: (data) ->

0 commit comments

Comments
 (0)