Skip to content

Discussion: level of backward compatibility with the legacy mxgraph codebase?  #8

Closed

Description

@tbouffard

My idea is to centralize decisions on this area and make any architectural changes documented and explicit. Feel free to comment.

For new mxGraph users, compatibility is not an issue, but for existing ones, introducing too much changes in one step could be challenging.

Starting point: #1 (comment)

I don't intend to maintain backwards compatibility for all of the modules as I think there needs to be some architectural changes to keep the codebase maintainable going into the future, but the structure+functionality of mxGraph overall seems fairly well thought out as-is in my opinion, even if it uses an older JS code style. I think I will probably keep the class names and function parameters etc the same for the most part.

Notably, I have already removed support for VML/Internet Explorer and Edge before it shifted to the Chromium engine, as I think that significantly eases maintenance.

Activity

  1. tbouffard commented on Mar 26, 2021

    @tbouffard
    MemberAuthor

    I am ok for the VML/Internet Explorer and Edge before it shifted to the Chromium engine removing. This was historically kept for paying customers of the former maintainers of mxGraph. There is less and less demand for these old browsers, and as a community, this will slow us down.

    As an existing user of mxGraph, that also uses it with the mxGraph Typescript support, I need more details about @mcyph I don't intend to maintain backwards compatibility for all of the modules ideas.
    I am opened to any changes but I would be happy to know which parts of mxGraph will be impacted and what ECMAScript version will be targeted (for now, comments in https://github.com/mcyph/mxgraph/blob/af8338c077478390b9fe588c075dfab93acce5e0/src/mxgraph/util/mxAbstractCanvas2D.js suggest that mxGraph may target ES9)

  2. changed the title [-]Decision: level of backward compatibility with the legacy mxgraph codebase? [/-] [+]Discussion: level of backward compatibility with the legacy mxgraph codebase? [/+] on Mar 26, 2021
  3. added
    chore
    on Mar 26, 2021
  4. mcyph commented on Mar 27, 2021

    @mcyph

    There's a lot to cover here and I'm sure I'll miss some things. I'll need to add to this but I've tried to summarize what I've changed and what I'll be proposing to change from here.

    Ideally, I think TypeScript support might be best integrated into the codebase too(?) I might need to read some more/ask for guidance on how to do this as I haven't used TypeScript before, but I have created type definitions using e.g. Cython before and think it might be similar.


    Although I've made quite extensive changes to the codebase so far, I think so far there isn't a huge amount which would need to be changed for existing users of mxGraph aside from things like the way modules currently need to be explicitly imported. A bundle with everything in one could probably be created to ease transition. I currently am using ES9 syntax like for (const i of myList) {}, although only in some areas and am using Babel to transpile, which should mean a vast majority of current browsers (Firefox/Chrome/Safari/Edge) would be supported.

    Most of the changes I've made are things like:

    • removing VML/IE6-11 support as mentioned (though IE9-11 might still work with some issues)
    • conversion to ES6 classes from prototypes
    • using ESLint to automatically arrange the code
    • moving from var to let/const
    • using ===/!== instead of ==/!= in cases where I thought it wouldn't cause side effects. I notice that mxUtils.getValue is also used extensively for configuration, but I was hesitant to use the triple operators in this case, and some of the other mxUtils functions also almost certainly rely on the behaviour of == and != for comparisons.
    • removing of mxUtils.bind() and replacing with () => {}-style prebound functions
    • separating things so there's only a single class per file
    • updating example code to use classes, local rather than global configuration and removing boilerplate (this actually has been a fairly large percentage of the work I've been doing)

    There sometimes will be bugs I've introduced as a result of these changes, but I think for the most part these are back-compatible.

    The way mxClient fits into everything and how e.g. the localization resources should be loaded needs to be clarified/fixed. Currently this functionality isn't working. Clarification about how the mxCodecs system works and how it integrates with tree-shaking also needs to be done at some stage, as the codecs aren't registered until the module is imported.


    In terms of things I'm considering but haven't done yet, and may cause issues for backwards compatibility:

    • I'm considering whether there's a way to prioritize composition over inheritance:

      • Need to figure out what to do with variables created in mxGraph.createHandlers(): tooltipHandler, selectionCellsHandler, connectionHandler, graphHandler, panningHandler, popupMenuHandler. (I personally think allowing instances as arguments to the constructor could be a better design than requiring subclasses to override e.g. createConnectionHandler for instance).
      • I'm thinking about whether there's a means of specifying configurations for different class instances, and not making configuration global for all future unrelated instances, with the goal of increasing flexibility and reducing side effects/bugs. It could mean another config variable to many classes, but I think the benefits could outweigh the downsides if there aren't better alternatives.
    • If replacing the configuration system, we'll need to consider whether setting global options via the prototype as before will be supported via a backwards compatibility mechanism.

    • Another thing to think about is, should changes to config objects take effect on instances that config has previously been associated with via "subscriptions"?

    This might be further in the future, but I'd like to consider e.g. allowing for integrating charts, canvases and and other HTML content inside the SVG as nodes, possibly via foreignObject tags or the native SVG renderer in some chart systems like eCharts and hoping clarifying how everything fits together could eventually allow for this.

  5. mcyph commented on Mar 27, 2021

    @mcyph

    Some potential ways of providing the config I've been considering are:

    I'm currently leaning towards using JavaScript Proxys as they could try explicit configuration via config argument first, prototype compatibility second, then default values last. They could be flexible with potential validation of values, and notification when values are changed to subscribing class instances. I'm also thinking it might need less documentation than if every variable had a separate setX or getX method. The downside I can see is it's a less used (though apparently widely supported) JavaScript feature that would be more complex at a lower level.

    If doing this, I'll need to go through each variable in each class and document which are instance variables that shouldn't be in the configuration (like the graph instance), those which are configuration values and need to be moved, and the ambiguous ones that come somewhere in between of the two.

  6. junsikshim commented on Mar 28, 2021

    @junsikshim
    Collaborator

    I've been trying to modernize mxgraph on my own, and I also had similar thoughts to mcyph's comments.

    Explicit getters/setters like o.setTargetPoint(x)/o.getTargetPoint()

    I tried to hide the inner states inside a closure, and expose only the getters and setters. But while doing that, I realized there are so many properties created on the fly on this. Some of them are used only inside that component, so it would be better to not expose them to outside.

    Moreover, in control.html example, an mxImageShape is created and assigned to a mxCellState as a new property named deleteControl which is not an override. It might be fine to use custom properties like that, but if people's implementations are based on some inner states(this.xxx is always available to the outside), hiding them will cause trouble.

    Also, in mxGraphHandler, there is already a method called getCells() along with this.cells = ... assignments. So, I had to create something like _getCells() for internal use which wasn't very pretty.

    I'm considering whether there's a way to prioritize composition over inheritance:

    I tried to throw out all the 'extends' stuff out, and use composition instead. So, extending mxEventSource became something like,

    const { fireEvent, addListener, removeListener } = mxEventSource();

    It was working alright, but after finding out all the unexpected overrides, my efforts ran into a brick wall, especially with all the mxShape subcomponents. I was relying heavily on closures, but it was hard to mix and match with overriden methods.

    Hope to discuss more and find a better way!

  7. mcyph commented on Mar 28, 2021

    @mcyph

    Yeah sounds great! I think certainly over the longer term keeping the inner states hidden could be a good goal.

    My reasoning for using ES6 classes was not primarily because of inheritance but ability to keep the constructor and inheritence chain (the extends ...) and relevant variables at the top of each file so I could see the most important info when I opened them. ES6 classes have in my previous projects behaved not exactly the same, but very similar to prototypes, and I thought that using them could allow for incremental changes. I also think while they aren't well-supported at the moment, private class fields are likely to soon be widely available by the time the refactor is done, and could convert internal variables over time.

    As you say many of the examples set properties in the prototype of each class, and also frequently reference variables like graph.container. I've tried to convert many of the examples to use inheritance so they don't pollute the global namespaces, but my feeling is it may be best to keep things working the old way for at least a while until users of the library have had a chance to migrate over. (I'm mainly using inheritance there because of composition not currently being possible with how mxGraph et al are instantiated btw). It's tempting to go further in cleaning things up, but I think that way we would have more time to get feedback from people who will use the modified mxGraph with legacy codebases.

    My feeling is so long as there's not too many levels of abstraction (preferably there would be as few as possible in my opinion) inheritance for shapes isn't a huge problem. But if there's lots of levels it can be hard to figure out what functionality/variables are where, and it might be easier to just duplicate methods. Like for instance mxCloud inherits from mxActor and mxShape, but perhaps it would be easier to only derive from a single class? I think perhaps it might be best to focus on other things first, but it may pay to use a diagramming tool (https://www.diagrams.net/ would be perfect 😄) to figure out how things interrelate and how to streamline things.

    Maybe it's somewhat a radical idea, but I wonder whether more-or-less mimicking how css works with separation of style, inheritance and class names could be a good idea. Like for instance someone could do something like the below with JS accessors and/or Proxys (note it's not taking into account the arguments/feasibility etc, it's just semi-pseudocode):

    const styles = {myClassName: {border: "1px solid blue"}};
    const myGraph = new mxGraph(div, styles);
    const myEllipse1 = new mxEllipse(className="myClassName");
    const myEllipse2 = new mxEllipse(className="myClassName");
    myGraph.appendChild(myEllipse1);
    myGraph.appendChild(myEllipse2);
    
    // Some time later, setting the below will instantly only affect myEllipse1/myEllipse2 respectively:
    myEllipse1.style.borderWidth = "5px";
    myEllipse2.style.borderColor = "red"; 
    

    I think it might be viable to mimic the way other elements work, so as to minimize the amount new users need to learn..but that could also affect backwards compatibility as the style variable is taken in many classes etc..it's still early days and need to consider a fair amount of things first 🤔

  8. mcyph commented on Mar 28, 2021

    @mcyph

    @junsikshim I want to look through in some more detail but I notice you've gone much further than I have in separating the constants and reorganizing mxUtils. I think it would be nice to integrate this as there's not much reason I can see for having a big utility class, especially when it makes tree-shaking more tricky due to so many files importing it.

  9. junsikshim commented on Mar 29, 2021

    @junsikshim
    Collaborator

    Right. When I used mxGraph in my projects before, the bloated bundle size a big problem, so enabling tree-shaking has been a primary goal of mine.

    Some other design choices I was trying to implement include...

    I removed all nulls from the code base in order to use the default function parameter functionality.

    mxGraphModel.prototype.getChildCells = function (parent, vertices, edges) {
      vertices = vertices != null ? vertices : false;
      edges = edges != null ? edges : false;

    becomes,

    mxGraphModel.prototype.getChildCells = function (parent, vertices = false, edges = false) {

    Since all the null checks are using != and ==, so using undefined instead of null is not a problem, but not using strict inequality feels kind of dirty, so I created isSet() / isUnset() helper function to check for nullish values.

    export const isSet = (v) => v !== undefined && v !== null;
    export const isUnset = (v) => !isSet(v);

    With that, if (a != null) becomes if (isSet(a)).
    Checking for null as well as undefined is for backward compatibility.

    Also, there are so many occurrences written like below,

    if (this.state.text != null &&
          this.state.text.node != null &&
          this.state.text.node.nextSibling != null) ...

    It would be a lot better to take advantage of optional chaining and write it like,

    if (isSet(this.state.text?.node?.nextSibling))

    I'll stop here before this comment gets too long :)

  10. junsikshim commented on Mar 30, 2021

    @junsikshim
    Collaborator

    @mcyph

    Like for instance mxCloud inherits from mxActor and mxShape, but perhaps it would be easier to only derive from a single class?

    I definitely think it should have only one super class. Extending from multiple classes doesn't make sense anyway, and if we treat them as mixins which we can compose, we might lose backward compatibility. In order to get more insights, I agree that we need some kind of diagram to see how things interrelate. But, I'm not sure where to start, if someone can begin to draw, I'd be willing to add on to it.

  11. mcyph commented on Mar 30, 2021

    @mcyph

    @junsikshim yeah there's a lot to consider and I'd like to get my repo status up to the stage where I can potentially submit a PR+merge with jsGraph's repo so more people can contribute and I'm not holding anyone up. Main things which I need to do I can think of:

    • Remove the React dependency, replacing with a basic node-only examples interface. Auto-generated examples output as .html could be possible once they're stable+is a good goal though it'd be harder to debug if needing to keep rebuilding when developing.
    • Make mxUtils use your refactored version. (The rest of the changes you've made would be quite broad so debating whether to try to go through and merge all at once now or do a big PR later, but it'd be good if some of the typing problems could be resolved/reduced. If all else fails too I think putting our two codebases side by side and comparing/merging is an option).
    • Figure out how to autogenerate the documentation.

    I should note while I'm thinking about it that I've removed the .net and java versions of mxGraph too (in case users will be affected by this), but from where I'm standing it should be feasible to get something of mergeable quality soon, even if only to a dev branch. I think it'd be easiest to do architectural changes like changing the superclasses iteratively after merging, autogenerated class diagrams might be enough to show class relationships depending how we go as some IDEs have UML generation systems.

  12. junsikshim commented on Mar 30, 2021

    @junsikshim
    Collaborator

    @mcyph Sounds great! I think we should start to build based on your work.

    My version of refactoring was an experiment to apply some composition feels to it, but after weeks of trying I realized it is impossible with the current architecture of mxgraph. So, just disregard my work, and I'll contribute where I can :)

  13. tbouffard commented on Mar 31, 2021

    @tbouffard
    MemberAuthor

    First, thanks @mcyph and @junsikshim for having taken time to share so much information and ideas. It is really great to see enthoustic people willing to improve the old venerable mxGraph library.
    I will check your personal repository on next week to better understand the technical changes you propose.
    Here are my 2 cents for the new mxgraph 😄

    As you say many of the examples set properties in the prototype of each class, and also frequently reference variables like graph.container. I've tried to convert many of the examples to use inheritance so they don't pollute the global namespaces, but my feeling is it may be best to keep things working the old way for at least a while until users of the library have had a chance to migrate over. (I'm mainly using inheritance there because of composition not currently being possible with how mxGraph et al are instantiated btw). It's tempting to go further in cleaning things up, but I think that way we would have more time to get feedback from people who will use the modified mxGraph with legacy codebase

    This is exactly what I had in mind: let's have a large goal for the mxGraph internals "be ready to change anything internally" but do it at a regular pace to avoid

    • spending months developing a new version without it being used
    • breaking the whole usage of the lib for existing users when it is ready

    Let's define the baby steps for the internal changes that will also bring new capabilities for new features like some already expressed in comments on this issue.

    As a mxGraph user, what I see in the first part of #8 (comment) (the list under 'Most of the changes I've made are things like') seems not a big deal and the changes I expect to have to manage are not too big as well.
    IMHO, it is ok to have to change the way the class are imported and the lib is instantiated (I will be so happy if we can remove all the globals and the way mxClient is spread all around), moving to ES6 classes neigher (I largely extend the mxGraph code in my current project, so I don't see it as an issue).

    In the first step, we should limit the public API changes (for instance, avoid rename, yes prefixing everything by mx is crappy, but we can live with it at the beginning) except the removal already discussed here.
    Anything else, like composition over inheritance, configuration changes, internal private class fields, .... should be done later

    About the class diagrams you want to create, I have found this old resources (I didn't check in details, so this may be useless): https://github.com/process-analytics/mxgraph2/tree/mxgraph-4_1_1/etc/diagrams

    mobile support
    The lib previously worked on mobile, so we should keep the support as well. The mobile browsers list to support should be reviewed I guess.

    typescript support
    As a mxGraph TypeScript user, having mxGraph written in TypeScript would be nice, but I am not sure it should be done as a first step. I don't have any idea of the effort needed to convert the new code into TS.
    But at least we could provide the TypeScript definitions.
    I guess we could benefit from the https://github.com/typed-mxgraph/typed-mxgraph experience (I am a contributor of this project) and insights typed-mxgraph/typed-mxgraph#12.
    The challenge we faced in typed-mxgraph with the legacy mxgraph codebase is that 'many properties are created on the fly on this' as @junsikshim noticed. Having the correct properties on types is a crafting work and we have missed a lot - most feedback we got from user is in this area.
    So without internal changes in the mxGraph codebase, generating the types could be challenging.

    documentation API generation
    According to an archive of the old mxGraph development repository (https://github.com/process-analytics/mxgraph2/blob/mxgraph-4_1_1/build.sh#L104), the API documentation was previously generated with https://www.naturaldocs.org/
    The https://jgraph.github.io/mxgraph/docs/js-api/files/index-txt.html page is generated from  https://github.com/jsGraph/mxgraph/tree/5dc3a07195313fd134bf8b058f4ae1d660202e07/javascript/src/js/index.txt
    This tool uses a uncommon format comparing to JSdoc which is supported by most IDE, so we may switch to another API documentation format.

    In https://github.com/typed-mxgraph/typed-mxgraph, we have started migrating the API documentation to TSDoc, which can produce html documentation with https://typedoc.org for instance.
    See https://tbouffard.github.io/typed-mxgraph/api/index.html (no typedoc configuration, this could be improved if needed).

    java and dotnet support
    IMHO, they should be removed from this repository and the code should be moved to dedicated repositories if someone is ready to maintain it. The java version hasn't been updated for a while. I personally only use it indirectly with tools like https://github.com/process-analytics/mxgraph-svg2shape or https://github.com/jgraph/svg2xml

  14. junsikshim commented on Apr 1, 2021

    @junsikshim
    Collaborator

    Great summary!
    I agree that it'd better to focus on reformatting the current code and keep breaking-changes minimal.

    As with mobile, documentation, java & dotnet support, I totally agree with @tbouffard.

    While it'd be great to have TS support, I think we should only provide the definitions. The more I look into the code, I feel like it would take months(if not impossible) to just get compiled with TS on :(

    Here are some other details I'm thinking about.

    • Support only svg. Then we can remove all vml/xml/html supports including (mxVmlCanvas2D, mxXmlCanvas2D, many methods and conditions and all the 'dialects'), but I'm not 100% sure if those are still needed in some cases.
    • Remove mxXmlRequest.
    • Remove mxResources. Do people use it?
    • Remove IE CSS filters.
    • Remove quirks mode support.

    I guess we got to set the browser support policy first, then other decisions will follow naturally. I think IE11+ would be ok, but wonder what people are expecting.

  15. mcyph commented on Apr 2, 2021

    @mcyph

    I've actually been making some pretty big changes in last few days which could have an impact on where to go from here, notably I've already converted a large % of the view, shape and some of the util modules to TypeScript. I was initially hesitant to using TypeScript but as a result of doing it and IDE hints I've already managed to spot quite a few inconsistencies in the documentation and code, and have been able to understand the way everything interrelates by knowing whether e.g. something returns a mxPoint or mxRectangle. It also has the advantage of enabling making sure classes such as mxCellRenderer don't set properties on other class instances like mxCell that aren't documented.

    I initially started experimenting with get/set class accessor methods in mxGraphView in the hope of adding some validation of the variables used by each class, but I'm no longer in favor of this idea, because it adds a lot of boilerplate and could break compatibility with some older code. I actually think that rewriting in TypeScript could take less time and result in higher quality overall, I think I'm only days away from getting to that stage. I don't think we need to rewrite everything in TypeScript though, it's mainly core things like the datatypes and mxGraph. Some SVG things have been tricky to convert, and converting mxGraph to TS has been challenging because of how large that file is (and in fact I'm not sure whether/whether not it's better to split that file up at this stage) but hoping can make it compile soon.

    • I'd already basically started removing IE CSS filters/vml/quirks support and have essentially been removing all non-SVG code. I think we should consider more tightly integrating SVG, as we may be able to support styles/filters and other things that previously weren't possible when supporting VML at the same time.

    • I've started removing accessing style values via mxConstants variables, instead favoring directly referencing the properties. My reasoning is that they're always the same and the names usually obvious so there's no need to refer to the keys externally. TypeScript can also enforce property setting/getting. For example, in mxShape:

      this.fill = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, this.fill);
      this.gradient = mxUtils.getValue(this.style, mxConstants.STYLE_GRADIENTCOLOR, this.gradient);
      this.gradientDirection = mxUtils.getValue(this.style, mxConstants.STYLE_GRADIENT_DIRECTION, this.gradientDirection);
      this.opacity = mxUtils.getValue(this.style, mxConstants.STYLE_OPACITY, this.opacity);

      becomes

      this.fill = ifNotNullElse(this.style.fillColor, this.fill)
      this.gradient = ifNotNullElse(this.style.gradientColor, this.gradient);
      this.gradientDirection = ifNotNullElse(this.style.gradientDirection, this.gradientDirection);
      this.opacity = ifNotNullElse(this.style.opacity, this.opacity);
    • I'm on the fence about whether to remove the mx prefix from everything. On the one hand I'm not too fussed by the mx prefix, but on the other it'd be nice to remove it as some IDEs like PyCharm/WebStorm complain with a red underline that "constructors should start with an upper case letter" and compatibility could be provided by import aliases e.g. import { Graph as mxGraph } from 'mxGraph/Graph' or import * from 'mxGraph/compat'

    • I've tested my previous changes (while the codebase was compiling) briefly on mobile and things should be OK. I don't think I've changed anything much that's likely to affect that, but I agree we should keep testing to make sure of this.

    • It might be a good idea to look at your TypeScript project @tbouffard and see whether we can use your definitions to check I've annotated everything correctly, and also maybe copy the docstrings across. I quite like the look of something like https://typedoc.org/ so it'd be good to both correct inconsistent docs+update it at the same time. I don't think it'll necessarily be essential to do this to get things to release (or at least "dev" or "testing") quality, but it'd certainly be a good idea to do it once typescript conversion is further along.

    I don't think this codebase is likely to be that unmaintainable going into the future, especially now most of it's been migrated away from prototypes+updated to newer syntax. I used to write code in the same sort of style/language features largely because of older JS+IE's limitations too, and it was very tricky to build on things, but JavaScript/ECMAScript and browsers have come a long way in the last few years. I think it would be feasible to keep this lib functional even with small updates, assuming standards like SVG don't have support removed/have backwards compatibility broken for some reason.

  16. 9 remaining items

  17. mcyph commented on Apr 9, 2021

    @mcyph

    @tbouffard I've auto-added most of the type annotations and JSDoc comments from the typed-mxgraph project. With a few exceptions (like mxUtils and mxConstants) I think it's worked for a majority of cases. I've put the type definition as a // ...-style comment underneath the docstring to allow easier checking of the converted .ts files, and hopefully also it can make things easier to convert for the .js files which haven't yet been converted to .ts. I'm actually pretty amazed how comprehensive the typed-mxgraph docs+types are!

  18. junsikshim commented on Apr 10, 2021

    @junsikshim
    Collaborator

    @mcyph How about pushing to a branch here so we can all work on it? Possibly starting with custom webpack settings instead of using next. The folders might have to be rearranged though (examples and so on.)

  19. mcyph commented on Apr 10, 2021

    @mcyph

    @junsikshim Will need to check whether I can be added as admin or have an admin create a branch here but yeah sure!

    Cleaning up the examples and removing react/next is a substantial task and is probably one of, if not the largest thing that still needs to be done. I won't have time for the next few weeks to do this, but I think it's worth noting the package.json for the react/next examples is in ./src/package.json, whereas the library itself is in ./package.json, which means that users of the library wouldn't need to download react/next.

    I started trying to remove react+next but needed to revert my changes so that I could work on refactoring the core part of mxGraph. I'm still not sure the best way of doing this - some of the most complex examples are in the ./docs/stashed directory and I don't know whether it would be best to get the rest of the examples working stably first, or whether there's some way of removing react first and still being able to debug+easily build on them. I think actually the biggest task is refactoring the examples and removing react shouldn't take as much time. If you'd like to work on this in the meantime that'd be great, but either way my goal still remains to remove react+next when it's practical to do so.

  20. junsikshim commented on Apr 10, 2021

    @junsikshim
    Collaborator

    @mcyph I think I can help to setup project and examples while you work on the core itself. I haven't looked at your refactored examples yet, but once the dev setup is complete, it'll be much easier to work with. Also, I think it's useful to have multiple versions(vanilla, react, etc.) of the same example probably with proper wrappers so people don't have to wrap them manually with refs. Anyway, let's put it into a branch somehow and begin working on it :)

  21. mcyph commented on Apr 10, 2021

    @mcyph

    @junsikshim Sounds great - I've added some explanations about how the examples are structured to https://github.com/mcyph/mxgraph/blob/master/src/pages/README.md, please let me know if there's anything you'd like me to clarify etc!

  22. mcyph commented on Apr 11, 2021

    @mcyph

    Currently there's a bug I'm having trouble tracking down where if you move the node/vertices they don't update the position of connected edges. I'm not sure whether it's because of a changed default argument or a different change. [EDIT: Fixed the bug, it turned out to be to do with the cell.invalidating variable not being reset in mxGraphView and not to do with this, but leaving the below here as it could have consequences in other situations]

    Supplying null won't go to a default anymore in most cases because of the functions using default arguments, e.g. previously code looked like this:

    function myFn(myArg) {
        myArg = myArg != null ? myArg : true;
    }

    Whereas now it looks like this with TypeScript/default arguments:

    function myFn(myArg: boolean=true) {
        ...
    }

    This could have further ramifications in some cases for existing codebases which expect null to use the default argument. I'm hoping there isn't too much code like this in the wild as default parameters are a lot cleaner but it's hard to say.

    One thing that's very tempting going forwards is to separate mxCell into different mxNode (or mxVertex) and mxEdge classes, as I think it would make things more idiomatic and allow putting edge- or node-specific functionality into the types. That may also break code, but it's hard to say how much because I think a lot of the time external code doesn't normally directly use mxCell.

  23. junsikshim commented on Apr 12, 2021

    @junsikshim
    Collaborator

    I agree that it'd better to separate mxCell into mxVertex and mxEdge(the handlers are already separated into mxVertexHandler and mxEdgeHandler). As @mcyph said, I also don't think it is a huge architectural change so it could be done in near future.

  24. mcyph commented on Apr 12, 2021

    @mcyph

    🤔 yeah the more I look at the codebase the more I feel that could be one of the best ways of making the source more easily navigable for new contributors and being able to build on things. It would have some effect on compatibility but it would probably only need relatively minor changes for those already using the library.

    I wonder whether mxCell and mxCellState should be merged prior to doing this, and the functions of mxGraphModel largely merged into either mxVertex or mxEdge too. In fact, a large number of the functions which take mxCell or mxCellState as their first parameter could be merged into the types and just create forwarding functions for back-compat in the original classes.

    I'm trying to figure out whether there's code where mxCell/mxCellState would need to be separate, like in the undoable transactions code, but even there I'm not sure and in those cases it might be possible to work around by cloning all the properties each time.

  25. junsikshim commented on Apr 12, 2021

    @junsikshim
    Collaborator

    I'm not sure where it was, but I think I read something like, mxCell is the actual data structure and mxCellState works like a cache. And when the change is not yet made(while dragging or something like that), only mxCellState is updated.

    So, since their roles are divided into a model and a view, I think it's better to keep them separated even if there are lots of overlapping features. I may be wrong as I don't have a thorough understanding of the architecture though.

  26. mcyph commented on Apr 12, 2021

    @mcyph

    Yes, I think you're right. The mxCell docs says it "represents the state of the groups, vertices and edges in a graph" and the mxCellState "represents the current state of a cell in a given mxGraphView", so it's sort of like the state of the cell states I guess 🤔 In that case maybe the cell states should be stored in the graph view??

    I've created a throwaway branch+organized all the files based on what the first parameter to each function is. I'm not sure what will come of this but essentially these classes seem like semi-singleton utility classes, and think in many cases they would be easier to work with if they had a mxCell or mxCellState associated with them as the first or last parameter of their constructor. (If it was the last, we could keep back-compat with the old way, though it wouldn't be the optimum having to pass null as the first param in every class call for new code.) I'm trying to think how this fits into the SOLID principles and what consequences this has for maintenance and understandability.

    image

  27. tbouffard commented on Dec 24, 2021

    @tbouffard
    MemberAuthor

    Closing
    Discussions continue in #18, #19, #41 and #51

  28. added this to the 0.1.0 milestone on Nov 16, 2022
  29. added
    question
    and removed
    chore
    on Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions