Skip to content
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

Merged
merged 5 commits into from
Sep 25, 2024
Merged

Improve search in large diagrams #931

merged 5 commits into from
Sep 25, 2024

Conversation

philippfromme
Copy link
Contributor

@philippfromme philippfromme commented Sep 23, 2024

Proposed Changes

  • do not set zoom to 1
  • reduce padding below search
  • add custom marker to preselected element

Related to bpmn-io/bpmn-js#2233
Related to camunda/camunda-modeler#4538

brave_cwSIL4Oz5C

Checklist

To ensure you provided everything we need to look at your PR:

  • Brief textual description of the changes present
  • Visual demo attached
  • Steps to try out present, i.e. using the @bpmn-io/sr tool
  • Related issue linked via Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}

@nikku
Copy link
Member

nikku commented Sep 25, 2024

Try out via

npx @bpmn-io/sr bpmn-io/bpmn-js -l bpmn-io/diagram-js#search-improvements-next

Copy link
Member

@nikku nikku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well. Thanks for following up.

@nikku nikku merged commit 430bc0a into develop Sep 25, 2024
8 of 10 checks passed
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Sep 25, 2024
@nikku nikku deleted the search-improvements-next branch September 25, 2024 16:47
@@ -1153,7 +1153,7 @@ Canvas.prototype._viewboxChanged = function() {
Canvas.prototype.viewbox = function(box) {

if (box === undefined && this._cachedViewbox) {
return this._cachedViewbox;
return JSON.parse(JSON.stringify(this._cachedViewbox));
Copy link
Member

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.

Copy link
Contributor Author

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 called viewbox() to then used the viewbox at a later point just to realize it had been changed.

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple clone:

{ ...viewbox }

Copy link
Member

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).

Copy link
Member

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.

canvas.scrollToElement(shape);

// then
expect(JSON.stringify(viewbox)).to.eql(viewboxStringified);
Copy link
Member

Choose a reason for hiding this comment

The 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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing whether the viewbox I got from calling viewbox() has been changed. If you remove the JSON.parse(JSON.stringify()) part you'll see the test failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A much simpler test would be:

// mind the "strict object equality"
expect(canvas.viewbox()).not.to.equal(canvas.viewbox())

But

// mind the loose object comparison
expect(canvas.viewbox()).to.eql(canvas.viewbox());

?

@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Sep 26, 2024
@nikku
Copy link
Member

nikku commented Sep 26, 2024

@GeethaParthasarathy FYI :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Review pending
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants