Skip to content

Commit e47e6a9

Browse files
committed
_compareAsJSON for groupby styles
1 parent f439e41 commit e47e6a9

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/plot_api/plot_api.js

+2
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,8 @@ function getDiffFlags(oldContainer, newContainer, outerparts, opts) {
24932493
// in case type changed, we may not even *have* a valObject.
24942494
if(!valObject) continue;
24952495

2496+
if(valObject._compareAsJSON && JSON.stringify(oldVal) === JSON.stringify(newVal)) continue;
2497+
24962498
var valType = valObject.valType;
24972499
var i;
24982500

src/transforms/groupby.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ exports.attributes = {
7373
'For example, with `groups` set to *[\'a\', \'b\', \'a\', \'b\']*',
7474
'and `styles` set to *[{target: \'a\', value: { marker: { color: \'red\' } }}]',
7575
'marker points in group *\'a\'* will be drawn in red.'
76-
].join(' ')
76+
].join(' '),
77+
_compareAsJSON: true
7778
},
7879
editType: 'calc'
7980
},
@@ -115,9 +116,15 @@ exports.supplyDefaults = function(transformIn, traceOut, layout) {
115116

116117
if(styleIn) {
117118
for(i = 0; i < styleIn.length; i++) {
118-
styleOut[i] = {};
119+
var thisStyle = styleOut[i] = {};
119120
Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'target');
120-
Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'value');
121+
var value = Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'value');
122+
123+
// so that you can edit value in place and have Plotly.react notice it, or
124+
// rebuild it every time and have Plotly.react NOT think it changed:
125+
// use _compareAsJSON to say we should diff the _JSON_value
126+
if(Lib.isPlainObject(value)) thisStyle.value = Lib.extendDeep({}, value);
127+
else if(value) delete thisStyle.value;
121128
}
122129
}
123130

test/jasmine/tests/plotschema_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('plot schema', function() {
115115
var valObject = valObjects[attr.valType],
116116
opts = valObject.requiredOpts
117117
.concat(valObject.otherOpts)
118-
.concat(['valType', 'description', 'role', 'editType', 'impliedEdits']);
118+
.concat(['valType', 'description', 'role', 'editType', 'impliedEdits', '_compareAsJSON']);
119119

120120
Object.keys(attr).forEach(function(key) {
121121
expect(opts.indexOf(key) !== -1).toBe(true, key, attr);

0 commit comments

Comments
 (0)