582
582
return labelVector;
586
* Returns the absolute position of the main label
587
* @return the absolute position of the main label
589
protected Point2D getAbsoluteLabelPosition() {
590
Point2D result = getAbsoluteLabelPositionFromRelative(GraphConstants.getLabelPosition(getAllAttributes()));
595
* Returns the absolute position of the specified extra label
596
* @param index the index of the extra label
597
* @return the absolute position of the specified extra label
599
protected Point2D getAbsoluteExtraLabelPosition(int index) {
600
Point2D[] positions = GraphConstants
601
.getExtraLabelPositions(getAllAttributes());
602
if (positions != null && positions.length > index) {
603
Point2D result = getAbsoluteLabelPositionFromRelative(positions[index]);
610
* Converts relative label position to absolute and allows for
612
* @param geometry the relative label position
613
* @return the absolute label position including any offset
615
protected Point2D getAbsoluteLabelPositionFromRelative(Point2D geometry) {
616
Point2D result = convertRelativeLabelPositionToAbsolute(geometry);
623
Point2D offset = GraphConstants.getOffset(getAllAttributes());
625
if (offset != null) {
626
offsetX = offset.getX();
627
offsetY = offset.getY();
630
double x = result.getX() + offsetX;
631
double y = result.getY() + offsetY;
632
return new Point2D.Double(x, y);
639
* Converts an relative label position (x is distance along edge and y is
640
* distance above/below edge vector) into an absolute co-ordination point
641
* @param geometry the relative label position
642
* @return the absolute label position
644
protected Point2D convertRelativeLabelPositionToAbsolute(Point2D geometry) {
645
int pointCount = getPointCount();
648
double[] segments = new double[pointCount];
649
Point2D pt = getPoint(0);
653
// Find the total length of the segments and also store the length
655
for (int i = 1; i < pointCount; i++)
657
Point2D tmp = getPoint(i);
661
double dx = pt.getX() - tmp.getX();
662
double dy = pt.getY() - tmp.getY();
664
double segment = Math.sqrt(dx * dx + dy * dy);
666
segments[i - 1] = segment;
672
// Change x to be a value between 0 and 1 indicating how far
673
// along the edge the label is
674
double x = geometry.getX()/GraphConstants.PERMILLE;
675
double y = geometry.getY();
677
// dist is the distance along the edge the label is
678
double dist = x * length;
682
double segment = segments[0];
684
// Find the length up to the start of the segment the label is
685
// on (length) and retrieve the length of that segment (segment)
686
while (dist > length + segment && index < pointCount - 1)
689
segment = segments[index++];
692
// factor is the proportion along this segment the label lies at
693
double factor = (dist - length) / segment;
695
Point2D p0 = getPoint(index - 1);
696
Point2D pe = getPoint(index);
698
if (p0 != null && pe != null)
700
// The x and y offsets of the label from the start point
702
double dx = pe.getX() - p0.getX();
703
double dy = pe.getY() - p0.getY();
705
// The normal vectors of
706
double nx = dy / segment;
707
double ny = dx / segment;
709
// The x position is the start x of the segment + the factor of
710
// the x offset between the start and end of the segment + the
711
// x component of the y (height) offset contributed along the
713
x = p0.getX() + dx * factor - nx * y;
715
// The x position is the start y of the segment + the factor of
716
// the y offset between the start and end of the segment + the
717
// y component of the y (height) offset contributed along the
719
y = p0.getY() + dy * factor + ny * y;
720
return new Point2D.Double(x, y);
1225
projlenSq = dotprod * dotprod / (x2 * x2 + y2 * y2);
1369
projlenSq = dotprod * dotprod / (xSegment * xSegment + ySegment * ySegment);
1228
tmp = Math.sqrt(projlenSq);
1234
p0 = edge.getPoint(index);
1235
Point2D pe = edge.getPoint(index+1);
1240
if (p0 != null && pe != null)
1242
double factor = tmp / seg;
1244
double dx = pe.getX() - p0.getX();
1245
double dy = pe.getY() - p0.getY();
1247
double tx = p0.getX() + dx * factor;
1248
double ty = p0.getY() + dy * factor;
1250
offsetX = p.getX() - tx;
1251
offsetY = p.getY() - ty;
1254
// Uses the offset constant to align the label to the point
1255
// from the relative location on the edge shape
1256
Point2D off = new Point2D.Double(offsetX, offsetY);
1257
GraphConstants.setOffset(edge.getAllAttributes(), off);
1259
// Contructs the relative point for the label
1260
Point2D result = new Point2D.Double(((((totalLength/2 - length - tmp)/
1261
totalLength)*-2)+1)*GraphConstants.PERMILLE / 2, 0);
1372
double projlen = Math.sqrt(projlenSq);
1378
double yDistance = Line2D.ptLineDist(pt2.getX(), pt2.getY(), pt.getX(), pt.getY(), p.getX(), p.getY());
1379
int direction = Line2D.relativeCCW(pt2.getX(), pt2.getY(), pt.getX(), pt.getY(), p.getX(), p.getY());
1381
if (direction == -1) {
1382
yDistance = -yDistance;
1385
// Constructs the relative point for the label
1386
Point2D result = new Point2D.Double(((((totalLength/2 - length - projlen)/
1387
totalLength)*-2)+1)*GraphConstants.PERMILLE / 2, yDistance);
1389
// Use the utility method to find
1390
Point2D storedRelativePosition = edge.convertRelativeLabelPositionToAbsolute(result);
1391
if (p.equals(storedRelativePosition)) {
1392
GraphConstants.setRemoveAttributes(edge.getAllAttributes(), new Object[] {GraphConstants.OFFSET});
1394
Point2D off = new Point2D.Double(p.getX() - storedRelativePosition.getX(), p.getY() - storedRelativePosition.getY());
1395
GraphConstants.setOffset(edge.getAllAttributes(), off);
1388
1522
EdgeView e = relevantEdge;
1389
1523
int handlesize = graph.getHandleSize();
1390
1524
EdgeRenderer er = (EdgeRenderer) edge.getRenderer();
1391
Point2D p = graph.toScreen(er.getLabelPosition(e));
1525
Point2D labelPosition = er.getLabelPosition(e);
1527
if (labelPosition != null) {
1528
p = (Point2D)labelPosition.clone();
1392
1531
Dimension d = er.getLabelSize(e, graph.convertValueToString(e));
1393
1532
if (p != null && d != null) {
1394
1533
Point2D s = graph.toScreen(new Point2D.Double(d.width,