-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
6,378 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { mix } from '../../util/common'; | ||
import Context from './context'; | ||
|
||
class Base { | ||
type = ''; | ||
startEvent = 'touchstart'; | ||
processEvent = 'touchmove'; | ||
endEvent = 'touchend'; | ||
resetEvent = null; | ||
// 交互的上下文 | ||
context = null; | ||
|
||
getDefaultCfg() { | ||
return {}; | ||
} | ||
|
||
getInteractionContext(chart) { | ||
let interactionContext = chart.get('interactionContext'); | ||
if (interactionContext) { | ||
return interactionContext; | ||
} | ||
interactionContext = new Context(chart); | ||
chart.set('interactionContext', interactionContext); | ||
return interactionContext; | ||
} | ||
|
||
constructor(cfg, chart) { | ||
mix(this, this.getDefaultCfg(), cfg); | ||
this.context = this.getInteractionContext(chart); | ||
this.chart = chart; | ||
this._bindEvents(chart); | ||
} | ||
|
||
_bindEvents(chart) { | ||
const { startEvent, processEvent, endEvent, resetEvent } = this; | ||
const canvas = chart.get('canvas'); | ||
// 统一绑定事件 | ||
canvas.on(startEvent, this._start); | ||
canvas.on(processEvent, this._process); | ||
canvas.on(endEvent, this._end); | ||
canvas.on(resetEvent, this._reset); | ||
} | ||
|
||
_clearEvents() { | ||
const { chart, startEvent, processEvent, endEvent, resetEvent } = this; | ||
const canvas = chart.get('canvas'); | ||
|
||
// 统一绑定事件 | ||
canvas.off(startEvent, this._start); | ||
canvas.off(processEvent, this._process); | ||
canvas.off(endEvent, this._end); | ||
canvas.off(resetEvent, this._start); | ||
} | ||
|
||
_start = ev => { | ||
this.start(ev); | ||
} | ||
_process = ev => { | ||
this.process(ev); | ||
} | ||
_end = ev => { | ||
this.end(ev); | ||
} | ||
_reset = ev => { | ||
this.reset(ev); | ||
} | ||
|
||
// override | ||
start() {} | ||
// override | ||
process() {} | ||
// override | ||
end() {} | ||
// override | ||
reset() {} | ||
|
||
destroy() { | ||
this._clearEvents(); | ||
} | ||
} | ||
|
||
export default Base; |
Oops, something went wrong.