-
Notifications
You must be signed in to change notification settings - Fork 593
Per series roll period #811
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
Open
evamedia
wants to merge
7
commits into
danvk:master
Choose a base branch
from
evamedia:per-series-roll-period
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
adaa6ca
Per series roll period
evamedia 41047fb
Added auto_test
evamedia 8c386f1
Adding test html example
evamedia 717ff0b
Style guide updates
evamedia c57720f
Changes Requested
evamedia ab6575d
removed a few tabs
evamedia 28c3e15
var not const
evamedia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /** | ||
| * @fileoverview Tests for per series rolling averages. | ||
| * | ||
| * @author Nick Hayday ([email protected]) | ||
| */ | ||
|
|
||
| import Dygraph from '../../src/dygraph'; | ||
|
|
||
| import Util from './Util'; | ||
|
|
||
| describe("per-series-rolling-average", function() { | ||
|
|
||
| cleanupAfterEach(); | ||
|
|
||
| it('testPerSeriesRollingAverage', function() { | ||
| var opts = { | ||
| width: 480, | ||
| height: 320, | ||
| series: { | ||
| Y: { | ||
| rollPeriod: 1 } | ||
| } | ||
| }; | ||
| var data = "X,Y,Z\n" + | ||
| "0,0,0\n" + | ||
| "1,1,10\n" + | ||
| "2,2,20\n" + | ||
| "3,3,30\n" | ||
| ; | ||
|
|
||
| var graph = document.getElementById("graph"); | ||
| var g = new Dygraph(graph, data, opts); | ||
|
|
||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 1 Z: 10", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 2 Z: 20", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 3 Z: 30", Util.getLegend()); | ||
| assert.equal(1, g.getOption("rollPeriod", "Y")); | ||
| g.updateOptions({ | ||
| series: { Y: { rollPeriod: 2 } } | ||
| }); | ||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 0.5 Z: 10", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 1.5 Z: 20", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 2.5 Z: 30", Util.getLegend()); | ||
| assert.equal(2, g.getOption("rollPeriod", "Y")); | ||
| g.updateOptions({ | ||
| series: { Y: { rollPeriod: 3 }, | ||
| Z: { rollPeriod: 2 } } | ||
| }); | ||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 0.5 Z: 5", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 1 Z: 15", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 2 Z: 25", Util.getLegend()); | ||
| assert.equal(3, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(2, g.getOption("rollPeriod", "Z")); | ||
| g.updateOptions({ | ||
| series: { Y: { rollPeriod: 1 }, | ||
| Z: { rollPeriod: 4 } } | ||
| }); | ||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 1 Z: 5", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 2 Z: 10", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 3 Z: 15", Util.getLegend()); | ||
| assert.equal(1, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(4, g.getOption("rollPeriod", "Z")); | ||
| }); | ||
|
|
||
| it('testDefaultToGlobalRollingAverage', function() { | ||
| var opts = { | ||
| width: 480, | ||
| height: 320, | ||
| rollPeriod: 2, | ||
| series: { | ||
| Y: { | ||
| rollPeriod: 1 } | ||
| } | ||
| }; | ||
| var data = "X,Y,Z\n" + | ||
| "0,0,0\n" + | ||
| "1,1,10\n" + | ||
| "2,2,20\n" + | ||
| "3,3,30\n" | ||
| ; | ||
|
|
||
| var graph = document.getElementById("graph"); | ||
| var g = new Dygraph(graph, data, opts); | ||
|
|
||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 1 Z: 5", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 2 Z: 15", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 3 Z: 25", Util.getLegend()); | ||
| assert.equal(1, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(2, g.getOption("rollPeriod", "Z")); | ||
| assert.equal(2, g.getOption("rollPeriod")); | ||
| g.updateOptions({ | ||
| series: { Y: { rollPeriod: 3 } } | ||
| }); | ||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 0.5 Z: 5", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 1 Z: 15", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 2 Z: 25", Util.getLegend()); | ||
| assert.equal(3, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(2, g.getOption("rollPeriod", "Z")); | ||
| assert.equal(2, g.getOption("rollPeriod")); | ||
| g.updateOptions({ | ||
| rollPeriod: 4 | ||
| }); | ||
| g.setSelection(0); assert.equal("0: Y: 0 Z: 0", Util.getLegend()); | ||
| g.setSelection(1); assert.equal("1: Y: 0.5 Z: 5", Util.getLegend()); | ||
| g.setSelection(2); assert.equal("2: Y: 1 Z: 10", Util.getLegend()); | ||
| g.setSelection(3); assert.equal("3: Y: 2 Z: 15", Util.getLegend()); | ||
| assert.equal(3, g.getOption("rollPeriod", "Y")); | ||
| assert.equal(4, g.getOption("rollPeriod", "Z")); | ||
| assert.equal(4, g.getOption("rollPeriod")); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2026,14 +2026,17 @@ Dygraph.prototype.predraw_ = function() { | |
|
|
||
| this.cascadeEvents_('predraw'); | ||
|
|
||
|
|
||
| // Convert the raw data (a 2D array) into the internal format and compute | ||
| // rolling averages. | ||
| var seriesName = this.getLabels(); | ||
| this.rolledSeries_ = [null]; // x-axis is the first series and it's special | ||
| for (var i = 1; i < this.numColumns(); i++) { | ||
| // var logScale = this.attr_('logscale', i); // TODO(klausw): this looks wrong // konigsberg thinks so too. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you get rid of the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the whole library? |
||
| var series = this.dataHandler_.extractSeries(this.rawData_, i, this.attributes_); | ||
| if (this.rollPeriod_ > 1) { | ||
| series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, this.attributes_); | ||
| var rollPeriod = this.getOption('rollPeriod', seriesName[i]); | ||
| if (rollPeriod > 1) { | ||
| series = this.dataHandler_.rollingAverage(series, rollPeriod, this.attributes_); | ||
| } | ||
|
|
||
| this.rolledSeries_.push(series); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" href="../css/dygraph.css"> | ||
| <title>Per Series Rolling Average</title> | ||
| <script type='text/javascript' src='https://code.jquery.com/jquery-1.11.3.min.js'></script> | ||
| <script type="text/javascript" src="../dist/dygraph.js"></script> | ||
| <script type="text/javascript" src="data.js"></script> | ||
| <style type="text/css"> | ||
| #graphdiv { | ||
| width:600px; | ||
| height: 300px; | ||
| left: 10px; | ||
| right: 10px; | ||
| top: 40px; | ||
| bottom: 10px; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
|
|
||
| <div id="graphdiv"> </div> | ||
|
|
||
| Check the boxes to apply the rolling average <br> | ||
|
|
||
| <input type="checkbox" href="#" id="high" name="high" />High (7 day rolling average)<br> | ||
| <input type="checkbox" href="#" id="low" name="low" />Low (30 day rolling average) | ||
|
|
||
| <script type="text/javascript"> | ||
|
|
||
| var g = new Dygraph(document.getElementById('graphdiv'), data, | ||
| { | ||
| title: 'Per Series Rolling Average', | ||
| xlabel: 'Date', | ||
| ylabel: 'Temperature (F)' | ||
| }); | ||
|
|
||
| function updateRollPeriod(series, value) { | ||
| var seriesOpt = {}; | ||
| seriesOpt[series] = { rollPeriod: value }; | ||
| g.updateOptions ({ series: seriesOpt }); | ||
| } | ||
|
|
||
| $("#high").change(function () { | ||
| if(this.checked) { | ||
| updateRollPeriod("High", 7); | ||
| } else { | ||
| updateRollPeriod("High", 1); | ||
| } | ||
| }); | ||
|
|
||
| $("#low").change(function () { | ||
| if(this.checked) { | ||
| updateRollPeriod("Low", 30); | ||
| } else { | ||
| updateRollPeriod("Low", 1); | ||
| } | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: fix indentation here