[canviz] r478 committed - text Y-coordinate offset and gradient Y-coordinate inversion bugs have...

1 view
Skip to first unread message

can...@googlecode.com

unread,
Sep 6, 2013, 9:19:53 PM9/6/13
to canviz-...@googlegroups.com
Revision: 478
Author: ryandesign.com
Date: Sat Sep 7 01:19:33 2013 UTC
Log: text Y-coordinate offset and gradient Y-coordinate inversion bugs
have been fixed in xdotversion 1.5; rename some variables to better
indicate their purpose

http://code.google.com/p/canviz/source/detail?r=478

Modified:
/canviz/trunk/src/Canviz.js
/canviz/trunk/src/Entity.js

=======================================
--- /canviz/trunk/src/Canviz.js Mon Aug 26 21:10:36 2013 UTC
+++ /canviz/trunk/src/Canviz.js Sat Sep 7 01:19:33 2013 UTC
@@ -61,7 +61,7 @@
};

// Constants
-var MAX_XDOT_VERSION = '1.4';
+var MAX_XDOT_VERSION = '1.5';
// An alphanumeric string or a number or a double-quoted string or an HTML
string
var ID_MATCH = '([a-zA-Z\u0080-\uFFFF_][0-9a-zA-Z\u0080-\uFFFF_]*|
-?(?:\\.\\d+|\\d+(?:\\.\\d*)?)|"(?:\\\\"|[^"])*"|<(?:<[^>]*>|[^<>]+?)+>)';
// ID or ID:port or ID:compassPoint or ID:port:compassPoint
@@ -229,7 +229,7 @@
break;
case 'size':
if (attrValue.substr(attrValue.length - 1) == '!') {
- this.bbEnlarge = true;
+ this.bbEnlarge = 1; // true
attrValue = attrValue.substr(0, attrValue.length -
1);
}
attrValue = attrValue.split(',');
@@ -237,8 +237,8 @@
this.maxHeight = XDOT_DPI *
attrValue[attrValue.length - 1];
break;
case 'xdotversion':
- if (0 > versionCompare(MAX_XDOT_VERSION,
attrHash.xdotversion)) {
- debug('unsupported xdotversion ' +
attrHash.xdotversion + '; this script currently supports up to
xdotversion ' + MAX_XDOT_VERSION);
+ if (versionCompare(attrValue, MAX_XDOT_VERSION) > 0)
{
+ debug('unsupported xdotversion ' + attrValue + ';
this script currently supports up to xdotversion ' + MAX_XDOT_VERSION);
}
break;
}
@@ -260,6 +260,9 @@
},
draw: function (redrawCanvasOnly) {
if (typeof redrawCanvasOnly == 'undefined') redrawCanvasOnly = false;
+ var bugs = this.bugs = {};
+ var xdotVersion = this.graphs[0].attrs.xdotversion;
+ bugs.gradY = bugs.textY = versionCompare(xdotVersion, '1.5') < 0;
var ctx = this.ctx;
var ctxScale = this.scale * this.dpi / XDOT_DPI;
var bbScaledDrawingWidth = this.bbScale * (this.width + 2 *
this.paddingX);
=======================================
--- /canviz/trunk/src/Entity.js Thu Sep 5 03:26:37 2013 UTC
+++ /canviz/trunk/src/Entity.js Sat Sep 7 01:19:33 2013 UTC
@@ -140,39 +140,41 @@
ctx.restore();
break;
case 'T': // text
- var left = tokenizer.takeNumber(),
- bottom = tokenizer.takeNumber(),
+ var x = tokenizer.takeNumber(),
+ baseline = tokenizer.takeNumber(),
textAlignIndex = 1 + tokenizer.takeNumber(),
textAlign = TEXT_ALIGNMENTS[textAlignIndex],
textWidth = tokenizer.takeNumber(),
str = tokenizer.takeString();

if (!/^\s*$/.test(str)) {
- // The Y-coordinate of text operations in xdot neglects to
take
+ // Prior to xdotversion 1.5 (Graphviz version
2.33.20130906.0446,
+ // git commit 5059989a0e35c3423da5b870480748569c61fb4a) the
+ // Y-coordinate of text operations in xdot neglects to take
// into account the yoffset_centerline. The error
for "simple"
- // strings is -0.2 * fontSize and -1 for complex ones;
+ // strings is 0.2 * fontSize and 1 for complex ones;
// unfortunately xdot does not tell us whether a string is
// simple or complex. We adjust for the more common simple
// case, though this causes complex strings to look worse.
// http://www.graphviz.org/mantisbt/view.php?id=2333
- var yError = -0.2 * fontSize;
+ var yError = this.canviz.bugs.textY * 0.2 * fontSize;
switch (this.canviz.textMode) {
case 'canvas':
ctx.save();
- ctx.translate(left - textAlignIndex * textWidth / 2,
bottom);
+ ctx.translate(x - textAlignIndex * textWidth / 2,
baseline);
// Uninvert the coordinate system so the text isn't
drawn upside down.
if (this.canviz.invertY) ctx.scale(1, -1);
ctx.font = fontSize + 'px ' + fontFamily;
// xdot uses pen color for text, but canvas uses fill
color
ctx.fillStyle = ctx.strokeStyle;
- ctx.fillText(str, 0, yError);
+ ctx.fillText(str, 0, -yError);
ctx.restore();
break;
case 'dom':
if (!redrawCanvasOnly) {
str = escapeHtml(str).replace(/ /g, '&nbsp;');
- left = this.canviz.marginX + bbScale *
(this.canviz.paddingX + left - textAlignIndex * textWidth);
- var top = this.canviz.marginY + bbScale *
(this.canviz.paddingY + (this.canviz.invertY ? this.canviz.height -
bottom : bottom) - fontSize);
+ var left = this.canviz.marginX + bbScale *
(this.canviz.paddingX + x - textAlignIndex * textWidth);
+ var top = this.canviz.marginY + bbScale *
(this.canviz.paddingY + (this.canviz.invertY ? this.canviz.height -
baseline : baseline) - fontSize);
var text;
var href = this.getAttr('URL', true) ||
this.getAttr('href', true);
if (href) {
@@ -294,7 +296,11 @@
if (radial) r0 = tokenizer.takeNumber();
x1 = tokenizer.takeNumber();
y1 = tokenizer.takeNumber();
- if (1) { // http://www.graphviz.org/mantisbt/view.php?id=2336
+ if (this.canviz.bugs.gradY) {
+ // Prior to xdotversion 1.5 (Graphviz version 2.33.20130907.0446,
git
+ // commit 7baedbfdd2607942bd74cc22fe6130aceb5dc0fc) the gradient
+ // Y-coordinate is inadvertently mirrored across the bottom edge
of the
+ // graph. http://graphviz.org/mantisbt/view.php?id=2336
if (this.canviz.invertY) {
y0 *= -1;
y1 *= -1;
Reply all
Reply to author
Forward
0 new messages