Skip to content

Instantly share code, notes, and snippets.

@tabrindle
Created September 12, 2013 13:42
Show Gist options
  • Save tabrindle/6537572 to your computer and use it in GitHub Desktop.
Save tabrindle/6537572 to your computer and use it in GitHub Desktop.
D3 compatibility file for Sencha
Ext.define('Ext.ux.D3Container', {
alias: 'plugin.D3Container',
constructor: function(config) {
this.initConfig(config);
},
init: function(parent) {
this.D3Container = new Ext.Container({
layout: 'fit'
});
d3.select(this.D3Container.innerElement).append("svg:svg");
parent.add(this.D3Container);
this.D3Container.innerElement.on({
painted: 'onPainted',
touchstart: 'onTouchStart',
touchend: 'onTouchEnd',
touchmove: 'onTouchMove',
scope: this
});
},
onPainted: function(element){
this.clientRect = element.dom.getBoundingClientRect();
},
onTouchStart:function(event) {
var touch = {
x: (event.pageX - this.clientRect.left),
y: (event.pageY - this.clientRect.top)
};
this.D3Container.fireEvent('touchstart', this.D3Container.innerElement, touch);
},
onTouchEnd:function(event) {
var touch = {
x: (event.pageX - this.clientRect.left),
y: (event.pageY - this.clientRect.top)
};
this.D3Container.fireEvent('touchend', this.D3Container.innerElement, touch);
},
onTouchMove:function(event) {
var touch = {
x: (event.pageX - this.clientRect.left),
y: (event.pageY - this.clientRect.top)
};
this.D3Container.fireEvent('touchmove', this.D3Container.innerElement, touch);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment