Skip to content

Commit

Permalink
Change margin of ATTACHMENTS.pathLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
anseki committed Sep 7, 2016
1 parent bb74a92 commit 54e5eda
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/leader-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -4281,14 +4281,16 @@
}

curStats.pathData = value = ATTACHMENTS.pathLabel.getOffsetPathData(pathList,
// margin between line and base-line: attachProps.height / 2
llStats.line_strokeWidth / 2 + attachProps.strokeWidth / 2 + attachProps.height / 2,
attachProps.height * 1.5);
// margin between line and base-line: attachProps.height / 4
// llStats.line_strokeWidth / 2 + attachProps.strokeWidth / 2 + attachProps.height / 2,
llStats.line_strokeWidth / 2 + attachProps.strokeWidth / 2 + attachProps.height / 4,
// margin between corner and text: attachProps.height * 1.25
attachProps.height * 1.25);

// Apply `pathData`
if (pathDataHasChanged(value, aplStats.pathData)) {
traceLog.add('pathData'); // [DEBUG/]
attachProps.path.setPathData(value);
attachProps.elmPath.setPathData(value);
aplStats.pathData = value;
attachProps.bBox = attachProps.elmPosition.getBBox(); // for adjustEdge
attachProps.updateStartOffset(props);
Expand Down Expand Up @@ -4317,7 +4319,9 @@
if (attachProps.semIndex !== 2) {
plugBackLen = Math.max(
llStats.attach_plugBackLenSE[attachProps.semIndex] || 0,
llStats.line_strokeWidth / 2);
llStats.line_strokeWidth / 2) +
// margin between plug and text: attachProps.height / 4
attachProps.strokeWidth / 2 + attachProps.height / 4;
startOffset += attachProps.semIndex === 0 ? plugBackLen : -plugBackLen;
startOffset = startOffset < 0 ? 0 : startOffset > pathLenAll ? pathLenAll : startOffset;
}
Expand Down Expand Up @@ -4527,16 +4531,17 @@
text.styleText[propName] = attachProps[propName];
}
});
text.styleText.textAnchor = ['start', 'end', 'middle'][attachProps.semIndex];
if (attachProps.semIndex === 2 && !attachProps.lineOffset) {
// The position never change.
text.elmOffset.startOffset.baseVal.newValueSpecifiedUnits(SVGLength.SSVG_LENGTHTYPE_PERCENTAGE, 50);
}

text.elmsAppend.forEach(function(elm) { props.svg.appendChild(elm); });
// Get size in straight
text.elmPath.setPathData([{type: 'M', values: [0, 100]}, {type: 'h', values: [100]}]);
bBox = text.elmPosition.getBBox();
// textAnchor and startOffset might affect the size.
text.styleText.textAnchor = ['start', 'end', 'middle'][attachProps.semIndex];
if (attachProps.semIndex === 2 && !attachProps.lineOffset) { // The position never change.
text.elmOffset.startOffset.baseVal.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 50);
}

attachProps.height = bBox.height;
if (attachProps.outlineColor) {
strokeWidth = bBox.height / 9;
Expand All @@ -4561,10 +4566,10 @@
var props = bindTarget.props;

if (!attachProps.color) { addEventHandler(props, 'cur_line_color', attachProps.updateColor); }
attachProps.semIndex = bindTarget.optionName === 'startLabel' ? 0 :
bindTarget.optionName === 'endLabel' ? 1 : 2;
addEventHandler(props, 'cur_line_strokeWidth', attachProps.updatePath);
addEventHandler(props, 'apl_path', attachProps.updatePath);
attachProps.semIndex = bindTarget.optionName === 'startLabel' ? 0 :
bindTarget.optionName === 'endLabel' ? 1 : 2;
if (attachProps.semIndex !== 2 || attachProps.lineOffset) {
addEventHandler(props, 'cur_attach_plugBackLenSE', attachProps.updateStartOffset);
}
Expand Down
6 changes: 6 additions & 0 deletions test/guide-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ select.guide-mask-select {
stroke-width: 1px;
fill: none;
}

.guide-pathLabel {
fill: none;
stroke-width: 1px;
stroke: rgba(0, 112, 254, 0.7);
}
12 changes: 12 additions & 0 deletions test/guide-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ var guideView = (function() {
path.setPathData(pathSegs);
})();

// ======== pathLabel
(function() {
var elmPath, usePath;
props.attachments.forEach(function(attachProps) {
if (attachProps.conf === window.ATTACHMENTS.pathLabel && (elmPath = attachProps.elmPath)) {
usePath = guideSvg.appendChild(baseDocument.createElementNS(SVG_NS, 'use'));
usePath.href.baseVal = '#' + elmPath.id;
usePath.className.baseVal = 'guide-pathLabel';
}
});
})();

guideElements.push(guideSvg);

(function() {
Expand Down
14 changes: 14 additions & 0 deletions test/spec/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ describe('options', function() {
expect(props.options.plugSizeSE[0]).toBe(2);
expect(ll.startPlugSize).toBe(2);

// invalid number (NaN)
traceLog.clear();
ll.startPlugSize = NaN;
expect(traceLog.getTaggedLog('setOptions')).not.toContain('needs.plug');
expect(props.options.plugSizeSE[0]).toBe(2);
expect(ll.startPlugSize).toBe(2);

// invalid number (Infinity)
traceLog.clear();
ll.startPlugSize = Infinity;
expect(traceLog.getTaggedLog('setOptions')).not.toContain('needs.plug');
expect(props.options.plugSizeSE[0]).toBe(2);
expect(ll.startPlugSize).toBe(2);

// valid value (specified type)
traceLog.clear();
ll.startPlugSize = 3; // number
Expand Down

0 comments on commit 54e5eda

Please sign in to comment.