Skip to content

Commit cc1aab2

Browse files
committed
Merge branch 'develop'
2 parents df6a7a8 + 7034070 commit cc1aab2

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/renderers/_base.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6014,6 +6014,54 @@ export abstract class RendererBase {
60146014
} else if (anchors) {
60156015
line.marker("end", markerCircle);
60166016
}
6017+
} else if ( (note.type !== undefined) && (note.type === "line") ) {
6018+
if ((note.targets as any[]).length < 2) {
6019+
throw new Error("Line annotations require at least two 'targets'.");
6020+
}
6021+
6022+
let colour = this.options.colourContext.annotations;
6023+
if ( ("colour" in note) && (note.colour !== undefined) && (note.colour !== null) ) {
6024+
colour = this.resolveColour(note.colour ) as string;
6025+
}
6026+
let style: "solid"|"dashed" = "solid";
6027+
let dasharray: string|undefined;
6028+
if ( ("style" in note) && (note.style !== undefined) ) {
6029+
style = note.style;
6030+
}
6031+
if ( ("dashed" in note) && (Array.isArray(note.dashed)) ) {
6032+
style = "dashed";
6033+
dasharray = note.dashed.map(n => n.toString()).join(" ");
6034+
}
6035+
let opacity = 1;
6036+
if ( ("opacity" in note) && (note.opacity !== undefined) ) {
6037+
opacity = note.opacity;
6038+
}
6039+
let strokeWidth = 0.03;
6040+
if ( ("strokeWidth" in note) && (note.strokeWidth !== undefined) ) {
6041+
strokeWidth = note.strokeWidth;
6042+
}
6043+
const points: string[] = [];
6044+
for (const node of (note.targets as ITarget[])) {
6045+
const pt = this.getStackedPoint(grid, node.col, node.row);
6046+
if (pt === undefined) {
6047+
throw new Error(`Annotation - Line: Could not find coordinates for row ${node.row}, column ${node.col}.`);
6048+
}
6049+
points.push(`${pt.x},${pt.y}`);
6050+
}
6051+
const stroke: StrokeData = {
6052+
color: colour,
6053+
opacity,
6054+
width: this.cellsize * strokeWidth,
6055+
linecap: "round", linejoin: "round"
6056+
};
6057+
if (style === "dashed") {
6058+
if (dasharray !== undefined) {
6059+
stroke.dasharray = dasharray;
6060+
} else {
6061+
stroke.dasharray = (4 * Math.ceil(strokeWidth / 0.03)).toString();
6062+
}
6063+
}
6064+
notes.polyline(points.join(" ")).addClass(`aprender-annotation-${x2uid(cloned)}`).stroke(stroke).fill("none").attr({ 'pointer-events': 'none' });
60176065
} else if ( (note.type !== undefined) && (note.type === "eject") ) {
60186066
if ((note.targets as any[]).length !== 2) {
60196067
throw new Error("Eject annotations require exactly two 'targets'.");

src/schemas/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ export interface AnnotationBasic {
12901290
/**
12911291
* The type of annotation. `move` draws an arrow between two cells. `eject` draws ever-growing arcs between a sequence of cells. `enter` and `exit` both draw a dotted line around cells. `dots` draws a small dot in the given cells. `outline` expects at least three points and draws a dotted line around the outer edge of the defined polygon.
12921292
*/
1293-
type: "move" | "eject" | "enter" | "exit" | "dots" | "outline" | "glyph";
1293+
type: "move" | "eject" | "enter" | "exit" | "dots" | "outline" | "glyph" | "line";
12941294
/**
12951295
* The cells involved in the annotation
12961296
*

src/schemas/schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@
321321
"exit",
322322
"dots",
323323
"outline",
324-
"glyph"
324+
"glyph",
325+
"line"
325326
]
326327
},
327328
"targets": {

0 commit comments

Comments
 (0)