Label background

1 view
Skip to first unread message

martin.berg

unread,
Aug 24, 2009, 8:01:47 AM8/24/09
to juicekit
Hi,

I've been trying to set the label background so that the labels a
better highlighted, even tried to modify the lib
but could not get it to work.

Is it possible to set the label background without modifying the lib
or how in sudo code would you modify it to add this, even hardcode it.

??
Thannks

Some code(I wrote a custom renderer 'extends ShapeRenderer for this

class CustRenderer extends ShapeRenderer {
private var hColor:uint;
private var hLimit:uint;
private var hField:String;
private var depth:uint;

private static var array:Array;
private static var lList:ArrayCollection;

array = new Array(20);
lList = new ArrayCollection(array);

public function CustRenderer(defaultSize:Number = 6, hColor:uint =
0xFF0000, hLimit:uint = 0, hField:String = "PercentOpened", depth:uint
= 0) {
super(defaultSize);
this.hColor = hColor;
this.hLimit = hLimit;
this.hField = hField;
this.depth = depth;
}

override public function render(d:DataSprite):void {
var lineAlpha:Number = d.lineAlpha;
var fillAlpha:Number = d.fillAlpha;
var size:Number = d.size * defaultSize;
var g:Graphics = d.graphics;
g.clear();

var label:TextSprite = d.props["#label#"];
if (fillAlpha > 0) g.beginFill(d.fillColor, fillAlpha);
if (lineAlpha > 0) g.lineStyle(d.lineWidth, d.lineColor, lineAlpha);

switch (d.shape) {
case null:
break;
case Shapes.BLOCK: {
//Alert.show(depth.toString(), "-");
/*if(d.parent.hasOwnProperty("#label#") && d.parent.y == d.y){
Alert.show("?", "?");
g.drawRect(d.u-d.x, d.u-d.x + 14, d.w, d.h - 14);
}else
g.drawRect(d.u-d.x, d.v-d.y, d.w, d.h);*/
if(label == null || label.text.length == 0) {
//if(lList.contains(d.y.toString() + "-" + (depth -1).toString
()))
//if(lList.contains((d.v-d.y).toString() + "-" + depth.toString
()))
//if(d.h > 14)
var colides:int = 1;
for(var i:int = 0; i < lList.length; i++) {
var po:PanelObject = lList[i];
if(po != null && d.y == po.y && po.d == (this.depth - 1))
colides = 2;
}
if(colides == 2 && d.h > 14)
g.drawRect(d.u-d.x, d.v-d.y + 14, d.w, d.h - 14);
else
g.drawRect(d.u-d.x, d.v-d.y, d.w, d.h);
} else {
colides = 1;
for(var i:int = 0; i < lList.length; i++) {
var po:PanelObject = lList[i];

if(po != null && d.y == po.y && po.d == this.depth) {
//Alert.show("" +po.y.toString(), "1");
colides = 2;
}

}
if(colides == 1)
lList.addItem(new PanelObject(d.x ,d.y, d.w, this.depth));
//Alert.show((d.v-d.y).toString() + "-" + depth.toString
());
//}
g.drawRect(d.u-d.x, d.v-d.y, d.w, d.h);
}
break;
} case Shapes.POLYGON:
if (d.points!=null)
Shapes.drawPolygon(g, d.points);
break;
case Shapes.POLYBLOB:
if (d.points!=null)
Shapes.drawCardinal(g, d.points,
d.points.length/2, 0.15, true);
break;
case Shapes.VERTICAL_BAR:
g.drawRect(-size/2, -d.h, size, d.h);
break;
case Shapes.HORIZONTAL_BAR:
g.drawRect(-d.w, -size/2, d.w, size);
break;
case Shapes.WEDGE:
Shapes.drawWedge(g, d.origin.x-d.x, d.origin.y-d.y, d.h, d.v, d.u,
d.u+d.w);
break;
default:
Shapes.getShape(d.shape)(g, size);
}

if (fillAlpha > 0) g.endFill();

// Highlight
var num:Number = int(d.data[hField]);
if(num <= hLimit) {
g.beginFill(hColor, 1);
g.drawRect(d.u-d.x, d.v-d.y, d.w, d.h);
g.endFill();
}

if(label != null && label.text.length > 0 ) {
//Alert.show(label.text, "-");
g.beginFill(0xFFFF00, 1);
g.drawRect(d.u-d.x, d.v-d.y, d.w, 14);
g.endFill();
} else {
//g.beginFill(0xFF00FF, 1);
//g.drawRect(d.u-d.x, d.v-d.y -14, d.w, 14);
//g.endFill();
}
// Paint label background
//if(label == null) {
//g.beginFill(0xFFFFFF, 1);
//g.drawRect(d.u-d.x, d.v-d.y, d.w, 14);
//g.endFill();
//}
}
}
class PanelObject {
var x:int;
var y:int;
var w:int;
var d:uint;
public function PanelObject(x:int, y:int, w:int, d:uint) {
this.d = d;
this.x = x;
this.y = y;
this.w = w;
}
}

Unfortunately it does not do it correctly

martin.berg

unread,
Aug 24, 2009, 8:05:30 AM8/24/09
to juicekit
The problem is that the labels on lower levels overwrite the label
background on higher levels

Chris Gemignani

unread,
Aug 24, 2009, 2:44:11 PM8/24/09
to juic...@googlegroups.com
Hi Martin:

We're planning to release an update to JuiceKit in the next few days that may resolve your problem.  You can get it at http://github.com/chrisgemignani/juicekit/tree/juicekit-1.2RC1. One feature we've added to the TreeMap is an adaptive color strategy (labelColorStrategy) for the labels that colors them black or white to achieve maximum contrast with the background color.

labelColorStrategy
Type: String   CSS Inheritance: no
Possible labelColorStrategy values are: blackwhite adaptively choose black or white depending on the background color, glow apply a white glow around letters or none don't apply any effect. Deprecation warning: This default will be changed to blackwhite in JuiceKit 2.0. The default value is "glow".
TreeMapControl
Regards,
Chris
--
Chris Gemignani
Juice Analytics
phone: 571.205.4789
Reply all
Reply to author
Forward
0 new messages