Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
9c82dbd0
Commit
9c82dbd0
authored
Oct 05, 2020
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Oct 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move bucket utilities module into util dir
parent
6f846ffb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
bucket-bar.coffee
src/annotator/plugin/bucket-bar.coffee
+1
-1
buckets.js
src/annotator/util/buckets.js
+9
-9
buckets-test.js
src/annotator/util/test/buckets-test.js
+5
-4
No files found.
src/annotator/plugin/bucket-bar.coffee
View file @
9c82dbd0
...
...
@@ -3,7 +3,7 @@ $ = require('jquery')
scrollIntoView
=
require
(
'scroll-into-view'
)
{
findClosestOffscreenAnchor
,
constructPositionPoints
,
buildBuckets
}
=
require
(
'.
/bucket-bar-j
s'
)
{
findClosestOffscreenAnchor
,
constructPositionPoints
,
buildBuckets
}
=
require
(
'.
./util/bucket
s'
)
highlighter
=
require
(
'../highlighter'
)
...
...
src/annotator/
plugin/bucket-bar-j
s.js
→
src/annotator/
util/bucket
s.js
View file @
9c82dbd0
...
...
@@ -5,7 +5,7 @@ import { getBoundingClientRect } from '../highlighter';
*/
/**
* A
structured Array
representing either the top (`startOrEnd` = 1) or the
* A
tuple
representing either the top (`startOrEnd` = 1) or the
* bottom (`startOrEnd` = -1) of an anchor's highlight bounding box.
*
* @typedef {[pixelPosition: number, startOrEnd: (-1 | 1), anchor: Anchor]} PositionPoint
...
...
@@ -98,7 +98,7 @@ export function findClosestOffscreenAnchor(anchors, direction) {
export
function
constructPositionPoints
(
anchors
)
{
const
aboveScreenAnchors
=
new
Set
();
const
belowScreenAnchors
=
new
Set
();
const
points
=
/** @type {PositionPoint[]} */
(
new
Array
()
);
const
points
=
/** @type {PositionPoint[]} */
(
[]
);
for
(
let
anchor
of
anchors
)
{
if
(
!
anchor
.
highlights
?.
length
)
{
...
...
@@ -147,14 +147,14 @@ export function constructPositionPoints(anchors) {
* @return {BucketInfo}
*/
export
function
buildBuckets
(
points
)
{
const
buckets
=
/** @type {Array<Anchor[]>} */
(
new
Array
()
);
const
bucketPositions
=
/** @type {number[]} */
(
new
Array
()
);
const
buckets
=
/** @type {Array<Anchor[]>} */
(
[]
);
const
bucketPositions
=
/** @type {number[]} */
(
[]
);
// Anchors that are part of the currently-being-built bucket, and a correspon-
// ding count of unclosed top edges seen for that anchor
const
current
=
/** @type {{anchors: Anchor[], counts: number[] }} */
({
anchors
:
new
Array
()
,
counts
:
new
Array
()
,
anchors
:
[]
,
counts
:
[]
,
});
points
.
forEach
((
point
,
index
)
=>
{
...
...
@@ -223,12 +223,12 @@ export function buildBuckets(points) {
// from the buckets collection, and re-add 1 merged bucket (always)
// Always pop off the last bucket
const
ultimateBucket
=
buckets
.
pop
()
||
new
Array
()
;
const
ultimateBucket
=
buckets
.
pop
()
||
[]
;
// If there is a previous/penultimate bucket, pop that off, as well
let
penultimateBucket
=
new
Array
()
;
let
penultimateBucket
=
[]
;
if
(
buckets
[
buckets
.
length
-
1
]?.
length
)
{
penultimateBucket
=
buckets
.
pop
()
||
new
Array
()
;
penultimateBucket
=
buckets
.
pop
()
||
[]
;
// Because we're removing two buckets but only re-adding one below,
// we'll end up with a misalignment in the `bucketPositions` collection.
// Remove the last entry here, as it corresponds to the ultimate bucket,
...
...
src/annotator/
plugin/test/bucket-bar-j
s-test.js
→
src/annotator/
util/test/bucket
s-test.js
View file @
9c82dbd0
...
...
@@ -2,8 +2,8 @@ import {
findClosestOffscreenAnchor
,
constructPositionPoints
,
buildBuckets
,
}
from
'../bucket
-bar-j
s'
;
import
{
$imports
}
from
'../bucket
-bar-j
s'
;
}
from
'../buckets'
;
import
{
$imports
}
from
'../buckets'
;
function
fakeAnchorFactory
()
{
let
highlightIndex
=
0
;
...
...
@@ -14,7 +14,7 @@ function fakeAnchorFactory() {
};
}
describe
(
'annotator/
plugin/bucket-bar-j
s'
,
()
=>
{
describe
(
'annotator/
util/bucket
s'
,
()
=>
{
let
fakeGetBoundingClientRect
;
beforeEach
(()
=>
{
...
...
@@ -175,7 +175,7 @@ describe('annotator/plugin/bucket-bar-js', () => {
assert
.
deepEqual
(
positionPoints
.
points
[
3
],
[
351
,
-
1
,
fakeAnchors
[
3
]]);
});
it
(
'sorts on-screen points based on position type secondarily'
,
()
=>
{
it
(
'sorts on-screen points based on position
primarily,
type secondarily'
,
()
=>
{
fakeGetBoundingClientRect
.
callsFake
(()
=>
{
return
{
top
:
250
,
...
...
@@ -200,6 +200,7 @@ describe('annotator/plugin/bucket-bar-js', () => {
}
});
});
describe
(
'buildBuckets'
,
()
=>
{
it
(
'should return empty buckets if points array is empty'
,
()
=>
{
const
bucketInfo
=
buildBuckets
([]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment