-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #320 from antvis/fix-issue-319
feat(g-base): add getCursor() and setCursor(cursor) method for Canvas
- Loading branch information
Showing
7 changed files
with
172 additions
and
3 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
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
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
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
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
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
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,63 @@ | ||
const expect = require('chai').expect; | ||
import Canvas from '../../src/canvas'; | ||
import { simulateMouseEvent, getClientPoint } from '../util'; | ||
|
||
const dom = document.createElement('div'); | ||
document.body.appendChild(dom); | ||
dom.id = 'c1'; | ||
dom.style.border = '1px solid black'; | ||
dom.style.width = '600px'; | ||
dom.style.height = '600px'; | ||
|
||
describe('#319', () => { | ||
const canvas = new Canvas({ | ||
container: dom, | ||
width: 600, | ||
height: 600, | ||
// cursor: 'default', | ||
}); | ||
const el = canvas.get('el'); | ||
|
||
it('getCursor and setCursor for canvas should work', () => { | ||
canvas.addShape('circle', { | ||
attrs: { | ||
x: 100, | ||
y: 100, | ||
r: 50, | ||
fill: 'red', | ||
cursor: 'pointer', | ||
}, | ||
}); | ||
canvas.addShape('circle', { | ||
attrs: { | ||
x: 180, | ||
y: 100, | ||
r: 50, | ||
fill: 'blue', | ||
cursor: 'move', | ||
}, | ||
}); | ||
expect(canvas.getCursor()).eqls('default'); | ||
expect(canvas.setCursor('crosshair')); | ||
expect(canvas.getCursor()).eqls('crosshair'); | ||
// circle1 | ||
const { clientX, clientY } = getClientPoint(canvas, 100, 100); | ||
simulateMouseEvent(el, 'mousemove', { | ||
clientX, | ||
clientY, | ||
}); | ||
expect(el.style.cursor).eqls('pointer'); | ||
// circle2 | ||
simulateMouseEvent(el, 'mousemove', { | ||
clientX: clientX + 80, | ||
clientY, | ||
}); | ||
expect(el.style.cursor).eqls('move'); | ||
// canvas | ||
simulateMouseEvent(el, 'mousemove', { | ||
clientX: clientX + 200, | ||
clientY, | ||
}); | ||
expect(el.style.cursor).eqls('crosshair'); | ||
}); | ||
}); |