Skip to content

Commit 6f8e5a6

Browse files
committed
Support shape shift in texttemplate as well
- Add texttemplate with slope and xcenter to mock
1 parent 5509ee6 commit 6f8e5a6

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/components/shapes/label_texttemplate.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ function x1Fn(shape) { return shape.x1; }
1616
function y0Fn(shape) { return shape.y0; }
1717
function y1Fn(shape) { return shape.y1; }
1818

19+
function x0shiftFn(shape) { return shape.x0shift || 0; }
20+
function x1shiftFn(shape) { return shape.x1shift || 0; }
21+
function y0shiftFn(shape) { return shape.y0shift || 0; }
22+
function y1shiftFn(shape) { return shape.y1shift || 0; }
23+
1924
function dxFn(shape, xa) {
20-
return d2l(shape.x1, xa) - d2l(shape.x0, xa);
25+
return d2l(shape.x1, xa) + x1shiftFn(shape) - d2l(shape.x0, xa) - x0shiftFn(shape);
2126
}
2227

2328
function dyFn(shape, xa, ya) {
24-
return d2l(shape.y1, ya) - d2l(shape.y0, ya);
29+
return d2l(shape.y1, ya) + y1shiftFn(shape) - d2l(shape.y0, ya) - y0shiftFn(shape);
2530
}
2631

2732
function widthFn(shape, xa) {
@@ -41,11 +46,11 @@ function lengthFn(shape, xa, ya) {
4146
}
4247

4348
function xcenterFn(shape, xa) {
44-
return l2d((d2l(shape.x1, xa) + d2l(shape.x0, xa)) / 2, xa);
49+
return l2d((d2l(shape.x1, xa) + x1shiftFn(shape) + d2l(shape.x0, xa) + x0shiftFn(shape)) / 2, xa);
4550
}
4651

4752
function ycenterFn(shape, xa, ya) {
48-
return l2d((d2l(shape.y1, ya) + d2l(shape.y0, ya)) / 2, ya);
53+
return l2d((d2l(shape.y1, ya) + y1shiftFn(shape) + d2l(shape.y0, ya) + y0shiftFn(shape)) / 2, ya);
4954
}
5055

5156
function slopeFn(shape, xa, ya) {

test/image/mocks/zzz_shape_shift_vertical.json

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"A", "B", "C", "D"
66
],
77
"y": [
8-
1, 2, 3, 4
8+
1, 2, 2.5, 4
99
],
1010
"type": "bar"
1111
},
@@ -14,7 +14,7 @@
1414
"A", "B", "C", "D"
1515
],
1616
"y": [
17-
3, 2, 4, 1
17+
3, 2, 1.5, 1
1818
],
1919
"type": "scatter"
2020
}
@@ -24,6 +24,9 @@
2424
"xaxis": {
2525
"autorange": "reversed"
2626
},
27+
"yaxis": {
28+
"range": [0, 5]
29+
},
2730
"shapes": [
2831
{
2932
"layer": "above",
@@ -64,6 +67,25 @@
6467
"x0shift": -0.25,
6568
"x1shift": -0.25,
6669
"yref": "paper"
70+
},
71+
{
72+
"label": {
73+
"texttemplate": "dy/dx = -1.5 / 1 = %{slope}. xcenter: %{xcenter}"
74+
75+
},
76+
"layer": "above",
77+
"x0": "A",
78+
"x1": "C",
79+
"x0shift": 0.5,
80+
"x1shift": -0.5,
81+
"y0": 4.5,
82+
"y1": 3,
83+
"type": "line",
84+
"line": {
85+
"width": 3,
86+
"color": "pink"
87+
},
88+
"editable": true
6789
}
6890
]
6991
}

0 commit comments

Comments
 (0)