View Full Version : Draw component auto scaling

1 Nov 2011, 12:27 PM
I have a draw component that I update ever time I poll my server. It seems to scale to the first image I draw, but if the updated image is bigger or smaller, it still scales to the size of the first image.

I am graphing network connections, so the drawing size can change with every update.

Is there an event or a function I need to call after updating the Ext.draw.Component or the surface to get it to update it's scale?


1 Nov 2011, 12:35 PM
I create the draw component with an initial place-holder box:

draw = Ext.create('Ext.draw.Component', {
id: "MainDraw",
viewBox: true,
items: [ {
type: 'rect',
zIndex : -2,
stroke : "#FF0000",
fill : "#0000FF",
x: 0,
y: 0,
width: 2000,
height: 1000

window.add (draw);

Then in my polling callback I do:

var surface = Ext.getCmp('MainDraw').surface;
surface.removeAll (true);
var sprite = Ext.create('Ext.draw.Sprite',
surface: surface,
type: 'rect',
zIndex : -2,
stroke : "#FF0000",
fill : "#0000FF",
x: 200,
y: 200,
width: 50,
height: 50
sprite.show (true);

but the new rect is not scaled to fill the available area like the original one was. It is scaled as if the orginal rec were still part of the drawing.

2 Nov 2011, 10:20 AM
I was able to get it to work by calling the undocumented:

surface.setViewBox(0, 0, width, height);

It seems like a bug to me that this is not done automatically when viewBox is true.