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

feat(annotations): Emit annotations color #1309

Merged
merged 3 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const ANNOTATOR_EVENT = {
fetch: 'annotationsfetched',
error: 'annotationerror',
scale: 'scaleannotations',
setColor: 'annotations_color_set',
setVisibility: 'annotations_visible_set',
};

Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ class BaseViewer extends EventEmitter {
const annotatorOptions = this.createAnnotatorOptions({
annotator: this.annotatorConf,
features: options && options.features,
initialColor: this.annotationModule.getColor(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the future, we may want to consider supporting something like an initial object that gets merged into the annotator's initial state.

initialMode: this.getInitialAnnotationMode(),
intl: (options && options.intl) || intlUtil.createAnnotatorIntl(),
modeButtons: ANNOTATION_BUTTONS,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,9 @@ describe('lib/viewers/BaseViewer', () => {
};

beforeEach(() => {
base.annotationModule.cache = {
get: jest.fn().mockReturnValue('#000'),
};
base.options.viewer = { NAME: 'viewerName' };
base.options.location = { locale: 'en-US' };
base.options.showAnnotations = true;
Expand Down Expand Up @@ -1177,6 +1180,7 @@ describe('lib/viewers/BaseViewer', () => {
features: {
enabledFeature: true,
},
initialColor: '#000',
};
jest.spyOn(base, 'areAnnotationsEnabled').mockReturnValue(true);
jest.spyOn(base, 'createAnnotatorOptions');
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ class DocBaseViewer extends BaseViewer {

handleAnnotationColorChange(color) {
this.annotationModule.setColor(color);
this.annotator.emit(ANNOTATOR_EVENT.setColor, color);
this.renderUI();
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2949,14 +2949,18 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.annotationModule = {
setColor: jest.fn(),
};
docBase.annotator = {
emit: jest.fn(),
};
docBase.renderUI = jest.fn();
});

test('should call setColor and renderUI', () => {
test('should call setColor and renderUI, and emit color', () => {
const color = '#fff';
docBase.handleAnnotationColorChange(color);

expect(docBase.annotationModule.setColor).toBeCalledWith(color);
expect(docBase.annotator.emit).toBeCalledWith(ANNOTATOR_EVENT.setColor, color);
expect(docBase.renderUI).toHaveBeenCalled();
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AnnotationControlsFSM, { AnnotationInput, AnnotationState, stateModeMap }
import ImageBaseViewer from './ImageBaseViewer';
import ImageControls from './ImageControls';
import {
ANNOTATOR_EVENT,
CLASS_ANNOTATIONS_IMAGE_FTUX_CURSOR_SEEN,
CLASS_INVISIBLE,
DISCOVERABILITY_ATTRIBUTE,
Expand Down Expand Up @@ -554,6 +555,7 @@ class ImageViewer extends ImageBaseViewer {

handleAnnotationColorChange(color) {
this.annotationModule.setColor(color);
this.annotator.emit(ANNOTATOR_EVENT.setColor, color);
this.renderUI();
}

Expand Down
12 changes: 10 additions & 2 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import Browser from '../../../Browser';
import ControlsRoot from '../../controls/controls-root';
import ImageControls from '../ImageControls';
import ImageViewer from '../ImageViewer';
import { CLASS_ANNOTATIONS_IMAGE_FTUX_CURSOR_SEEN, IMAGE_FTUX_CURSOR_SEEN_KEY } from '../../../constants';
import {
ANNOTATOR_EVENT,
CLASS_ANNOTATIONS_IMAGE_FTUX_CURSOR_SEEN,
IMAGE_FTUX_CURSOR_SEEN_KEY,
} from '../../../constants';

jest.mock('../../controls/controls-root');

Expand Down Expand Up @@ -712,14 +716,18 @@ describe('lib/viewers/image/ImageViewer', () => {
image.annotationModule = {
setColor: jest.fn(),
};
image.annotator = {
emit: jest.fn(),
};
image.renderUI = jest.fn();
});

test('should call setColor and renderUI', () => {
test('should call setColor and renderUI, and emit color', () => {
const color = '#fff';
image.handleAnnotationColorChange(color);

expect(image.annotationModule.setColor).toBeCalledWith(color);
expect(image.annotator.emit).toBeCalledWith(ANNOTATOR_EVENT.setColor, color);
expect(image.renderUI).toHaveBeenCalled();
});
});
Expand Down