Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Add y-axis log scale to the graph widget #513

Open
wants to merge 2 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
5 changes: 0 additions & 5 deletions templates/project/assets/javascripts/d3-3.2.8.js

This file was deleted.

5 changes: 5 additions & 0 deletions templates/project/assets/javascripts/d3-3.5.3.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions templates/project/assets/javascripts/rickshaw-1.4.3.min.js

This file was deleted.

3 changes: 3 additions & 0 deletions templates/project/assets/javascripts/rickshaw-1.5.1.min.js

Large diffs are not rendered by default.

39 changes: 35 additions & 4 deletions templates/project/widgets/graph/graph.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ class Dashing.Graph extends Dashing.Widget
# 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"))

y_scale_type = @get("yscale")

# If log scale is requested or required, we need to know the range to populate the axis
min = Number.MAX_VALUE
max = Number.MIN_VALUE
data = [ {x:0, y:0} ]
data = @get('points') if @get('points')

for d in data
min = Math.min(min, d.y)
max = Math.max(max, d.y)

if (!y_scale_type)
if ((min>0 && max>0 && max/min>500) || (min<0 && max<0 && min/max>500))
y_scale_type = 'log'
else
y_scale_type = 'linear'

if y_scale_type.match ///log(?:\(((?:\d+(?:\.\d+)?)|e)\))?///
y_base=RegExp.$1 || 10
(y_base=="e") && (y_base=Math.E)
y_scale=d3.scale.log().base(y_base).domain([min, max])
log_y_scale_base=Math.log(y_scale.base())
tickValues=[]
for p in [Math.ceil(Math.log(min)/log_y_scale_base)..Math.floor(Math.log(max)/log_y_scale_base)] by 1
tickValues.push(Math.pow(y_base,p))
else
y_scale=d3.scale.linear()
tickValues=null

@graph = new Rickshaw.Graph(
element: @node
width: width
Expand All @@ -19,16 +50,16 @@ class Dashing.Graph extends Dashing.Widget
series: [
{
color: "#fff",
data: [{x:0, y:0}]
data: data
scale: y_scale
}
]
padding: {top: 0.02, left: 0.02, right: 0.02, bottom: 0.02}
)

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

x_axis = new Rickshaw.Graph.Axis.Time(graph: @graph)
y_axis = new Rickshaw.Graph.Axis.Y(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
x_axis = new Rickshaw.Graph.Axis.Time(graph: @graph, timeFixture: new Rickshaw.Fixtures.Time.Local())
y_axis = new Rickshaw.Graph.Axis.Y.Scaled(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT, scale:y_scale, tickValues: tickValues)
@graph.render()

onData: (data) ->
Expand Down