Commit Graph

16 Commits (c45b78a4daf526ef528239a9bda38133e869cbe7)

Author SHA1 Message Date
Thomas Bouffard c45b78a4da
test: check XML import/export of style.baseStyleNames (#315)
Ensure that the array is correctly converted.
2024-01-26 11:49:25 +01:00
Thomas Bouffard 835bfe7ce9
feat: allow to load an XML-stored model produced by `mxGraph` (#300)
Implementation relies on both the declaration of aliases and the
introduction of dedicated codecs.
`Codec.getCodecByName` now takes aliases into account, so that importing
is fully functional.
The code of some `CodecRegistry` and `Codec` methods has been simplified
(check for nullity of method parameters).

The cell style is converted thanks to a specific utility function that
can serve as an example for those wishing to migrate their applications
from mxGraph to maxGraph.

test
- The `Codec` example has been restored from the stashed directory. It
is now available as a story written in TypeScript.
- The `ModelChecker` utility class was previously used only to validate
the imported model after import from the maxGraph model. It is now
shared and also used in mxGraph import tests. It has also been enhanced
to check the total number of cells in the model.
2024-01-16 11:03:56 +01:00
Thomas Bouffard 77a7359985
fix: ensure decode works without encode first (#297)
Declare generic `ObjectCodec` for `Cell` properties that are defined as
XML node. Codecs are currently only registered automatically during
encode/export, so for now, they have to be registered to be available
during decode/import.

Also improve some methods signatures in base Codec objects (use specific
types instead of `any`).
2024-01-09 06:01:45 +01:00
Thomas Bouffard 99ffdfa29b
feat: add `ModelXmlSerializer` to import/export the model (#290)
This class was previously only available in test. It simplifies maxGraph
model import/export as:
  - it hides `Codec` and `HTMLElement` management
  - it registers codecs automagically
2023-12-18 15:53:43 +01:00
Thomas Bouffard f9b2d7d19a
refactor!: move codecs to dedicated files and reduce side effects (#289)
Previously, codec classes were defined and registered in the same file
as the class they targeted. This prevented efficient tree-shaking: as
soon as the target class was imported (e.g. `StyleSheet`), the
corresponding codec was also imported (`StyleSheetCodec`). As a result,
a large amount of codec code (and dependent code) was present in
applications incorporating maxGraph, even if they didn't use the codec
function. As there are currently many problems with the codec function
that make it almost unusable, this was a great waste.

Codecs are no longer registered by default, which reduces side effects
and coupling.
It also greatly improves tree-shaking.
For example, in the `ts-example` application included in this repository
which doesn't use the "codec" feature, the size of the minified
`maxGraph` chunk goes from `568.58 kB` to `467.90 kB`, which corresponds
to a size reduction of `17.7%`!


BREAKING CHANGE: Codecs supplied by `maxGraph` are no longer registered
by default. They MUST be registered before performing an `encode` or
`decode`. You can use one of the following functions to register codecs:
  - `registerAllCodecs`
  - `registerCoreCodecs`
  - `registerEditorCodecs`
2023-12-13 17:39:40 +01:00
Thomas Bouffard 871e1c37d5
test: refactor graph initialization (#288)
Use the graph initialization util function in the "serialization" tests.
2023-12-11 08:54:15 +01:00
Thomas Bouffard ffd5036054
fix(robustness): prevent errors when a plugin is not loaded (#272)
Add guards to prevent accessing properties and methods on undefined
instances when a plugin is not loaded.
Also fix and improve the JSDoc of the `EdgeHandler` and `Guide` classes.
2023-12-07 16:10:33 +01:00
Thomas Bouffard 54c82230c1
test: improve HierarchicalLayout tests (#245)
Also check that the layout change the position of the cells.
2023-10-10 06:21:22 +02:00
Franz Ritter efb5b4bdf9
fix: allow `HierarchicalLayout` to manage circular dependencies (#233)
Uncomment the isAncestor method GraphHierachyNode, which is used by
HiearchlLayout. The uncommented implementation makes sure, that a
circular dependency is detected and resolved. Using the default
isAncestor does not work at this point, because the parent nodes of the
child nodes in the graph are not set.

The problem was unintentionally introduced during the initial refactoring of
the mxGraph code in 413796a.
The idea of the author was to remove an useless comment but they left an
extra /** behind which commented the isAncestor method.
2023-09-14 14:49:07 +02:00
Thomas Bouffard e82abd6da3
feat: improve the EdgeMixin type (#212)
The methods defined in the `EdgeMixin` type were not documented.
The signature of the `insertEdge` method was using a spread `any`
parameter, so it provided no guidance nor guard.
Instead, the type now declares the various form of the methods with the
right signature.
2023-07-07 07:56:01 +02:00
Thomas Bouffard cdd8830b5c
feat: improve the VertexMixin type (#211)
The methods defined in the `VertexMixin` type were not documented.
The signature of the `insertVertex` method was using a spread `any`
parameter, so it provided no guidance nor guard.

Instead, the type now declares the various form of the methods with the
right signature.
2023-07-07 07:41:49 +02:00
Thomas Bouffard 193d4bfe9b
test: introduce tests for model encode/decode (#183)
The code managing the "model encode/decode" is not yet fully
operational.
This set of changes adds tests to replicate current behavior and provide
the infrastructure for problem resolution. In particular, the tests show
that some errors occur on import because some Codecs are not registered.
There is no error if an export has already been performed.

**Other info**
The tests are done using both the model alone or a model linked to a
Graph instance.
Using only the model shows that some properties of objects in the model
are not set correctly: they are not decoded and are stored as `Element`
instances.
The test involving the Graph instance shows the behavior seen in "real"
application which are the consequences of the issue during the import.
2023-04-04 09:28:13 +02:00
Thomas Bouffard 6fc05a3876
refactor: simplify fontStyle code checking binary mask (#174)
Introduce the `styleUtils.matchBinaryMask` function to remove
duplication in the code checking binary mask on `fontStyle`.
2023-01-17 12:08:32 +01:00
Thomas Bouffard 5c53465c8e
fix: improve style configuration extensibility (#163)
The type of the `endArrow`, `startArrow` and `shape` properties in
`CellStateStyle` were too strict. They prevented to
use custom registered shapes in the style configuration without using a
cast.

Markers of the arrow and custom shapes can be registered by using
methods in `MarkerShape` and `CellRenderer` respectively.
The key to identify the shapes is a string so the types of the
properties in `CellStateStyle` now allow `string` as well.
These offer both the type guidance for standard maxGraph registered
shapes (via a dedicated type) and the extensibility
for custom shapes.
2023-01-06 10:52:53 +01:00
Thomas Bouffard 5a346079b5
fix: consider default style when computing effective style properties (#152)
`StyleSheet.getCellStyle` didn't keep the properties of the default
style when `baseStyleNames` was set in the `cellStyle` parameter.

The JSDoc was incorrect (it came from mxGraph) about how the style is
computed, in particular about the default style. It probably leads to
the erroneous implementation during migration. It is now fixed and
clearly describe the rules followed to merge style properties.

The 'Stylesheet' story has been updated to correctly use the maxGraph
API. It also includes more examples involving `baseStyleNames` to
show the 'properties merge' in action.
2022-12-17 09:16:26 +01:00
Thomas Bouffard b7a322b36f
fix: CellOverlay constructor use all parameters to set properties (#159)
The `align` and `verticalAlign` values passed to the constructor weren't
set, so the overlay position was always set to
the default one.

The `align` and `verticalAlign` properties are now using the AlignValue
and VAlignValue types respectively instead of
defining inline types. This improves the consistent in the whole code.

To demonstrate the fix, the Overlays story now set 'align' and
'verticalAlign' randomly.


Also introduce `jest` to test the fix and the whole
implementation of the changed method. Types check support is provided by
`ts-jest`. As maxGraph uses a lot of browser objects, also setup
`jest-jsdom-environment`.
2022-12-16 16:51:51 +01:00