Skip to content

Commit bec07aa

Browse files
committed
Merge pull request #75 from mchandramouli/master
adding warning and error indicator lines to TimeSeriesView
2 parents c487923 + b1c6d80 commit bec07aa

File tree

6 files changed

+65
-16
lines changed

6 files changed

+65
-16
lines changed

app/css/high-contrast.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ line.tick {
7979
stroke-opacity: 0.3;
8080
}
8181

82+
path.line-warn {
83+
stroke: yellow;
84+
fill: yellow;
85+
stroke-width: 2px;
86+
}
87+
path.line-error {
88+
stroke: red;
89+
fill: red;
90+
stroke-width: 2px;
91+
}
92+
8293
.min-tag{
8394
fill:red;
8495
margin: 0 1em;

app/js/graphene.coffee

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ class Graphene.TimeSeriesView extends Backbone.View
338338
initialize: ()->
339339
@name = @options.name || "g-" + parseInt(Math.random() * 1000000)
340340
@line_height = @options.line_height || 16
341+
@x_ticks = @options.x_ticks || 4
342+
@y_ticks = @options.y_ticks || 4
341343
@animate_ms = @options.animate_ms || 500
342344
@label_offset = @options.label_offset || 0
343345
@label_columns = @options.label_columns || 1
@@ -399,8 +401,8 @@ class Graphene.TimeSeriesView extends Backbone.View
399401
# build axis
400402
#
401403
xtick_sz = if @display_verticals then -@height else 0
402-
xAxis = d3.svg.axis().scale(x).ticks(4).tickSize(xtick_sz).tickSubdivide(true)
403-
yAxis = d3.svg.axis().scale(y).ticks(4).tickSize(-@width).orient("left").tickFormat(d3.format("s"))
404+
xAxis = d3.svg.axis().scale(x).ticks(@x_ticks).tickSize(xtick_sz).tickSubdivide(true)
405+
yAxis = d3.svg.axis().scale(y).ticks(@y_ticks).tickSize(-@width).orient("left").tickFormat(d3.format("s"))
404406

405407
vis = @vis
406408

@@ -452,7 +454,27 @@ class Graphene.TimeSeriesView extends Backbone.View
452454
#
453455
vis.selectAll("path.line").data(points).enter().append('path').attr("d", line).attr('class', (d,i) -> 'line '+"h-col-#{i+1}")
454456
vis.selectAll("path.area").data(points).enter().append('path').attr("d", area).attr('class', (d,i) -> 'area '+"h-col-#{i+1}")
455-
457+
458+
if (@options.warn && (dmax.ymax_graph > @options.warn))
459+
warnData = [[[@options.warn, xmin],[@options.warn, xmax]]]
460+
vis.selectAll("path.line-warn")
461+
.data(warnData)
462+
.enter()
463+
.append('path')
464+
.attr('d', line)
465+
.attr('stroke-dasharray', '10,10')
466+
.attr('class', 'line-warn')
467+
468+
if (@options.error && (dmax.ymax_graph > @options.error))
469+
errorData= [[[@options.error, xmin],[@options.error, xmax]]]
470+
vis.selectAll("path.line-error")
471+
.data(errorData)
472+
.enter()
473+
.append('path')
474+
.attr('d', line)
475+
.attr('stroke-dasharray', '10,10')
476+
.attr('class', 'line-error')
477+
456478
#
457479
# Title + Legend
458480
#
@@ -540,7 +562,7 @@ class Graphene.TimeSeriesView extends Backbone.View
540562
.transition()
541563
.ease("linear")
542564
.duration(@animate_ms)
543-
565+
544566
@postrender(@vis)
545567

546568
# Barcharts

app/js/graphene.events.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ function toggleHighlight(classVal, toggleVal) {
1212
}
1313

1414
function postRenderTimeSeriesView(vis) {
15-
console.log("attaching hover event...");
1615
var svg = vis;
1716
svg.selectAll('a.l').forEach( function(g) {
1817
g.forEach(function(a){
1918
var aid = a.getAttribute('id')
20-
console.log("adding mouse enter and exit events for " + aid);
2119
a.addEventListener('mouseenter', function() {
22-
console.log("enter " + aid)
2320
svg.selectAll('path#l-' + aid).forEach ( function (g) {
2421
g.forEach(function (path) {
2522
path.setAttribute('class', toggleHighlight(path.getAttribute('class'), "line-highlight"));
@@ -32,7 +29,6 @@ function postRenderTimeSeriesView(vis) {
3229
})
3330
})
3431
a.addEventListener('mouseleave', function() {
35-
console.log("exit " + aid)
3632
svg.selectAll('path#l-' + aid).forEach ( function (g) {
3733
g.forEach(function (path) {
3834
path.setAttribute('class', toggleHighlight(path.getAttribute('class'), "line-highlight"));

build/index.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,16 @@ line.tick {
711711
fill: none;
712712
stroke-opacity: 0.3; }
713713

714+
path.line-warn {
715+
stroke: yellow;
716+
fill: yellow;
717+
stroke-width: 2px; }
718+
719+
path.line-error {
720+
stroke: red;
721+
fill: red;
722+
stroke-width: 2px; }
723+
714724
.min-tag {
715725
fill: red;
716726
margin: 0 1em; }

build/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example-dash.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
source: "http://localhost:4567/",
4343
TimeSeries: {
4444
parent: '#g1-1',
45-
label_offset: 200,
46-
label_columns: 2,
45+
title: 'New Message',
46+
label_offset: 200,
47+
label_columns: 2,
48+
time_span_mins: 12,
4749
observer: function(data){
4850
console.log("Time series observing ", data);
4951
}
@@ -52,19 +54,27 @@
5254
"Feed Poll": {
5355
source: "http://localhost:4567/",
5456
TimeSeries: {
57+
title: 'Feed Poll',
58+
y_ticks: 2,
59+
display_verticals: true,
5560
parent: '#g1-2'
5661
}
5762
},
5863
"Topics": {
5964
source: "http://localhost:4567/",
6065
refresh_interval: 20000,
6166
TimeSeries: {
67+
title: 'Topics',
6268
parent: '#g1-3'
6369
}
6470
},
6571
"Queue Push": {
6672
source: "http://localhost:4567/",
6773
TimeSeries: {
74+
title: 'Queue Push',
75+
ymax: 1000,
76+
warn: 600,
77+
error: 800,
6878
parent: '#g2-1'
6979
}
7080
},

0 commit comments

Comments
 (0)