Simplify arrow rendering and fix 'bar' terminator width

This commit is contained in:
David Evans 2017-11-05 18:42:09 +00:00
parent ddb4430ed2
commit 3b1fa67466
13 changed files with 30 additions and 22 deletions

View File

@ -175,11 +175,11 @@ Bar -> Baz
### Simultaneous Actions (Beta!) ### Simultaneous Actions (Beta!)
<img src="screenshots/SimultaneousActions.png" alt="Simultaneous Actions preview" width="200" align="right" />
This is a work-in-progress feature. There are situations where this can This is a work-in-progress feature. There are situations where this can
lead to [ugly / unreadable overlapping content](https://github.com/davidje13/SequenceDiagram/issues/13). lead to [ugly / unreadable overlapping content](https://github.com/davidje13/SequenceDiagram/issues/13).
<img src="screenshots/SimultaneousActions.png" alt="Simultaneous Actions preview" width="200" align="right" />
``` ```
begin A, B, C, D begin A, B, C, D
A -> C A -> C

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -74,6 +74,7 @@ define([
const config = env.theme.connect; const config = env.theme.connect;
const from = env.agentInfos.get(agentNames[0]); const from = env.agentInfos.get(agentNames[0]);
const dx = config.arrow.width;
const dy = config.arrow.height / 2; const dy = config.arrow.height / 2;
const short = getArrowShort(env.theme); const short = getArrowShort(env.theme);
@ -88,7 +89,7 @@ define([
const x0 = ( const x0 = (
lineX + lineX +
short + short +
config.arrow.width + dx +
config.label.padding config.label.padding
); );
@ -112,12 +113,14 @@ define([
); );
const y1 = y0 + r * 2; const y1 = y0 + r * 2;
const space = short + dx / 2;
env.shapeLayer.appendChild(svg.make('path', Object.assign({ env.shapeLayer.appendChild(svg.make('path', Object.assign({
'd': ( 'd': (
'M ' + (lineX + (options.left ? short : 0)) + ' ' + y0 + 'M ' + (lineX + (options.left ? space : 0)) + ' ' + y0 +
' L ' + x1 + ' ' + y0 + ' L ' + x1 + ' ' + y0 +
' A ' + r + ' ' + r + ' 0 0 1 ' + x1 + ' ' + y1 + ' A ' + r + ' ' + r + ' 0 0 1 ' + x1 + ' ' + y1 +
' L ' + (lineX + (options.right ? short : 0)) + ' ' + y1 ' L ' + (lineX + (options.right ? space : 0)) + ' ' + y1
), ),
}, config.lineAttrs[options.line]))); }, config.lineAttrs[options.line])));
@ -125,7 +128,7 @@ define([
drawHorizontalArrowHead(env.shapeLayer, { drawHorizontalArrowHead(env.shapeLayer, {
x: lineX + short, x: lineX + short,
y: y0, y: y0,
dx: config.arrow.width, dx,
dy, dy,
attrs: config.arrow.attrs, attrs: config.arrow.attrs,
}); });
@ -135,7 +138,7 @@ define([
drawHorizontalArrowHead(env.shapeLayer, { drawHorizontalArrowHead(env.shapeLayer, {
x: lineX + short, x: lineX + short,
y: y1, y: y1,
dx: config.arrow.width, dx,
dy, dy,
attrs: config.arrow.attrs, attrs: config.arrow.attrs,
}); });
@ -149,6 +152,7 @@ define([
const from = env.agentInfos.get(agentNames[0]); const from = env.agentInfos.get(agentNames[0]);
const to = env.agentInfos.get(agentNames[1]); const to = env.agentInfos.get(agentNames[1]);
const dx = config.arrow.width;
const dy = config.arrow.height / 2; const dy = config.arrow.height / 2;
const dir = (from.x < to.x) ? 1 : -1; const dir = (from.x < to.x) ? 1 : -1;
const short = getArrowShort(env.theme); const short = getArrowShort(env.theme);
@ -174,10 +178,12 @@ define([
SVGTextBlockClass: env.SVGTextBlockClass, SVGTextBlockClass: env.SVGTextBlockClass,
}); });
const space = short + dx / 2;
env.shapeLayer.appendChild(svg.make('line', Object.assign({ env.shapeLayer.appendChild(svg.make('line', Object.assign({
'x1': x0 + (options.left ? short : 0) * dir, 'x1': x0 + (options.left ? space : 0) * dir,
'y1': y, 'y1': y,
'x2': x1 - (options.right ? short : 0) * dir, 'x2': x1 - (options.right ? space : 0) * dir,
'y2': y, 'y2': y,
}, config.lineAttrs[options.line]))); }, config.lineAttrs[options.line])));
@ -185,7 +191,7 @@ define([
drawHorizontalArrowHead(env.shapeLayer, { drawHorizontalArrowHead(env.shapeLayer, {
x: x0 + short * dir, x: x0 + short * dir,
y, y,
dx: config.arrow.width * dir, dx: dx * dir,
dy, dy,
attrs: config.arrow.attrs, attrs: config.arrow.attrs,
}); });
@ -195,7 +201,7 @@ define([
drawHorizontalArrowHead(env.shapeLayer, { drawHorizontalArrowHead(env.shapeLayer, {
x: x1 - short * dir, x: x1 - short * dir,
y, y,
dx: -config.arrow.width * dir, dx: -dx * dir,
dy, dy,
attrs: config.arrow.attrs, attrs: config.arrow.attrs,
}); });

View File

@ -74,12 +74,12 @@ defineDescribe('Sequence Integration', [
const content = getSimplifiedContent(renderer); const content = getSimplifiedContent(renderer);
expect(content).toContain( expect(content).toContain(
'<svg width="100%" height="100%" viewBox="-5 -5 82 49">' '<svg width="100%" height="100%" viewBox="-5 -5 82 47">'
); );
// Agent 1 // Agent 1
expect(content).toContain( expect(content).toContain(
'<line x1="20.5" y1="11" x2="20.5" y2="39" class="agent-1-line"' '<line x1="20.5" y1="11" x2="20.5" y2="37" class="agent-1-line"'
); );
expect(content).toContain( expect(content).toContain(
'<rect x="10" y="0" width="21" height="11"' '<rect x="10" y="0" width="21" height="11"'
@ -90,7 +90,7 @@ defineDescribe('Sequence Integration', [
// Agent 2 // Agent 2
expect(content).toContain( expect(content).toContain(
'<line x1="51.5" y1="11" x2="51.5" y2="39" class="agent-2-line"' '<line x1="51.5" y1="11" x2="51.5" y2="37" class="agent-2-line"'
); );
expect(content).toContain( expect(content).toContain(
'<rect x="41" y="0" width="21" height="11"' '<rect x="41" y="0" width="21" height="11"'
@ -101,10 +101,10 @@ defineDescribe('Sequence Integration', [
// Arrow // Arrow
expect(content).toContain( expect(content).toContain(
'<line x1="20.5" y1="20" x2="50.29' '<line x1="20.5" y1="19" x2="48.5" y2="19"'
); );
expect(content).toContain( expect(content).toContain(
'<polygon points="46.29' '<polygon points="46 14 51 19 46 24"'
); );
}); });

View File

@ -7,7 +7,7 @@ define(['core/ArrayUtilities', 'svg/SVGShapes'], (array, SVGShapes) => {
titleMargin: 10, titleMargin: 10,
outerMargin: 5, outerMargin: 5,
agentMargin: 10, agentMargin: 10,
actionMargin: 5, actionMargin: 3,
agentLineHighlightRadius: 4, agentLineHighlightRadius: 4,
agentCap: { agentCap: {
@ -42,7 +42,9 @@ define(['core/ArrayUtilities', 'svg/SVGShapes'], (array, SVGShapes) => {
bar: { bar: {
attrs: { attrs: {
'fill': '#000000', 'fill': '#000000',
'height': 5, 'stroke': '#000000',
'stroke-width': 1,
'height': 4,
}, },
}, },
none: { none: {
@ -66,12 +68,12 @@ define(['core/ArrayUtilities', 'svg/SVGShapes'], (array, SVGShapes) => {
}, },
}, },
arrow: { arrow: {
width: 4, width: 5,
height: 8, height: 10,
attrs: { attrs: {
'fill': '#000000', 'fill': '#000000',
'stroke': '#000000', 'stroke': 'none',
'stroke-width': 1, 'stroke-width': 0,
'stroke-linejoin': 'miter', 'stroke-linejoin': 'miter',
}, },
}, },