File size: 1,331 Bytes
af6912c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var elementGroup = require('./group-elements');
var roundNumber = require("./round-number");

function printStem(renderer, x, dx, y1, y2, klass, name) {
	if (dx < 0 || y1 < y2) { // correct path "handedness" for intersection with other elements
		var tmp = roundNumber(y2);
		y2 = roundNumber(y1);
		y1 = tmp;
	} else {
		y1 = roundNumber(y1);
		y2 = roundNumber(y2);
	}
	x = roundNumber(x);
	var x2 = roundNumber(x + dx);
	// TODO-PER: This fixes a firefox bug where it isn't displayed
	if (renderer.firefox112) {
		x += dx / 2; // Because the x coordinate is the edge of where the line goes but the width widens from the middle.
		var attr = {
			x1: x,
			x2: x,
			y1: y1,
			y2: y2,
			stroke: renderer.foregroundColor,
			'stroke-width': Math.abs(dx)
		}
		if (klass)
			attr['class'] = klass;
		if (name)
			attr['data-name'] = name;
		
		return renderer.paper.lineToBack(attr);
	}
	var pathArray = [["M", x, y1], ["L", x, y2], ["L", x2, y2], ["L", x2, y1], ["z"]];
	var attr = { path: "" };
	for (var i = 0; i < pathArray.length; i++)
		attr.path += pathArray[i].join(" ");
	if (klass)
		attr['class'] = klass;
	if (name)
		attr['data-name'] = name;
	if (!elementGroup.isInGroup()) {
		attr.stroke = "none";
		attr.fill = renderer.foregroundColor;
	}
	return renderer.paper.pathToBack(attr);
}

module.exports = printStem;