-
Notifications
You must be signed in to change notification settings - Fork 604
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
Per series roll period #811
base: master
Are you sure you want to change the base?
Conversation
Enables adding of rollPeriod inside series parameters. If rollPeriod is set globally, series will default to that if parameter not set
Thanks for the contribution! To be considered for merging, this needs unit tests and needs to follow the style of the rest of the dygraphs code. |
You can absolutely update per-series options. Here's a demo:
http://jsfiddle.net/eM2Mg/9155/
…On Thu, Dec 29, 2016 at 4:37 AM, evamedia ***@***.***> wrote:
Looking into unit tests, can you currently change per-series options with
updateOptions() ?
Limited testing seems to say no, I also found this
// TODO(danvk): validate per-series options.
// Supported:
// strokeWidth
// pointSize
// drawPoints
// highlightCircleSize
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#811 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAF__fLLt58GIrXcmeCM0181VECUNhIvks5rM39XgaJpZM4LVZD1>
.
|
Test’s setting of per series rollPeriod in initial setup, then changing, and adding to another series. Tests series defaults to global rollPeriod if not explicitly set
apologies, auto_test submitted, can you give me a pointer on the style? Is there a guide? |
Shows two series and demonstrates independent changing of rolling average
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.
This is looking good. I'd like one of the behaviors to be different, but other than that it's just style nits and cleanup. Thanks for adding the tests!
|
||
var seriesOpt = {}; | ||
seriesOpt["Y"] = { rollPeriod: 2 }; | ||
g.updateOptions ({ series: seriesOpt }); |
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.
Make the updateOptions calls self-contained by writing them as:
g.updateOptions({
series: { Y: { rollPeriod: 2 } }
});
and killing the seriesOpt
variable (here and below).
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")); | ||
|
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: remove these blank lines
height: 320, | ||
rollPeriod: 2, | ||
series: { | ||
Y: { |
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
g.setSelection(2); assert.equal("2: Y: 1 Z: 10", Util.getLegend()); | ||
g.setSelection(3); assert.equal("3: Y: 2 Z: 20", Util.getLegend()); | ||
assert.equal(3, g.getOption("rollPeriod", "Y")); | ||
assert.equal(3, g.getOption("rollPeriod", "Z")); |
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.
This should be 2 to be consistent with how other per-series options work. See http://jsfiddle.net/eM2Mg/9158/
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.
Not sure I understand "Y" is 3 because it was set previously, "Z" is 3 because the global rollPeriod was updated and "Z" hadn't been set separately. On the example initial strokeWidth : 4 for "Z" then the global StrokeWidth is changed to 1 , leaving "X" at 2
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.
Ah, nevermind. I misread this.
Could you add a test that makes sure updating the global rollPeriod
doesn't affect a per-series rollPeriod
?
if (this.rollPeriod_ > 1) { | ||
series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, this.attributes_); | ||
var seriesRollPeriod; | ||
|
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: remove blank line & fix indentation
</style> | ||
</head> | ||
<body> | ||
|
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: use a two space indent in this file
var seriesRollPeriod; | ||
|
||
if (this.getOption('rollPeriod', seriesName[i])) { | ||
seriesRollPeriod = this.getOption('rollPeriod', seriesName[i]); |
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.
It should suffice to say:
const rollPeriod = this.getOption('rollPeriod', seriesName[i]);
this will get the per-series value or fall back to the global one.
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.rollPeriod()); |
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.
We should get rid of the rollPeriod()
method. getOption('rollPeriod')
does the same thing but also lets you get per-series values.
// Convert the raw data (a 2D array) into the internal format and compute | ||
// rolling averages. | ||
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. | ||
var series = this.dataHandler_.extractSeries(this.rawData_, i, this.attributes_); | ||
if (this.rollPeriod_ > 1) { |
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.
Can you get rid of the rollPeriod_
member variable altogether?
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.
Do you mean the whole library?
Altered last test to prove changing global rollPeriod doesn’t change a series rollPeriod
Any idea if/when this functionality gets into the software? Currently I add it manally on each Dygraph release. |
Enables adding of rollPeriod inside series parameters. If rollPeriod is
set globally, series will default to that if parameter not set