-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rework groupby style syntax into array #1465
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
Changes from all commits
f55e58d
67058c9
7beddad
f67198b
3cc16ba
1543892
8df0096
49e24ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ var destroyGraphDiv = require('../assets/destroy_graph_div'); | |
var assertDims = require('../assets/assert_dims'); | ||
var assertStyle = require('../assets/assert_style'); | ||
|
||
|
||
describe('groupby', function() { | ||
|
||
describe('one-to-many transforms:', function() { | ||
|
@@ -19,7 +18,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'red'}}}, | ||
{target: 'b', value: {marker: {color: 'blue'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
@@ -30,7 +32,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['b', 'a', 'b', 'b', 'b', 'a', 'a'], | ||
style: { a: {marker: {color: 'green'}}, b: {marker: {color: 'black'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'green'}}}, | ||
{target: 'b', value: {marker: {color: 'black'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
@@ -58,6 +63,58 @@ describe('groupby', function() { | |
}); | ||
}); | ||
|
||
it('Accepts deprecated object notation for styles', function(done) { | ||
var oldStyleMockData = [{ | ||
mode: 'markers', | ||
x: [1, -1, -2, 0, 1, 2, 3], | ||
y: [1, 2, 3, 1, 2, 3, 1], | ||
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { | ||
a: {marker: {color: 'red'}}, | ||
b: {marker: {color: 'blue'}} | ||
} | ||
}] | ||
}]; | ||
var data = Lib.extendDeep([], oldStyleMockData); | ||
data[0].marker = { size: 20 }; | ||
|
||
var gd = createGraphDiv(); | ||
var dims = [4, 3]; | ||
|
||
Plotly.plot(gd, data).then(function() { | ||
assertStyle(dims, | ||
['rgb(255, 0, 0)', 'rgb(0, 0, 255)'], | ||
[1, 1] | ||
); | ||
|
||
return Plotly.restyle(gd, 'marker.opacity', 0.4); | ||
}).then(function() { | ||
assertStyle(dims, | ||
['rgb(255, 0, 0)', 'rgb(0, 0, 255)'], | ||
[0.4, 0.4] | ||
); | ||
|
||
expect(gd._fullData[0].marker.opacity).toEqual(0.4); | ||
expect(gd._fullData[1].marker.opacity).toEqual(0.4); | ||
|
||
return Plotly.restyle(gd, 'marker.opacity', 1); | ||
}).then(function() { | ||
assertStyle(dims, | ||
['rgb(255, 0, 0)', 'rgb(0, 0, 255)'], | ||
[1, 1] | ||
); | ||
|
||
expect(gd._fullData[0].marker.opacity).toEqual(1); | ||
expect(gd._fullData[1].marker.opacity).toEqual(1); | ||
}).then(done); | ||
|
||
// The final test for restyle updates using deprecated syntax | ||
// is ommitted since old style syntax is *only* sanitized on | ||
// initial plot, *not* on restyle. | ||
}); | ||
|
||
it('Plotly.restyle should work', function(done) { | ||
var data = Lib.extendDeep([], mockData0); | ||
data[0].marker = { size: 20 }; | ||
|
@@ -92,7 +149,10 @@ describe('groupby', function() { | |
expect(gd._fullData[1].marker.opacity).toEqual(1); | ||
|
||
return Plotly.restyle(gd, { | ||
'transforms[0].style': { a: {marker: {color: 'green'}}, b: {marker: {color: 'red'}} }, | ||
'transforms[0].style': [[ | ||
{target: 'a', value: {marker: {color: 'green'}}}, | ||
{target: 'b', value: {marker: {color: 'red'}}} | ||
]], | ||
'marker.opacity': 0.4 | ||
}); | ||
}).then(function() { | ||
|
@@ -192,7 +252,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'red'}}}, | ||
{target: 'b', value: {marker: {color: 'blue'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
@@ -387,7 +450,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'red'}}}, | ||
{target: 'b', value: {marker: {color: 'blue'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
@@ -401,17 +467,20 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { | ||
a: { | ||
style: [{ | ||
target: 'a', | ||
value: { | ||
marker: { | ||
color: 'orange', | ||
size: 20, | ||
line: { | ||
color: 'red' | ||
} | ||
} | ||
}, | ||
b: { | ||
} | ||
}, { | ||
target: 'b', | ||
value: { | ||
mode: 'markers+lines', // heterogeonos attributes are OK: group 'a' doesn't need to define this | ||
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. not that this is new, but heterogeneous But that makes me wonder: you don't need to supply This has an interesting use case, I think, that wouldn't have worked (at least not nearly as well) the old way: you could have a "highlight" style to do something special to one group you're focusing on, and to focus on a different group you just change Also, there's a case we couldn't have previously: what if two targets are the same? I could imagine wanting to do this in exactly the "focus style" example... you have styles for each group (say, different marker colors) but then there's a different style you want to move between groups... in that case the actual style to apply to a given group would be the composition of all styles targeting the group. Should we support this? Or do something else if you get the same target more than once? 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.
That should be already part of the suite. But yes, we should test that.
I don't see a problem with supporting multiple styles item with the same 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. @alexcjohnson No, you don't need to specify for all. Or to be more precise, you don't need to now if you didn't before. 😄 At the moment, I'm internally transforming the style array into a key-value index that matches the old specification format. So if two are the same, the last in the array will overwrite other instances. I think merging would be an appropriate use case mergeDeepNoArrays. I don't personally find it a particularly compelling use-case, but it's a pretty straightforward change to add support for pretty weird user input. |
||
marker: { | ||
color: 'cyan', | ||
|
@@ -426,7 +495,7 @@ describe('groupby', function() { | |
color: 'purple' | ||
} | ||
} | ||
} | ||
}] | ||
}] | ||
}]; | ||
|
||
|
@@ -447,11 +516,14 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { | ||
a: {marker: {size: 30}}, | ||
style: [{ | ||
target: 'a', | ||
value: {marker: {size: 30}} | ||
}, { | ||
// override general color: | ||
b: {marker: {size: 15, line: {color: 'yellow'}}, line: {color: 'purple'}} | ||
} | ||
target: 'b', | ||
value: {marker: {size: 15, line: {color: 'yellow'}}, line: {color: 'purple'}} | ||
}] | ||
}] | ||
}]; | ||
|
||
|
@@ -464,7 +536,7 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: {/* can be empty, or of partial group id coverage */} | ||
style: [/* can be empty, or of partial group id coverage */] | ||
}] | ||
}]; | ||
|
||
|
@@ -548,7 +620,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
// groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'], | ||
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'red'}}}, | ||
{target: 'b', value: {marker: {color: 'blue'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
@@ -561,7 +636,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: [], | ||
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'red'}}}, | ||
{target: 'b', value: {marker: {color: 'blue'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
@@ -574,7 +652,10 @@ describe('groupby', function() { | |
transforms: [{ | ||
type: 'groupby', | ||
groups: null, | ||
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} } | ||
style: [ | ||
{target: 'a', value: {marker: {color: 'red'}}}, | ||
{target: 'b', value: {marker: {color: 'blue'}}} | ||
] | ||
}] | ||
}]; | ||
|
||
|
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.
@etpinard @alexcjohnson Comparing this to similar cases, I'm not 100% sure what
_isLinkedToArray
does or whether it's needed here. I've omitted it.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.
I should probably let @etpinard handle this but I think you want both
_isLinkedToArray
and_arrayAttrRegexps
- the latter of which won't get used yet but when we extend the array editing stuff I did inrelayout
torestyle
it will be important.see https://github.com/plotly/plotly.js/blob/master/src/components/updatemenus/attributes.js#L17-L52
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.
That was my template, but I had a hard time tracking down exactly what it does. See: registry.js#L100-L105. It seems like since
groupby
has nolayoutAttributes
, this key will have no effect.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.
right, at the moment
_arrayAttrRegexps
doesn't do anything inside traces, it's just a question of if we want to put it in so we don't forget about this when we do get to implementing it. Maybe better not to include it, in case we implement it a different way. I think_isLinkedToArray
matters to plot_schema already though, doesn't it?Uh oh!
There was an error while loading. Please reload this page.
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.
Added
_isLinkedToArray
but did not add_arrayAttrRegexps
, which I think only applies to nested array attributes likeupdatemenus[...].buttons
. Granted this istransforms[...].styles
, but I'm not totally sure where this would need to be added. At the transform level vs. inside styles, perhaps? Glad to add it blindly, but without really knowing how to test it, I think maybe better to omit for now.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.
Maybe we should name this attributes
styles
instead? All (I think)isLinkedToArray
attribute have plural names.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.
Is that an acceptable change for cleanData?
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.
Yes 👍