Skip to content

Conversation

@evamedia
Copy link

@evamedia evamedia commented Dec 25, 2016

Enables adding of rollPeriod inside series parameters. If rollPeriod is
set globally, series will default to that if parameter not set

Enables adding of rollPeriod inside series parameters. If rollPeriod is
set globally, series will default to that if parameter not set
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 90.071% when pulling adaa6ca on evamedia:per-series-roll-period into 623dd1d on danvk:master.

@danvk
Copy link
Owner

danvk commented Dec 27, 2016

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.

@danvk
Copy link
Owner

danvk commented Dec 30, 2016 via email

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
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 90.155% when pulling 41047fb on evamedia:per-series-roll-period into 623dd1d on danvk:master.

@evamedia
Copy link
Author

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
@danvk
Copy link
Owner

danvk commented Dec 30, 2016

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 90.155% when pulling 8c386f1 on evamedia:per-series-roll-period into 623dd1d on danvk:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.176% when pulling 717ff0b on evamedia:per-series-roll-period into 623dd1d on danvk:master.

Copy link
Owner

@danvk danvk left a 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 });
Copy link
Owner

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"));

Copy link
Owner

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: {
Copy link
Owner

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"));
Copy link
Owner

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/

Copy link
Author

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

Copy link
Owner

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?

src/dygraph.js Outdated
if (this.rollPeriod_ > 1) {
series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, this.attributes_);
var seriesRollPeriod;

Copy link
Owner

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>

Copy link
Owner

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

src/dygraph.js Outdated
var seriesRollPeriod;

if (this.getOption('rollPeriod', seriesName[i])) {
seriesRollPeriod = this.getOption('rollPeriod', seriesName[i]);
Copy link
Owner

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());
Copy link
Owner

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.

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) {
Copy link
Owner

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?

Copy link
Author

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
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 90.148% when pulling c57720f on evamedia:per-series-roll-period into 623dd1d on danvk:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 90.148% when pulling ab6575d on evamedia:per-series-roll-period into 623dd1d on danvk:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.17% when pulling 28c3e15 on evamedia:per-series-roll-period into 623dd1d on danvk:master.

@mdrmdrmdr
Copy link

mdrmdrmdr commented Jan 3, 2018

Any idea if/when this functionality gets into the software? Currently I add it manally on each Dygraph release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants