Skip to content

Add support for per-element clip attributes #972

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ function draw(chart, caller, clip) {

const drawableElements = getDrawableElements(state.visibleElements, caller).sort((a, b) => a.element.options.z - b.element.options.z);
for (const item of drawableElements) {
if (item.element.options.clip && !clip) {
clipArea(ctx, chartArea);
clip = true;
} else if (item.element.options.clip === false && clip) {
unclipArea(ctx);
clip = false;
}
drawElement(ctx, chartArea, state, item);
}

Expand Down
6 changes: 3 additions & 3 deletions src/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export function updateElements(chart, state, options, mode) {
}

if (!defined(element.x)) {
// If the element is newly created, assing the properties directly - to
// make them readily awailable to any scriptable options. If we do not do this,
// the properties retruned by `resolveElementProperties` are available only
// If the element is newly created, assign the properties directly - to
// make them readily available to any scriptable options. If we do not do this,
// the properties returned by `resolveElementProperties` are available only
// after options resolution.
Object.assign(element, properties);
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ BoxAnnotation.defaults = {
borderRadius: 0,
borderShadowColor: 'transparent',
borderWidth: 1,
clip: undefined,
display: true,
init: undefined,
hitTolerance: 0,
Expand All @@ -50,6 +51,7 @@ BoxAnnotation.defaults = {
callout: {
display: false
},
clip: undefined,
color: 'black',
content: null,
display: false,
Expand Down
1 change: 1 addition & 0 deletions src/types/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ LabelAnnotation.defaults = {
side: 5,
start: '50%',
},
clip: undefined,
color: 'black',
content: null,
display: true,
Expand Down
3 changes: 2 additions & 1 deletion types/label.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export interface CoreLabelOptions {
* Overrides the opacity of the image.
*/
opacity?: Scriptable<number, PartialEventContext>,
z?: Scriptable<number, PartialEventContext>
z?: Scriptable<number, PartialEventContext>,
clip?: Scriptable<boolean, PartialEventContext>
}

export interface ContainedLabelOptions extends CoreLabelOptions {
Expand Down
1 change: 1 addition & 0 deletions types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface CoreAnnotationOptions extends AnnotationEvents, ShadowOptions,
borderDash?: Scriptable<number[], PartialEventContext>,
borderDashOffset?: Scriptable<number, PartialEventContext>,
borderWidth?: Scriptable<number, PartialEventContext>,
clip?: Scriptable<boolean, PartialEventContext>,
display?: Scriptable<boolean, PartialEventContext>,
drawTime?: Scriptable<DrawTime, PartialEventContext>,
hitTolerance?: Scriptable<number, PartialEventContext>,
Expand Down
Loading