Skip to content

Commit cec7a8b

Browse files
committed
improve annotations; allow annotation to be drawn by px
1 parent 68ec6eb commit cec7a8b

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/modules/annotations/Helpers.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ export default class Helpers {
187187
}
188188
}
189189

190+
if (typeof y === 'string' && y.indexOf('px') > -1) {
191+
yP = parseFloat(y)
192+
}
193+
190194
return yP
191195
}
192196

@@ -232,6 +236,22 @@ export default class Helpers {
232236
x1 = w.globals.gridWidth
233237
}
234238

239+
if (
240+
type === 'x1' &&
241+
typeof anno.x === 'string' &&
242+
anno.x.indexOf('px') > -1
243+
) {
244+
x1 = parseFloat(anno.x)
245+
}
246+
247+
if (
248+
type === 'x2' &&
249+
typeof anno.x2 === 'string' &&
250+
anno.x2.indexOf('px') > -1
251+
) {
252+
x2 = parseFloat(anno.x2)
253+
}
254+
235255
return type === 'x1' ? x1 : x2
236256
}
237257

src/modules/annotations/XAxisAnnotations.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ export default class XAnnotations {
6565
rect.node.classList.add(anno.id)
6666
}
6767
}
68-
let textY = anno.label.position === 'top' ? 4 : w.globals.gridHeight
6968

7069
let textRects = this.annoCtx.graphics.getTextRects(
7170
text,
7271
parseFloat(anno.label.style.fontSize)
7372
)
73+
let textY =
74+
anno.label.position === 'top'
75+
? 4
76+
: anno.label.position === 'center'
77+
? w.globals.gridHeight / 2 +
78+
(anno.label.orientation === 'vertical' ? textRects.width / 2 : 0)
79+
: w.globals.gridHeight
7480

7581
let elText = this.annoCtx.graphics.drawText({
7682
x: x1 + anno.label.offsetX,

src/modules/annotations/YAxisAnnotations.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export default class YAnnotations {
6161
rect.node.classList.add(anno.id)
6262
}
6363
}
64-
let textX = anno.label.position === 'right' ? w.globals.gridWidth : 0
64+
let textX =
65+
anno.label.position === 'right'
66+
? w.globals.gridWidth
67+
: anno.label.position === 'center'
68+
? w.globals.gridWidth / 2
69+
: 0
6570

6671
let elText = this.annoCtx.graphics.drawText({
6772
x: textX + anno.label.offsetX,

0 commit comments

Comments
 (0)