-
Notifications
You must be signed in to change notification settings - Fork 419
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
Improve search in large diagrams #931
Changes from all commits
58e3a20
12fea64
9e36453
1f93932
2612d06
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 |
---|---|---|
|
@@ -867,6 +867,25 @@ describe('Canvas', function() { | |
})); | ||
|
||
|
||
it('should return copy of viewbox', inject(function(canvas) { | ||
|
||
// given | ||
canvas.addShape({ id: 's0', x: 0, y: 0, width: 300, height: 300 }); | ||
|
||
var shape = canvas.addShape({ id: 's1', x: 10000, y: 0, width: 300, height: 300 }); | ||
|
||
var viewbox = canvas.viewbox(), | ||
viewboxStringified = JSON.stringify(viewbox); | ||
|
||
// when | ||
canvas.scrollToElement(shape); | ||
|
||
// then | ||
expect(JSON.stringify(viewbox)).to.eql(viewboxStringified); | ||
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 don't understand the test either 🙈. If we want the to verify "no identity", why don't we test for "not equal"? 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'm testing whether the viewbox I got from calling 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. A much simpler test would be:
But
? |
||
expect(JSON.stringify(canvas.viewbox())).not.to.eql(viewboxStringified); | ||
})); | ||
|
||
|
||
it('should provide default viewbox / overflowing diagram', inject(function(canvas) { | ||
|
||
// given | ||
|
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.
What is the issue here, could you elaborate? To me this looks like a hack. The cached viewbox, after all, should not be fiddled with.
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.
The problem is when you return a reference to the viewbox to the caller of
viewbox()
they will assume that it's not going to be mutated. This is an issue I ran into. I calledviewbox()
to then used the viewbox at a later point just to realize it had been changed.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.
BTW there is a dedicated API for deep cloning: https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
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.
Could be a follow-up improvement.
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.
Simple clone:
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.
If this needs to return a copy, a shallow clone won't work due to nested objects (
inner
and friends).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.
I'll need to figure why this needs a copy in the first place. We always construct a fresh viewbox., and the cached viewbox is not to be fiddled with.
@philippfromme Still looking for a concrete scenario where users would mutate the viewbox, and would love to see that as a test.
To prevent mutation (which does not make sense anyway), we can freeze the object, too.