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

Rewrite bucket-generating logic #2647

Merged
merged 1 commit into from
Oct 21, 2020
Merged

Rewrite bucket-generating logic #2647

merged 1 commit into from
Oct 21, 2020

Conversation

lyzadanger
Copy link
Contributor

@lyzadanger lyzadanger commented Oct 19, 2020

This draft PR demonstrates an approach to refactoring reimplements the logic used to compute and position anchor buckets in the bucket bar. It does not yet have tests.

It is my hope that this re-implementation will be more comprehensible to future devs, provide a clearer separation of concerns and more clearly express the desired outcome of the bucketing logic.

It:

  • Removes the weird empty extra buckets
  • Redefines types in buckets util in a way that feels more intuitive
  • Moves some positioning "logic" into CSS
  • Removes the need for BucketBar to maintain (and export) constants
  • Fixes this bug

The resulting buckets are very close to what the previous algorithm created, minus the knack for sometimes putting anchors into multiple buckets (bug #397).

There's probably one more follow-up pass to rectify a few lingering...interesting features of the code...but this is feeling better...

Fixes #2618
Fixes #397

{ anchors: below, position: window.innerHeight - BUCKET_NAV_SIZE + 1 },
{ anchors: [], position: window.innerHeight }
);
this.buckets = anchorBuckets(this.annotator.anchors);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhh this feels better.

const anchorCount = this.buckets[index].anchors.length;
// Positioning logic currently _relies_ on their being interstitial
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh, this also feels better.

});
}

isUpper(i) {
return i === 1;
return i === 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Make these methods unnecessary

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

This is a great improvement! I left some minor feedback on the details.

below: Array.from(belowScreenAnchors),
points,
};
return anchorPositions;
Copy link
Member

Choose a reason for hiding this comment

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

You could write this function as one filter/map/sort chain. I'd be fine with it either way.

@lyzadanger
Copy link
Contributor Author

@robertknight I've pushed a commit that integrates your initial feedback, most materially fixing the ickiness of the internal bucket-building function formerly known as _nextBucket

@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #2647 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2647      +/-   ##
==========================================
+ Coverage   97.70%   97.72%   +0.02%     
==========================================
  Files         200      200              
  Lines        7548     7527      -21     
  Branches     1659     1651       -8     
==========================================
- Hits         7375     7356      -19     
+ Misses        173      171       -2     
Impacted Files Coverage Δ
src/annotator/plugin/bucket-bar.js 100.00% <100.00%> (ø)
src/annotator/util/buckets.js 100.00% <100.00%> (+2.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1628a11...7f6d011. Read the comment docs.

@lyzadanger lyzadanger changed the title WIP: Rewrite bucket-generating logic Rewrite bucket-generating logic Oct 20, 2020
@lyzadanger lyzadanger marked this pull request as ready for review October 20, 2020 18:23
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

LGTM. This is a huge improvement over the version on master. I requested some minor changes, after which this is good to merge. Give me a shout if you have a query about any of those.

The existing CSS structure is fiddly to understand due to use of ::before and ::after to create the arrows and the amount of overriding of properties that happens to style the .upper and .lower indicators. At least it is self-contained though and we can revisit that later.

Restructure the way that buckets are generated and represented. Simplify
what `BucketBar` needs to do with the buckets. Fix a bug in which
anchors can be occasionally included in multiple buckets.

Fixes #397
Fixes #2618
@lyzadanger lyzadanger merged commit d2f8816 into master Oct 21, 2020
@lyzadanger lyzadanger deleted the refactor-bucketing branch October 21, 2020 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants