How do I add or redefine shapes within ShapeNodeRealizer?
Applies to: yFiles 2.4, yFiles 2.3, yFiles 2.2 print article email article

Type: Questions & Answers

Describes how to add custom shapes to the ShapeNodeRealizer.

To add your own shapes to ShapeNodeRealizer is demonstrated by the yFiles demo demo/view/StateNodeRealizer.java. To redefine the appearance of an already given shape like HEXAGON is done by overriding method setShapeType. Currently both procedures involve the subclassing of ShapeNodeRealizer. Within setShapeType the original HEXAGON shape is constructed this way:

GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD,6);
path.moveTo((float)(x),(float)(y+height/2.0)); 
path.lineTo((float)(x+width*0.1),(float)(y));
path.lineTo((float)(x+width*0.9),(float)(y));
path.lineTo((float)(x+width),(float)(y+height/2.0));
path.lineTo((float)(x+width*0.9),(float)(y+height));
path.lineTo((float)(x+width*0.1),(float)(y+height));
path.closePath();
//assign the hexagonal path to the protected shape attribute
shape = path;

See GenericNodeRealizer for an alternative approach of how to customize the visual appearance of nodes.

Keywords: ShapeNodeRealizer - shape - custom shape - visual appearance - NodeRealizer - GenericNodeRealizer -

Provide feedback:
How useful was this article?    less 1 2 3 4 5 more
Email address (optional):
COPYRIGHT © 2008 yWorks · ALL RIGHTS RESERVED imprint | top | home