In order to calculate label layouts on the server (either using integrated or generic labeling), some prerequisites have to be met:
If label mapping is enabled, the label layout data calculated by the layout algorithm will be committed to the label data objects when the graph is written back to the client. If the label has to be accessed/changed before the graph is written back, but after the layout, this can be triggered manually using copyLabelLayouts(LayoutGraph graph).
Label instances can be added on the server using StyledLayoutGraph's methods addLabel(Node node, Label label) and addLabel(Edge edge, Label label), or by adding the Label instances manually to the list of labels returned by getLabels(Node node) and getLabels(Edge edge).
When a label is added on the server, the layout graph is not automatically updated. This shouldn't be a problem, as long as no label layout is calculated before sending the graph back to the client. In order to synchronize the list of labels with the layout graph, FlexIOTools's static methods syncLabels(Node node, boolean createIfNotExisting) and syncLabels(Edge edge, boolean createIfNotExisting) can be used.
Note that before calling the synchronize methods either a reasonable preferred size should be set on the new labels or a style which implements a LabelSizeCalculator. If no size is set or can be calculated, a default size (40,40) is used. If no preferred size is set and the synchronize methods are not used, the correct preferred size will be calculated on the client when the new label is parsed.
Copyright ©2007-2015, yWorks GmbH. All rights reserved. |