Hi all,
I needed a modification on Y axis labels to display a friendly
bitrate, here is a patch that allow you to add a function as parameter
to format the label.
Could help someone else.
Also, it could be interesting to include the labels inside the canvas,
so we could export the image (in Firefox, right click and show image,
doesn't displays the labels).
Used like :
var valueGeometry = new Timeplot.DefaultValueGeometry({
gridColor: "#000000",
labelFormat: function(label){
if( label > 1000000000 )
{
return (label / 1000000000) + " Gbps";
}
if( label > 1000000 )
{
return (label / 1000000) + " Mbps";
}
if( label > 1000 )
{
return (label / 1000) + " Kbps";
}
return label+" bps";
},
});
Regards,
Jon.
Here is the patch :
--- scripts/geometry.js (révision 2100)
+++ scripts/geometry.js (copie de travail)
@@ -28,6 +28,7 @@
this._gridShortSize = ("gridShortSize" in params) ?
params.gridShortSize : 10;
this._minValue = ("min" in params) ? params.min : null;
this._maxValue = ("max" in params) ? params.max : null;
+ this._labelFormat = ("labelFormat" in params) ?
params.labelFormat : function(label){return label;};
this._linMap = {
direct: function(v) {
return v;
@@ -246,7 +247,7 @@
if (this._minValue >= 0) {
while (y < this._canvas.height) {
if (y > 0) {
- grid.push({ y: y, label: v });
+ grid.push({ y: y, label: this._labelFormat(v) });
}
v += inc;
y = this.toScreen(v);
@@ -254,7 +255,7 @@
} else if (this._maxValue <= 0) {
while (y > 0) {
if (y < this._canvas.height) {
- grid.push({ y: y, label: v });
+ grid.push({ y: y, label: this._labelFormat(v) });
}
v -= inc;
y = this.toScreen(v);
@@ -262,7 +263,7 @@
} else {
while (y < this._canvas.height) {
if (y > 0) {
- grid.push({ y: y, label: v });
+ grid.push({ y: y, label: this._labelFormat(v) });
}
v += inc;
y = this.toScreen(v);
@@ -271,7 +272,7 @@
y = this.toScreen(v);
while (y > 0) {
if (y < this._canvas.height) {
- grid.push({ y: y, label: v });
+ grid.push({ y: y, label: this._labelFormat(v) });
}
v -= inc;
y = this.toScreen(v);
--
You received this message because you are subscribed to the Google Groups
"SIMILE Widgets" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simile-widgets?hl=en.