-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid-snapping): integrate space tool
Related to camunda/camunda-modeler#1344 Related to camunda/camunda-modeler#1348
- Loading branch information
1 parent
cd74f22
commit b762015
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var HIGH_PRIORITY = 2000; | ||
|
||
/** | ||
* Integrates space tool with grid snapping. | ||
*/ | ||
export default function SpaceToolBehavior(eventBus, gridSnapping) { | ||
eventBus.on([ | ||
'spaceTool.move', | ||
'spaceTool.end' | ||
], HIGH_PRIORITY, function(event) { | ||
var context = event.context; | ||
|
||
if (!context.initialized) { | ||
return; | ||
} | ||
|
||
var axis = context.axis; | ||
|
||
if (axis === 'x') { | ||
|
||
// snap delta x to multiple of 10 | ||
event.dx = gridSnapping.snapValue(event.dx); | ||
} else { | ||
|
||
// snap delta y to multiple of 10 | ||
event.dy = gridSnapping.snapValue(event.dy); | ||
} | ||
}); | ||
} | ||
|
||
SpaceToolBehavior.$inject = [ | ||
'eventBus', | ||
'gridSnapping' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import GridSnapping from '../GridSnapping'; | ||
|
||
import ResizeBehavior from './ResizeBehavior'; | ||
import SpaceToolBehavior from './SpaceToolBehavior'; | ||
|
||
export default { | ||
__depends__: [ | ||
GridSnapping | ||
], | ||
__init__: [ | ||
'gridSnappingResizeBehavior' | ||
'gridSnappingResizeBehavior', | ||
'gridSnappingSpaceToolBehavior' | ||
], | ||
gridSnappingResizeBehavior: [ 'type', ResizeBehavior ] | ||
gridSnappingResizeBehavior: [ 'type', ResizeBehavior ], | ||
gridSnappingSpaceToolBehavior: [ 'type', SpaceToolBehavior ] | ||
}; |
55 changes: 55 additions & 0 deletions
55
test/spec/features/grid-snapping/behavior/SpaceToolBehaviorSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
bootstrapDiagram, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import gridSnappingModule from 'lib/features/grid-snapping'; | ||
import modelingModule from 'lib/features/modeling'; | ||
import moveModule from 'lib/features/move'; | ||
import spaceToolModule from 'lib/features/space-tool'; | ||
|
||
import { | ||
createCanvasEvent as canvasEvent | ||
} from '../../../../util/MockEvents'; | ||
|
||
|
||
describe('features/grid-snapping - space tool', function() { | ||
|
||
var shape; | ||
|
||
beforeEach(bootstrapDiagram({ | ||
modules: [ | ||
gridSnappingModule, | ||
modelingModule, | ||
moveModule, | ||
spaceToolModule | ||
] | ||
})); | ||
|
||
beforeEach(inject(function(canvas, elementFactory) { | ||
|
||
shape = elementFactory.createShape({ | ||
id: 'shape', | ||
x: 100, y: 100, | ||
width: 100, height: 100 | ||
}); | ||
|
||
canvas.addShape(shape); | ||
})); | ||
|
||
|
||
it('should snap make space', inject(function(spaceTool, dragging) { | ||
|
||
// when | ||
spaceTool.activateMakeSpace(canvasEvent({ x: 90, y: 100 })); | ||
|
||
dragging.move(canvasEvent({ x: 110, y: 100 })); | ||
|
||
dragging.end(); | ||
|
||
// then | ||
expect(shape.x).to.eql(120); | ||
expect(shape.y).to.eql(100); | ||
})); | ||
|
||
}); |