-
Notifications
You must be signed in to change notification settings - Fork 200
Fixes the 'Anchors' example. #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ javascript/dist | |
| .jshintrc | ||
| javascript/examples/**/dist | ||
| .idea/ | ||
| .vscode/ | ||
| *.iml | ||
| dist | ||
| package-lock.json | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare module '*.gif'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ import ConnectionConstraint from '../other/ConnectionConstraint'; | |
| import Point from '../geometry/Point'; | ||
| import Cell from '../cell/Cell'; | ||
|
|
||
| import pointImg from '../../../images/point.gif'; | ||
|
|
||
| /** | ||
| * Handles constraints on connection targets. This class is in charge of | ||
| * showing fixed points when the mouse is over a vertex and handles constraints | ||
|
|
@@ -38,7 +40,7 @@ class ConstraintHandler { | |
| * {@link Image} to be used as the image for fixed connection points. | ||
| */ | ||
| // pointImage: mxImage; | ||
| pointImage = new Image(`${Client.imageBasePath}/point.gif`, 5, 5); | ||
| pointImage = new Image(pointImg, 5, 5); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd better to provide a way to overwrite those images by adding some parameters to Graph. constructor({
container: ...,
model: ...,
plugins: ...,
stylesheet: ...,
resources: {
ConnectionPointImageUrl: ...
}
})Then, the users can provide their own images while the default images are also available. Let me know what you think!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this will be a better way. This can apply to other images referenced within the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we wanted to be (reasonably) back-compatible, we could set I feel more generally, it would be nice to allow setting specific user subclasses of handlers to a graph so that you could have different settings for different graphs on the same page. While subclasses might be a verbose solution, it at least is fairly consistent and haven't yet been able to think of a better solution.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is best to stay away from global configuration(the previous way) since it is separated from the actual Graph instantiation. When we want to create multiple different graphs on the same page, there has to be separate <script> tags containing I agree with @tbouffard that this should be an another topic. I'll merge this PR first, and let's discuss on this somewhere else. |
||
|
|
||
| /** | ||
| * Reference to the enclosing {@link mxGraph}. | ||
|
|
@@ -81,8 +83,8 @@ class ConstraintHandler { | |
| // Adds a graph model listener to update the current focus on changes | ||
| this.resetHandler = () => { | ||
| if ( | ||
| this.currentFocus != null && | ||
| this.graph.view.getState(this.currentFocus.cell) == null | ||
| this.currentFocus && | ||
| !this.graph.view.getState(this.currentFocus.cell) | ||
| ) { | ||
| this.reset(); | ||
| } else { | ||
|
|
@@ -211,15 +213,15 @@ class ConstraintHandler { | |
|
|
||
| // Gets cell under actual point if different from event location | ||
| if ( | ||
| cell == null && | ||
| point != null && | ||
| !cell && | ||
| point && | ||
| (me.getGraphX() !== point.x || me.getGraphY() !== point.y) | ||
| ) { | ||
| cell = this.graph.getCellAt(point.x, point.y); | ||
| } | ||
|
|
||
| // Uses connectable parent vertex if one exists | ||
| if (cell != null && !cell.isConnectable()) { | ||
| if (cell && !cell.isConnectable()) { | ||
| const parent = cell.getParent(); | ||
|
|
||
| if (parent && parent.isVertex() && parent.isConnectable()) { | ||
|
|
@@ -246,7 +248,7 @@ class ConstraintHandler { | |
| ) { | ||
| if (this.isEnabled() && !this.isEventIgnored(me)) { | ||
| // Lazy installation of mouseleave handler | ||
| if (this.mouseleaveHandler == null && this.graph.container != null) { | ||
| if (!this.mouseleaveHandler && this.graph.container ) { | ||
| this.mouseleaveHandler = () => { | ||
| this.reset(); | ||
| }; | ||
|
|
@@ -255,8 +257,8 @@ class ConstraintHandler { | |
| } | ||
|
|
||
| const tol = this.getTolerance(me); | ||
| const x = point != null ? point.x : me.getGraphX(); | ||
| const y = point != null ? point.y : me.getGraphY(); | ||
| const x = point ? point.x : me.getGraphX(); | ||
| const y = point ? point.y : me.getGraphY(); | ||
| const grid = new Rectangle(x - tol, y - tol, 2 * tol, 2 * tol); | ||
| const mouse = new Rectangle( | ||
| me.getGraphX() - tol, | ||
|
|
@@ -270,8 +272,8 @@ class ConstraintHandler { | |
| // Keeps focus icons visible while over vertex bounds and no other cell under mouse or shift is pressed | ||
| if ( | ||
| !this.isKeepFocusEvent(me) && | ||
| (this.currentFocusArea == null || | ||
| this.currentFocus == null || | ||
| (!this.currentFocusArea || | ||
| !this.currentFocus || | ||
| state || | ||
| !this.currentFocus.cell.isVertex() || | ||
| !intersects(this.currentFocusArea, mouse)) && | ||
|
|
@@ -289,9 +291,9 @@ class ConstraintHandler { | |
| let tmp; | ||
|
|
||
| if ( | ||
| this.focusIcons != null && | ||
| this.constraints != null && | ||
| (state == null || this.currentFocus === state) | ||
| this.focusIcons.length > 0 && | ||
| this.constraints && | ||
| (!state || this.currentFocus === state) | ||
| ) { | ||
| const cx = mouse.getCenterX(); | ||
| const cy = mouse.getCenterY(); | ||
|
|
@@ -303,9 +305,9 @@ class ConstraintHandler { | |
|
|
||
| if ( | ||
| (this.intersects(this.focusIcons[i], mouse, source, existingEdge) || | ||
| (point != null && | ||
| (point && | ||
| this.intersects(this.focusIcons[i], grid, source, existingEdge))) && | ||
| (minDistSq == null || tmp < minDistSq) | ||
| (minDistSq === null || tmp < minDistSq) | ||
| ) { | ||
| this.currentConstraint = this.constraints[i]; | ||
| this.currentPoint = this.focusPoints[i]; | ||
|
|
@@ -316,7 +318,7 @@ class ConstraintHandler { | |
| tmp.width -= 1; | ||
| tmp.height -= 1; | ||
|
|
||
| if (this.focusHighlight == null) { | ||
| if (!this.focusHighlight) { | ||
| const hl = this.createHighlightShape(); | ||
| hl.dialect = DIALECT.SVG; | ||
| hl.pointerEvents = false; | ||
|
|
@@ -325,7 +327,7 @@ class ConstraintHandler { | |
| this.focusHighlight = hl; | ||
|
|
||
| const getState = () => { | ||
| return this.currentFocus != null ? this.currentFocus : state; | ||
| return this.currentFocus ? this.currentFocus : state; | ||
| }; | ||
|
|
||
| InternalEvent.redirectMouseEvents(hl.node, this.graph, getState); | ||
|
|
@@ -337,7 +339,7 @@ class ConstraintHandler { | |
| } | ||
| } | ||
|
|
||
| if (this.currentConstraint == null) { | ||
| if (!this.currentConstraint) { | ||
| this.destroyFocusHighlight(); | ||
| } | ||
| } else { | ||
|
|
@@ -354,9 +356,9 @@ class ConstraintHandler { | |
| */ | ||
| redraw() { | ||
| if ( | ||
| this.currentFocus != null && | ||
| this.constraints != null && | ||
| this.focusIcons != null | ||
| this.currentFocus && | ||
| this.constraints && | ||
| this.focusIcons.length > 0 | ||
| ) { | ||
| const state = this.graph.view.getState(this.currentFocus.cell) as CellState; | ||
| this.currentFocus = state; | ||
|
|
@@ -423,12 +425,12 @@ class ConstraintHandler { | |
| icon.init(this.graph.getView().getDecoratorPane()); | ||
|
|
||
| // Move the icon behind all other overlays | ||
| if (icon.node.previousSibling != null) { | ||
| if (icon.node.previousSibling) { | ||
| icon.node.parentNode?.insertBefore(icon.node, icon.node.parentNode.firstChild); | ||
| } | ||
|
|
||
| const getState = () => { | ||
| return this.currentFocus != null ? this.currentFocus : state; | ||
| return this.currentFocus ? this.currentFocus : state; | ||
| }; | ||
|
|
||
| icon.redraw(); | ||
|
|
@@ -480,7 +482,7 @@ class ConstraintHandler { | |
| this.graph.view.removeListener(this.resetHandler); | ||
| this.graph.removeListener(this.resetHandler); | ||
|
|
||
| if (this.mouseleaveHandler != null && this.graph.container != null) { | ||
| if (this.mouseleaveHandler && this.graph.container) { | ||
| InternalEvent.removeListener( | ||
| this.graph.container, | ||
| 'mouseleave', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ This restores the original mxGraph style value. This will help people migrating from mxGraph.
Original mxGraph code: https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/util/mxConstants.js#L1796