Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

no way to center label

0 votes
When an edge is a spline, there is no way to add a label to it that is centered and placed over the edge. See this graph as an example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
  <!--Created by yFiles for Java 2.8-->
  <key for="graphml" id="d0" yfiles.type="resources"/>
  <key for="port" id="d1" yfiles.type="portgraphics"/>
  <key for="port" id="d2" yfiles.type="portgeometry"/>
  <key for="port" id="d3" yfiles.type="portuserdata"/>
  <key attr.name="url" attr.type="string" for="node" id="d4"/>
  <key attr.name="description" attr.type="string" for="node" id="d5"/>
  <key for="node" id="d6" yfiles.type="nodegraphics"/>
  <key attr.name="Description" attr.type="string" for="graph" id="d7"/>
  <key attr.name="url" attr.type="string" for="edge" id="d8"/>
  <key attr.name="description" attr.type="string" for="edge" id="d9"/>
  <key for="edge" id="d10" yfiles.type="edgegraphics"/>
  <graph edgedefault="directed" id="G">
    <data key="d7"/>
    <node id="n0">
      <data key="d5"><![CDATA[27]]></data>
      <data key="d6">
        <y:ShapeNode>
          <y:Geometry height="30.0" width="30.0" x="394.0" y="516.0"/>
          <y:Fill hasColor="false" transparent="false"/>
          <y:BorderStyle color="#000000" type="line" width="1.0"/>
          <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" hasText="false" height="4.0" modelName="internal" modelPosition="c" textColor="#000000" visible="true" width="4.0" x="13.0" y="13.0"/>
          <y:Shape type="ellipse"/>
        </y:ShapeNode>
      </data>
    </node>
    <node id="n1">
      <data key="d5"><![CDATA[28]]></data>
      <data key="d6">
        <y:ShapeNode>
          <y:Geometry height="30.0" width="30.0" x="394.0" y="306.0"/>
          <y:Fill hasColor="false" transparent="false"/>
          <y:BorderStyle color="#000000" type="line" width="1.0"/>
          <y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" hasText="false" height="4.0" modelName="internal" modelPosition="c" textColor="#000000" visible="true" width="4.0" x="13.0" y="13.0"/>
          <y:Shape type="ellipse"/>
        </y:ShapeNode>
      </data>
    </node>
    <edge id="e0" source="n1" target="n0">
      <data key="d9"/>
      <data key="d10">
        <y:SplineEdge>
          <y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
            <y:Point x="520.0" y="421.5"/>
          </y:Path>
          <y:LineStyle color="#000000" type="dashed" width="1.0"/>
          <y:Arrows source="none" target="standard"/>
          <y:EdgeLabel alignment="center" backgroundColor="#FFFFFF" distance="2.0" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasLineColor="false" height="18.701171875" modelName="centered" modelPosition="center" preferredPlacement="anywhere" ratio="0.5" textColor="#000000" visible="true" width="10.673828125" x="49.28985595703125" y="126.40604874894422">a</y:EdgeLabel>
        </y:SplineEdge>
      </data>
    </edge>
  </graph>
  <data key="d0">
    <y:Resources/>
  </data>
</graphml>
in Help by (220 points)

2 Answers

0 votes

That's not entirely true. In short, the label model of your edge label is Centered which doesn't work very well with non-straight line edges. You can change this to, for example, the Free (unrestricted) label model in the Properties View.

For convenience, I propose to create an edge with a label position that fits your needs and add it as template to a user-defined palette section.

Please see the following links for more details:

 

by [yWorks] (26.8k points)
The FREE placement has much the same problems as the CENTERED one:
the label does not remain placed over the edge when the edge is redrawn (e.g. bent).
0 votes
Label placement always assumes a straight-line edge path. Moreover, center position has strange semantics and only works as expected for edges without bends. (If there are bends, center places the label near the middle of the edge's longest straight-line segement.)
by [yWorks] (160k points)
Legal Disclosure | Privacy Policy
...