Hi there.

How can i set the cell size for an own shape? Tried following:

1) added a stylesheet setting width and height values:

        <mxStylesheet as="stylesheet">
                <add as="screen">
        <add as="shape" value="rectangle"/>
        <add as="height" value="50"/>
        <add as="width" value="50"/>
        <add as="fillColor" value="#84CFEF"/>
        <add as="strokeColor" value="#84CFEF"/>
        <add as="labelBackgroundColor" value="none"/>

2) this seems to get overriden by:

<Array as="templates">
<add as="shape">
        <Shape label="" description="" href="">
            <mxCell vertex="1" style="ellipse">     
                <mxGeometry as="geometry" width="" height=""/>

Can s.o. help with an idea?

asked 19 Oct '12, 12:39

Autoflow's gravatar image

accept rate: 0%

The width and height can only be set via the geometry, not via the stylesheet. However, you can override mxGraphView.updateVertexLabelOffset (which is the first method called after the size is updated in validateBounds) as follows to implement this:

var updateVertexLabelOffset = graph.view.updateVertexLabelOffset;
graph.view.updateVertexLabelOffset = function(state)
  updateVertexLabelOffset.apply(this, arguments);

  if (state.style['width'] != null)
    state.width = this.scale * parseFloat(state.style['width']);

  if (state.style['height'] != null)
    state.height = this.scale * parseFloat(state.style['height']);

This can then be used as follows:

var parent = graph.getDefaultParent();
var v1 = graph.insertVertex(parent, null, 'Hello', 20, 20, 0, 0,

answered 27 Oct '12, 07:17

Gaudenz's gravatar image

accept rate: 39%

edited 27 Oct '12, 07:25

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 19 Oct '12, 12:39

Seen: 1,965 times

Last updated: 27 Oct '12, 07:25