File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ export const GridLayer = PaperLayer.extend({
67
67
68
68
gridSettings . forEach ( ( gridLayerSetting , index ) => {
69
69
70
- const id = 'pattern_' + index ;
70
+ const id = this . _getPatternId ( index ) ;
71
71
const options = merge ( { } , gridLayerSetting ) ;
72
72
const { scaleFactor = 1 } = options ;
73
73
options . width = gridSize * scaleFactor || 1 ;
@@ -107,12 +107,16 @@ export const GridLayer = PaperLayer.extend({
107
107
}
108
108
gridSettings . forEach ( ( options , index ) => {
109
109
if ( isFunction ( options . update ) ) {
110
- const vPattern = patterns [ 'pattern_' + index ] ;
110
+ const vPattern = patterns [ this . _getPatternId ( index ) ] ;
111
111
options . update ( vPattern . node . firstChild , options , paper ) ;
112
112
}
113
113
} ) ;
114
114
} ,
115
115
116
+ _getPatternId ( index ) {
117
+ return `pattern_${ this . options . paper . cid } _${ index } ` ;
118
+ } ,
119
+
116
120
_getGridRefs ( ) {
117
121
let { _gridCache : grid } = this ;
118
122
if ( grid ) return grid ;
Original file line number Diff line number Diff line change @@ -1365,6 +1365,32 @@ QUnit.module('paper', function(hooks) {
1365
1365
return paper ;
1366
1366
} ;
1367
1367
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
+
1368
1394
QUnit . module ( 'drawGridSize option' , function ( hooks ) {
1369
1395
1370
1396
QUnit . test ( 'is used to draw grid' , function ( assert ) {
You can’t perform that action at this time.
0 commit comments