@Override public void insertGraphNode(GraphNode graphNode) throws GraphRenderingException { StringBuilder styleSB = new StringBuilder(); if (graphNode.getShape() != null) { String mxShape = getMxShape(graphNode.getShape()); styleSB.append(mxConstants.STYLE_SHAPE).append("=").append(mxShape).append(";"); } GraphNode.Alignment textAlignment = graphNode.getTextAlignment(); if (textAlignment != null) { styleSB.append(mxConstants.STYLE_ALIGN).append("=").append(getMxAlignment(textAlignment)).append(";"); } Color color = graphNode.getFillColor(); if (color != null) { String hexColor = "#" + Integer.toHexString(color.getRGB()).substring(2); styleSB.append(mxConstants.STYLE_FILLCOLOR).append("=").append(hexColor).append(";"); } String label = graphNode.getLabel(); mxRectangle rectangle = mxUtils.getSizeForHtml(label, new HashMap<>(), 1, 0); double width = rectangle.getWidth() + 35; double height = rectangle.getHeight() + 25; Object node = getGraph().insertVertex(getGraph().getDefaultParent(), null, label, 0, 0, width, height); getGraph().getModel().setStyle(node, styleSB.toString()); getGraphNodeObjectMap().put(graphNode, node); }
/** * Returns the size for the given label. If isHtml is true then any HTML * markup in the label is computed as HTML and all newlines inside the HTML * body are converted into linebreaks. */ public static mxRectangle getLabelSize(String label, Map<String, Object> style, boolean isHtml, double scale, double htmlWrapWidth) { mxRectangle size; if (isHtml) { size = getSizeForHtml(getBodyMarkup(label, true), style, scale, htmlWrapWidth); } else { size = getSizeForString(label, getFont(style), scale); } return size; }
/** * Returns the size for the given label. If isHtml is true then any HTML * markup in the label is computed as HTML and all newlines inside the HTML * body are converted into linebreaks. */ public static mxRectangle getLabelSize(String label, Map<String, Object> style, boolean isHtml, double scale, double htmlWrapWidth) { mxRectangle size; if (isHtml) { size = getSizeForHtml(getBodyMarkup(label, true), style, scale, htmlWrapWidth); } else { size = getSizeForString(label, getFont(style), scale); } return size; }