mxClient renders different shapes all as squares

2019-08-18 18:00发布

问题:

Several weeks ago I have been asked to upgrade a web application based on a very old version of MXGraph library (version 2.4). The application integrated also the 'grapheditor' a sort of demo application evolved later in Diagramly and then in Draw.io). Recently I completed the more problematic step, the transition from old "grapheditor" to Draw.io, so I am now able to open all the previous diagrams (saved as plain xml), modify and save them consistently. Ok, this is the nice part. The bad side is the 'read-only' section of the application ,where the users can more or less, only view the graph. This page is based on the mxClient.js that renders the graph described in the xml through this code:

    var graph = new mxGraph(container);
    var diagram = mxUtils.parseXml(xml);
    var codec = new mxCodec(diagram);
    codec.decode(diagram.documentElement, graph.getModel());
    graph.fit();

Upgrading the MX library to the last version (3.9.10) the same code works but some shapes are not rendered properly, they appears as squares instead of circles, ellipses, etc. The two following images are an example of this misbehavior

graph in the draw.io

same graph rendered by mxClient

After some tries I discovered that the old mxClient is able to render the same graph perfectly (as draw.io does) so I think there have to be something wrong (or missing) in my code or mxGraph installation/configuration. As a temporary workaround I can keep in place the old version of mxGraph but obviously I'd like to use the new one. Can someone give me an hint on this? Any help would be very appreciated. Thanks!

回答1:

The tape shape isn't part of core mxGraph, it's part of the GraphEditor example, in the additional shapes JavaScript.

If you look at the style of the ellipse, it's probably not the one in the core, most likely another one from Shapes.js.

Either pull in shapes.js, or use the viewer in draw.io.