-
Notifications
You must be signed in to change notification settings - Fork 194
Description
In maxGraph 0.8.0, the enums are declared as "const enum" and it causes interoperability issues. See #205.
These enums have been migrated from mxGraph value objects that were used to provide completion as mxGraph didn't provide types.
My Proposal
Most of the time, we could use const object instead: https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
In addition, a lot of these "enums" could be removed IMHO as their values are already provided by dedicated types. Most IDEs allow you to use values directly when defining associated properties.
So, we could remove most of them.
List of const enums
All existing "enum" are located in the Constants.ts file.
Analysis done for commit 4526986 (v0.2.1).
Most existing types linked to "const enums" use the "Value" postfix. The removal of some "enums" require to add new types. We could reuse this convention for the new types for consistency.
✔ To remove
✔ ALIGN
This is a mix of both vertical and horizontal alignment.
The values are already available with the AlignValue
and VAlignValue
types.
See #798
✔ ARROW
The enum is not used for edge marker registration in MarkerShape.addMarker
.
Everywhere else (examples, marker definition), the ArrowValue
type can already be used, for instance, when setting CellStateStyle.endArrow
.
✔ DIALECT
A Type already exists as an inline type in Graph.dialect
. We should extract it and reuse it as DialectValue
for instance.
Other places where dialect is used
- CellStateStyle: dialect property
- Shape: dialect: string | null = null;
See #800
✔ DIRECTION
There are a lot of places where the DirectionValue
type should be used instead
In particular, in CellStateStyle
properties related to 'ports'. The only properties using enum instead of types (DirectionValue here).
See #799
Some functions rely on the enum values to look for substrings. Using the type value should not change anything
- mathUtils.getPortConstraints: see feat: CellStateStyle port constraints accept multiple DirectionValue #721
✔ EDGESTYLE
The name came from mxGraph. If we keep this enum, it should be EDGE_STYLE
for consistency with the rest of the code.
We could remove it and introduce an EdgeStyleValue
type.
In the CellStateStyle
type, we could declare the edgeStyle
property as EdgeStyleValue | string
✔ ELBOW
Can be replaced by a type.
Used in ElbowConnector
and ElbowEdgeHandler
In the CellStateStyle
type, we could declare the elbow
property as ElbowStyleValue | string
See #801
✔ PERIMETER
Only used to register perimeter in StyleRegistry.putValue
.
Introduce a PerimeterValue type.
Update the method to make it accept a PerimeterValue
parameter.
Also make CellStateStyle.perimeter
accept the PerimeterValue
type
✔ RENDERING_HINT
Not used in the code
See #798
✔ SHAPE
The only place where it is used and don't rely on type is when registering shapes in CellRenderer.registerShape
.
Update the method to take a ShapeValue | string
parameter.
✔ TEXT_DIRECTION
Can be replaced by the usage of the TextDirectionValue type.
TextDirectionValue is already used in CellStateStyle.textDirection
, in the TextShape
constructor and in other classes.
Constants.DEFAULT_TEXT_DIRECTION should an enum value if we keep the enum
See #799
✔ To Keep with change
✔ CURSOR
It's more a global config object to know which cursor use for various elements/actions.
Switch from an enum to an object value as we are not using the enum to enumerate its values and as the cursors should be configurable.
If this is a Global Config object, it should be out of the constants namespace and a reset function should be created for consistency with other global configuration objects.
See #806
✔ DIRECTION_MASK
It is already an value object.
Its properties should be marked as read-only.
See #803
✔ FONT
Act as a binary mask. Switch to object value.
Its properties should be marked as read-only.
Rename to FONT_MASK or FONT_STYLE_MASK
- FONT_STYLE to make the intent more explicit
- postfix with _MASK for consistency with DIRECTION_MASK
See #804
✔ NODETYPE
The enum value relates to the value of Element.nodeType
We are not using the enum to enumerate its values, so it can be replaced by a const object
Notice that some entries are not used. We can keep them to avoid introducing new breaking changes with the former mxGraph implementation.
It could be renamed to NODE_TYPE for consistency with the rest of the code
See #802