GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refactor Graph class and mixins to improve modularity and tree-shaking · Issue #762 · maxGraph/maxGraph

Refactor Graph class and mixins to improve modularity and tree-shaking #762

New issue
Copy link
New issue
Copy link
Open
Enhancement
Open
Refactor Graph class and mixins to improve modularity and tree-shaking#762
Enhancement
Copy link
Assignees
tbouffard

Description

@tbouffard
tbouffard
opened on Apr 14, 2025
Issue body actions

Is your feature request related to a problem? Please describe

The Graph class is currently the central point of maxGraph (version 0.17.0), containing numerous functionalities. This setup prevents optional features from being loaded only when needed, which negatively impacts tree-shaking and performance.

Additionally, several methods in the Graph class are only used by plugins or other specific components but are still always bundled due to their location. This approach, inherited from mxGraph for easier migration, makes Graph a "God Object" and blurs responsibility boundaries.

Describe the solution you'd like

We want to clarify responsibilities and improve tree-shaking efficiency by relocating methods from the Graph class and its mixins to the specific plugins or classes where they are actually used. This may involve creating new plugins, moving existing methods, and possibly removing unused or deprecated ones.

Warning

This will introduce breaking changes, but the long-term benefits in modularity and performance make it worthwhile.

Proposed changes

Note

This list is not exhaustive.

✔ FitPlugin (Graph.fit)

  • Move Graph.fit to a new FitPlugin.
  • Related PR: #734
  • Available in 0.21.0

FoldingMixin

  • Remove the mixin.
  • Move its methods to a new dedicated plugin.
  • Relocate related Graph.options properties.

✔️ ImageMixin

  • See refactor!: convert ImageMixin to ImageBundlePlugin #1050
  • Available in 0.24.0

OverlaysMixin

  • Move the getCellOverlays to AbstractGraph. This is an extension point to eventually override the result of cell.overlays. The JSDoc of this method should be improved to mention that
  • Move properties from AbstractGraph to the new Plugin. Related getter/setter could be remove
    • warningImage

PanningMixin

  • Evaluate which methods are used only by PanningHandler and move them there.
  • Move appropriate methods to a new ScrollPlugin (see below).
  • The remaining methods may be moved to a separate plugin.

PageBreaksMixin

  • Evaluate page break-related properties currently defined directly in Graph.
  • Move updatePageBreaks (only used by EventsMixin) accordingly. See also sizeDidChange.

ScrollPlugin

  • Introduce a new plugin with id scroll.
  • Move the following methods:
    • From PanningMixin:
      • scrollCellToVisible
      • scrollRectToVisible
    • From Graph:
      • scrollPointToVisible (evaluate its impact before moving)
      • center

✔ TooltipMixin

  • Move getTooltip and getTooltipForCell to the TooltipHandler plugin.
  • Decide whether to remove or relocate setTooltips (likely remove).
  • Related PR: #640

Available in 0.23.0

ValidationMixin

  • This mixin is quite independent and currently uses browser alerts.
  • Consider replacing alerts with a custom logger in the Validation story.
  • Move allowLoops (and its getter/setter) here in preparation for future extraction.
  • Move properties from AbstractGraph to the new Plugin. Related getter/setter could be remove
    • alreadyConnectedResource
    • containsValidationErrorsResource
    • multiplicity
  • ⚠️ Some methods depends on the OverlaysMixin which is planned to be converted to Plugin
  • Proposed plugin id: connection-validation (find a place to document that plugin id convention for maxGraph builtin plugins is kebab-case, nums only)

Note: the method ConnectionsMixin.isValidConnection (and some methods it uses) is only used by ValidationMixin. So, the related code could be moved to the new plugin as well.

ZoomMixin

  • Create a ZoomPlugin (id zoom) and move all methods from this mixin.
  • This plugin will depend on ScrollPlugin, as zoom features require scroll capabilities. Document this dependency.

✔️ Edge and Vertex handler factory methods

See #823

maxGraph lets you perform actions on cells when they are selected. This is orchestrated by the SelectionCellsHandler plugin, which currently relies on Graph methods to create dedicated handlers for edges and vertices. This indirection comes from mxGraph and is still in place to ease migration.

If an application doesn't require selection actions (e.g., viewer-only mode), the plugin can be removed (see #432). However, EdgeHandler and VertexHandler classes remain imported because they are still defined in Graph.

  • Move these methods to the SelectionCellsHandler plugin.
  • This change can significantly reduce bundle size. Experimentation shows that the decrease could be about 65 kB (see PR #449).
  • Update stories to override plugin methods instead of the Graph.createHandler method:
    • ContextIcons → override createVertexHandler
    • Wires → override createEdgeHandlerInstance

Other refactorings

  • Continue reducing the size and responsibility of the Graph class:
    • Move methods used by a single component directly into that component:
      • Graph.isOrthogonal → move to GraphView as it is only used in GraphView.getFloatingTerminalPoint
      • Graph.defaultLoopStyle → move to GraphView as it is only used in GraphView.getEdgeStyle (see Make Graph.defaultLoopStyle configurable with a registered EdgeStyle string #758)

Describe alternatives you've considered

  • Keep current structure to ease mxGraph migration — dismissed due to tree-shaking and modularity issues.
  • Gradually refactor over several releases to reduce migration burden.

Additional context

  • This refactor introduces breaking changes and should be documented in the migration guide.
  • It aligns with long-term goals: improved modularity, better maintainability, and smaller builds.

Activity

  1. tbouffard
    added
    enhancementNew feature or request
    on Apr 14, 2025
  2. tbouffard
    added the
    Enhancement
    issue type on Apr 14, 2025
  3. tbouffard
    added a parent issue on Apr 14, 2025
    • Strategies for Further Tree-Shaking Improvements #665
  4. tbouffard
    removed
    enhancementNew feature or request
    on May 15, 2025
  5. tbouffard
    self-assigned this
    on Dec 22, 2025
  6. redfish4ktc
    added a commit that references this issue on Aug 10, 2026

    docs: add ADRs on mixins, plugins and moving members out of AbstractG…

    3cf3fda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tbouffard
    tbouffard

Labels

No labels
No labels

Type

Enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.