예제 #1
0
func (tr *tegRenderer) renderConnection(t *transition, shiftT *geometry.Point,
	p *place, shiftP *geometry.Point, inbound bool, index int) {
	var control *controlPoint
	var count int
	if inbound {
		control = p.outControl
		count = len(t.in)
	} else {
		control = p.inControl
		count = len(t.out)
	}
	xyC1 := control.Center()
	xyC1.X, xyC1.Y = xyC1.X+shiftP.X, xyC1.Y+shiftP.Y
	endT := calcBorderPointTransition(t, shiftT, inbound, count, index)
	endP := calcBorderPointPlace(p, shiftP, xyC1.X, xyC1.Y)
	var xyC2 *geometry.Point
	var start, end *geometry.Point
	if inbound {
		if t.horizontal {
			xyC2 = pt(endT.x, endT.y-Margin)
		} else {
			xyC2 = pt(endT.x-Margin, endT.y)
		}
		start = pt(endP.x, endP.y)
		end = pt(endT.xTip, endT.yTip)
	} else {
		if t.horizontal {
			xyC2 = pt(endT.x, endT.y+Margin)
		} else {
			xyC2 = pt(endT.x+Margin, endT.y)
		}
		start = pt(endT.x, endT.y)
		end = pt(endP.xTip, endP.yTip)
		xyC1, xyC2 = xyC2, xyC1
	}
	chain := render.NewChain(
		tr.absPoint(tr.scalePoint(start)),
		tr.absPoint(tr.scalePoint(xyC1)),
		tr.absPoint(tr.scalePoint(xyC2)),
		tr.absPoint(tr.scalePoint(end)),
	)
	chain.Style = &render.Style{
		LineWidth:   tr.scale(1.0),
		Stroke:      true,
		StrokeStyle: ColorUtility,
	}
	tr.buf.Chains.Put(chain)
}
예제 #2
0
func (pr *planeRenderer) renderChain(points []*geometry.Point, color string) {
	max := rpt(pr.canvasWidth, pr.canvasHeight)
	firstX, lastY := pr.absX(pr.scaleX(points[0].X)), pr.absY(pr.scaleY(points[len(points)-1].Y))

	pts := make([]*render.Point, 0, len(points)+2)
	pts = append(pts, rpt(firstX, max.Y))
	for i := 0; i < len(points); i++ {
		if i > 0 {
			p1 := points[i-1]
			p2 := points[i]
			pts = append(pts, pr.absPoint(pr.scalePoint(pt(p2.X, p1.Y))))
		}
		pts = append(pts, pr.absPoint(pr.scalePoint(points[i])))
	}
	pts = append(pts, rpt(max.X, lastY))

	if pr.drawShadows {
		for i := 0; i < len(pts)-1; i++ {
			bg := &render.Rect{
				Style: &render.Style{
					Fill:      true,
					FillStyle: util.AlphaHex(color, 60),
				},
				X: pts[i].X, Y: pts[i].Y,
				W: pts[i+1].X - pts[i].X,
				H: max.Y - pts[i].Y,
			}
			pr.buf.Rects.Put(bg)
		}
	}

	chain := render.NewChain(pts...)
	chain.Style = &render.Style{
		LineWidth:   pr.scale(2.0),
		Stroke:      true,
		StrokeStyle: color,
	}
	pr.buf.Chains.Put(chain)
}