UNPKG

@antv/g6

Version:

graph visualization frame work

48 lines (42 loc) 1.07 kB
var DELTA = 0.05; module.exports = { getDefaultCfg: function getDefaultCfg() { return { sensitivity: 2, minZoom: 0.1, maxZoom: 10 }; }, getEvents: function getEvents() { return { wheel: 'onWheel' }; }, onWheel: function onWheel(e) { e.preventDefault(); if (!this.shouldUpdate.call(this, e)) { return; } var graph = this.graph; var canvas = graph.get('canvas'); var point = canvas.getPointByClient(e.clientX, e.clientY); var pixelRatio = canvas.get('pixelRatio'); var sensitivity = this.get('sensitivity'); var ratio = graph.getZoom(); // 兼容IE、Firefox及Chrome if (e.wheelDelta < 0) { ratio = 1 - DELTA * sensitivity; } else { ratio = 1 + DELTA * sensitivity; } var zoom = ratio * graph.getZoom(); if (zoom > this.get('maxZoom') || zoom < this.get('minZoom')) { return; } graph.zoom(ratio, { x: point.x / pixelRatio, y: point.y / pixelRatio }); graph.paint(); graph.emit('wheelzoom', e); } };