Skip to content

Commit b82896a

Browse files
committed
handle paper-referenced shapes
1 parent a9a559e commit b82896a

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/components/shapes/label_texttemplate.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
'use strict';
22

3+
// Wrapper functions to handle paper-referenced shapes, which have no axis
4+
5+
function d2l(v, axis) {
6+
return axis ? axis.d2l(v) : v;
7+
}
8+
9+
function l2d(v, axis) {
10+
return axis ? axis.l2d(v) : v;
11+
}
12+
313

414
function x0Fn(shape) { return shape.x0; }
515
function x1Fn(shape) { return shape.x1; }
616
function y0Fn(shape) { return shape.y0; }
717
function y1Fn(shape) { return shape.y1; }
818

919
function dxFn(shape, xa) {
10-
return xa.d2l(shape.x1) - xa.d2l(shape.x0);
20+
return d2l(shape.x1, xa) - d2l(shape.x0, xa);
1121
}
1222

1323
function dyFn(shape, xa, ya) {
14-
return ya.d2l(shape.y1) - ya.d2l(shape.y0);
24+
return d2l(shape.y1, ya) - d2l(shape.y0, ya);
1525
}
1626

1727
function widthFn(shape, xa) {
@@ -31,11 +41,11 @@ function lengthFn(shape, xa, ya) {
3141
}
3242

3343
function xcenterFn(shape, xa) {
34-
return xa.l2d((xa.d2l(shape.x1) + xa.d2l(shape.x0)) / 2);
44+
return l2d((d2l(shape.x1, xa) + d2l(shape.x0, xa)) / 2, xa);
3545
}
3646

3747
function ycenterFn(shape, xa, ya) {
38-
return ya.l2d((ya.d2l(shape.y1) + ya.d2l(shape.y0)) / 2);
48+
return l2d((d2l(shape.y1, ya) + d2l(shape.y0, ya)) / 2, ya);
3949
}
4050

4151
function slopeFn(shape, xa, ya) {

test/image/mocks/zz-text_on_shapes_texttemplate.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@
160160
"width": 1000,
161161
"height": 1000,
162162
"shapes": [
163+
{
164+
"label": {
165+
"texttemplate": "Paper-referenced shape<br>x0: %{x0:.2f}, x1: %{x1:.2f}, xcenter: %{xcenter:.2f}, dx: %{dx:.2f}<br>y0: %{y0:.2f}, y1: %{y1:.2f}, ycenter: %{ycenter:.2f}, dy: %{dy:.2f}",
166+
"textposition": "middle left"
167+
},
168+
"layer": "above",
169+
"xref": "paper",
170+
"yref": "paper",
171+
"x0": 0.2,
172+
"x1": 0.6,
173+
"y0": 0.15,
174+
"y1": 0.05,
175+
"type": "rect",
176+
"opacity": 0.3,
177+
"editable": true
178+
},
163179
{
164180
"label": {
165181
"text": "this will be overridden",
@@ -186,7 +202,7 @@
186202
"layer": "above",
187203
"x0": 5,
188204
"x1": 9,
189-
"y0": 2.5,
205+
"y0": 3.7,
190206
"y1": 9,
191207
"type": "line",
192208
"opacity": 0.5,

0 commit comments

Comments
 (0)