Skip to content

Commit

Permalink
Rename textAnchor to textAlign.
Browse files Browse the repository at this point in the history
  • Loading branch information
basecode committed Apr 23, 2013
1 parent 5ae05f1 commit 41899bb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example/library/movies/text-metrics.js
Expand Up @@ -26,5 +26,5 @@ drawBox(new Text('bottom right').attr({
drawBox(new Text('center center').attr({
y:260,
textOrigin:'center',
textAnchor:'center'
textAlign:'center'
}));
8 changes: 4 additions & 4 deletions src/renderer/svg/svg.js
Expand Up @@ -90,7 +90,7 @@ define([
'touchstart'
];

var textAnchorMap = {
var textAlignMap = {
left: 'start',
center: 'middle',
right: 'end'
Expand Down Expand Up @@ -656,7 +656,7 @@ define([
var attributes = message.attributes;
var style = text.style;
var textOrigin = attributes.textOrigin;
var textAnchor = attributes.textAnchor;
var textAlign = attributes.textAlign;

if (attributes.selectable !== undefined) {
if (attributes.selectable !== false) {
Expand All @@ -666,8 +666,8 @@ define([
}
}

if (textAnchor != null) {
setStyle(style, 'textAnchor', textAnchorMap[textAnchor]);
if (textAlign != null) {
setStyle(style, 'textAnchor', textAlignMap[textAlign]);
}

if (textOrigin != null) {
Expand Down
16 changes: 8 additions & 8 deletions src/runner/text.js
Expand Up @@ -78,12 +78,12 @@ define([
return text.join('');
}

function getTextAnchor() {
return this._textAnchor;
function getTextAlign() {
return this._textAlign;
}
function setTextAnchor(textAnchor) {
if (/^(left|center|right)$/.test(textAnchor)) {
this._textAnchor = textAnchor;
function setTextAlign(textAlign) {
if (/^(left|center|right)$/.test(textAlign)) {
this._textAlign = textAlign;
}
}

Expand Down Expand Up @@ -127,8 +127,8 @@ define([
fontWeight: data('normal', true, true),
_cap: data('butt', true),
cap: accessor(getCap, setCap, true),
_textAnchor: data('left', true),
textAnchor: accessor(getTextAnchor, setTextAnchor, true),
_textAlign: data('left', true),
textAlign: accessor(getTextAlign, setTextAlign, true),
_textFillColor: data(0x000000ff, true), // transparent by default
textFillColor: accessor(getTextFillColor, setTextFillColor, true),
_textFillGradient: data(null, true),
Expand Down Expand Up @@ -163,7 +163,7 @@ define([
rendererAttributes.miterLimit = '_miterLimit';
rendererAttributes.selectable = 'selectable';
rendererAttributes.textOrigin = 'textOrigin';
rendererAttributes.textAnchor = '_textAnchor';
rendererAttributes.textAlign = '_textAlign';

if (text != null) {
this.attr('text', text);
Expand Down
12 changes: 6 additions & 6 deletions test/renderer/svg-spec.js
Expand Up @@ -173,16 +173,16 @@ define(['bonsai/renderer/svg/svg'], function(SvgRenderer) {
expect(textElement.style.dominantBaseline).toBe('auto');
});

it('sets text-anchor=start when attr.textAnchor=left', function() {
createSvgRenderer().drawText(textElement, { attributes: { textAnchor: 'left' } });
it('sets text-anchor=start when attr.textAlign=left', function() {
createSvgRenderer().drawText(textElement, { attributes: { textAlign: 'left' } });
expect(textElement.style.textAnchor).toBe('start');
});
it('sets text-anchor=middle when attr.textAnchor=center', function() {
createSvgRenderer().drawText(textElement, { attributes: { textAnchor: 'center' } });
it('sets text-anchor=middle when attr.textAlign=center', function() {
createSvgRenderer().drawText(textElement, { attributes: { textAlign: 'center' } });
expect(textElement.style.textAnchor).toBe('middle');
});
it('sets text-anchor=end when attr.textAnchor=right', function() {
createSvgRenderer().drawText(textElement, { attributes: { textAnchor: 'right' } });
it('sets text-anchor=end when attr.textAlign=right', function() {
createSvgRenderer().drawText(textElement, { attributes: { textAlign: 'right' } });
expect(textElement.style.textAnchor).toBe('end');
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/text-spec.js
Expand Up @@ -122,18 +122,18 @@ define([

});

describe('provides a property to change `textAnchor`', function() {
describe('provides a property to change `textAlign`', function() {
it('is set to `left` by default', function() {
expect(new Text('').attr('textAnchor')).toBe('left');
expect(new Text('').attr('textAlign')).toBe('left');
});
it('returns `center` when set to `center`.', function() {
expect(new Text('').attr('textAnchor', 'center').attr('textAnchor')).toBe('center');
expect(new Text('').attr('textAlign', 'center').attr('textAlign')).toBe('center');
});
it('returns `right` when set to `right`', function() {
expect(new Text('').attr('textAnchor', 'right').attr('textAnchor')).toBe('right');
expect(new Text('').attr('textAlign', 'right').attr('textAlign')).toBe('right');
});
it('ignores unkown values', function() {
expect(new Text('').attr('textAnchor', 4).attr('textAnchor')).toBe('left');
expect(new Text('').attr('textAlign', 4).attr('textAlign')).toBe('left');
});
});

Expand Down

0 comments on commit 41899bb

Please sign in to comment.