Skip to content

Commit 68c5be4

Browse files
authored
fix(dia.Paper): ensure grid pattern ids are unique (#2654)
1 parent 00a6756 commit 68c5be4

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

packages/joint-core/src/dia/layers/GridLayer.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const GridLayer = PaperLayer.extend({
6767

6868
gridSettings.forEach((gridLayerSetting, index) => {
6969

70-
const id = 'pattern_' + index;
70+
const id = this._getPatternId(index);
7171
const options = merge({}, gridLayerSetting);
7272
const { scaleFactor = 1 } = options;
7373
options.width = gridSize * scaleFactor || 1;
@@ -107,12 +107,16 @@ export const GridLayer = PaperLayer.extend({
107107
}
108108
gridSettings.forEach((options, index) => {
109109
if (isFunction(options.update)) {
110-
const vPattern = patterns['pattern_' + index];
110+
const vPattern = patterns[this._getPatternId(index)];
111111
options.update(vPattern.node.firstChild, options, paper);
112112
}
113113
});
114114
},
115115

116+
_getPatternId(index) {
117+
return `pattern_${this.options.paper.cid}_${index}`;
118+
},
119+
116120
_getGridRefs() {
117121
let { _gridCache: grid } = this;
118122
if (grid) return grid;

packages/joint-core/test/jointjs/paper.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,32 @@ QUnit.module('paper', function(hooks) {
13651365
return paper;
13661366
};
13671367

1368+
QUnit.test('Unique pattern id', function(assert) {
1369+
1370+
const paper1 = new joint.dia.Paper({
1371+
drawGrid: true,
1372+
gridSize: 10
1373+
});
1374+
1375+
const paper2 = new joint.dia.Paper({
1376+
drawGrid: true,
1377+
gridSize: 10
1378+
});
1379+
1380+
const svg1 = getGridVel(paper1);
1381+
const pattern1 = svg1.findOne('pattern');
1382+
assert.ok(pattern1.id);
1383+
1384+
const svg2 = getGridVel(paper2);
1385+
const pattern2 = svg2.findOne('pattern');
1386+
assert.ok(pattern2.id);
1387+
1388+
assert.notEqual(pattern1.id, pattern2.id);
1389+
1390+
paper1.remove();
1391+
paper2.remove();
1392+
});
1393+
13681394
QUnit.module('drawGridSize option', function(hooks) {
13691395

13701396
QUnit.test('is used to draw grid', function(assert) {

0 commit comments

Comments
 (0)