Resize icons on scale.

This commit is contained in:
Paulo Veiga 2011-09-02 20:05:51 -03:00
parent 001ff2e371
commit b1b0ee0de8
4 changed files with 41 additions and 6 deletions

View File

@ -48,11 +48,12 @@ mindplot.IconGroup = new Class({
seIconSize : function(width, height) { seIconSize : function(width, height) {
this._iconSize = {width:width,height:height}; this._iconSize = {width:width,height:height};
this._group.setCoordSize(width / mindplot.Icon.HEIGHT, height / mindplot.Icon.HEIGHT); this._resize(this._icons.length);
}, },
addIcon : function(icon) { addIcon : function(icon) {
$defined(icon, "icon is not defined"); $defined(icon, "icon is not defined");
icon.getImage().setVisibility(false);
icon.setGroup(this); icon.setGroup(this);
this._icons.push(icon); this._icons.push(icon);
@ -66,6 +67,8 @@ mindplot.IconGroup = new Class({
// Register event for the group .. // Register event for the group ..
this._removeTip.decorate(this._topicId, icon); this._removeTip.decorate(this._topicId, icon);
icon.getImage().setVisibility(true);
}, },
_findIconFromUrl : function(url) { _findIconFromUrl : function(url) {

View File

@ -254,7 +254,7 @@ mindplot.Topic = new Class({
}, },
_buildIconGroup : function() { _buildIconGroup : function() {
var textHeight = this.getTextShape().getHeight(); var textHeight = this.getTextShape().getFontHeight();
var result = new mindplot.IconGroup(this.getId(), textHeight); var result = new mindplot.IconGroup(this.getId(), textHeight);
var padding = this._getInnerPadding(); var padding = this._getInnerPadding();
result.setPosition(padding, padding); result.setPosition(padding, padding);
@ -426,8 +426,10 @@ mindplot.Topic = new Class({
}, },
setFontSize : function(value, updateModel) { setFontSize : function(value, updateModel) {
var textShape = this.getTextShape(); var textShape = this.getTextShape();
textShape.setSize(value); textShape.setSize(value);
if ($defined(updateModel) && updateModel) { if ($defined(updateModel) && updateModel) {
var model = this.getModel(); var model = this.getModel();
model.setFontSize(value); model.setFontSize(value);
@ -1142,10 +1144,17 @@ mindplot.Topic = new Class({
var textHeight = textShape.getHeight(); var textHeight = textShape.getHeight();
var topicPadding = this._getInnerPadding(); var topicPadding = this._getInnerPadding();
// Adjust the icon size to the size of the text ...
var iconGroup = this.getOrBuildIconGroup(); var iconGroup = this.getOrBuildIconGroup();
var fontHeight = this.getTextShape().getFontHeight();
iconGroup.setPosition(topicPadding, topicPadding);
iconGroup.seIconSize(fontHeight, fontHeight);
// Add a extra padding between the text and the icons
var iconsWidth = iconGroup.getSize().width; var iconsWidth = iconGroup.getSize().width;
if (iconsWidth != 0) { if (iconsWidth != 0) {
// Add a extra padding between the text and the icons
iconsWidth = iconsWidth + (textHeight / 4); iconsWidth = iconsWidth + (textHeight / 4);
} }

View File

@ -31,9 +31,8 @@ web2d.Text = new Class({
this._peer.setText(text); this._peer.setText(text);
}, },
setTextAlignment : function(align) setTextAlignment : function(align) {
{ $assert(align, "align can not be null");
$assert(align,"align can not be null");
this._peer.setTextAlignment(align); this._peer.setTextAlignment(align);
}, },
@ -87,5 +86,10 @@ web2d.Text = new Class({
getHeight : function() { getHeight : function() {
return parseInt(this._peer.getHeight()); return parseInt(this._peer.getHeight());
},
getFontHeight : function() {
var lines = this._peer.getText().split('\n').length;
return Math.round(this.getHeight() / lines);
} }
}); });

View File

@ -32,6 +32,10 @@ web2d.peer.svg.GroupPeer = new Class({
var change = this._coordSize.width != width || this._coordSize.height != height; var change = this._coordSize.width != width || this._coordSize.height != height;
this._coordSize.width = width; this._coordSize.width = width;
this._coordSize.height = height; this._coordSize.height = height;
console.log("coordSize.width:" + width);
console.log("coordSize.height:" + height);
if (change) if (change)
this.updateTransform(); this.updateTransform();
web2d.peer.utils.EventUtils.broadcastChangeEvent(this, "strokeStyle"); web2d.peer.utils.EventUtils.broadcastChangeEvent(this, "strokeStyle");
@ -69,6 +73,21 @@ web2d.peer.svg.GroupPeer = new Class({
var cx = this._position.x - this._coordOrigin.x * sx; var cx = this._position.x - this._coordOrigin.x * sx;
var cy = this._position.y - this._coordOrigin.y * sy; var cy = this._position.y - this._coordOrigin.y * sy;
console.log("------------------");
console.log("this._coordSize.width:" + this._coordSize.width);
console.log("this._coordSize.height:" + this._coordSize.height);
console.log("cx:" + cx);
console.log("cy:" + cy);
console.log("this._size.width:" + this._size.width);
console.log("this._size.height:" + this._size.height);
console.log("sx:" + sx);
console.log("sy:" + sy);
console.log("------------------");
this._native.setAttribute("transform", "translate(" + cx + "," + cy + ") scale(" + sx + "," + sy + ")"); this._native.setAttribute("transform", "translate(" + cx + "," + cy + ") scale(" + sx + "," + sy + ")");
}, },