Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6f76d5

Browse files
committed
fix texttemplate behavior for log axes and simplify
1 parent e1ac9d7 commit e6f76d5

File tree

1 file changed

+11
-33
lines changed

1 file changed

+11
-33
lines changed

src/components/shapes/label_texttemplate.js

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

3-
function d2l(v, axis) {
4-
return (
5-
axis.type === 'log' ? v :
6-
axis.d2l(v)
7-
);
8-
}
93

10-
function getPos(x, xa) {
11-
return (
12-
xa.type === 'date' ? x :
13-
d2l(x, xa)
14-
);
15-
}
16-
17-
function x0Fn(shape, xa) { return getPos(shape.x0, xa); }
18-
function x1Fn(shape, xa) { return getPos(shape.x1, xa); }
19-
function y0Fn(shape, xa, ya) { return getPos(shape.y0, ya); }
20-
function y1Fn(shape, xa, ya) { return getPos(shape.y1, ya); }
4+
function x0Fn(shape) { return shape.x0; }
5+
function x1Fn(shape) { return shape.x1; }
6+
function y0Fn(shape) { return shape.y0; }
7+
function y1Fn(shape) { return shape.y1; }
218

229
function dxFn(shape, xa) {
23-
return (
24-
d2l(shape.x1, xa) -
25-
d2l(shape.x0, xa)
26-
);
10+
return xa.d2l(shape.x1) - xa.d2l(shape.x0);
2711
}
2812

2913
function dyFn(shape, xa, ya) {
30-
return (
31-
d2l(shape.y1, ya) -
32-
d2l(shape.y0, ya)
33-
);
14+
return ya.d2l(shape.y1) - ya.d2l(shape.y0);
3415
}
3516

3617
function widthFn(shape, xa) {
@@ -44,25 +25,22 @@ function heightFn(shape, xa, ya) {
4425
function lengthFn(shape, xa, ya) {
4526
return (shape.type !== 'line') ? undefined :
4627
Math.sqrt(
47-
Math.pow((d2l(shape.x1, xa) - d2l(shape.x0, xa)), 2) +
48-
Math.pow((d2l(shape.y1, ya) - d2l(shape.y0, ya)), 2)
28+
Math.pow(dxFn(shape, xa), 2) +
29+
Math.pow(dyFn(shape, xa, ya), 2)
4930
);
5031
}
5132

5233
function xcenterFn(shape, xa) {
53-
var val = (d2l(shape.x1, xa) + d2l(shape.x0, xa)) / 2;
54-
return (xa.type === 'date') ? xa.l2d(val) : val;
34+
return xa.l2d((xa.d2l(shape.x1) + xa.d2l(shape.x0)) / 2);
5535
}
5636

5737
function ycenterFn(shape, xa, ya) {
58-
var val = (d2l(shape.y1, ya) + d2l(shape.y0, ya)) / 2;
59-
return (ya.type === 'date') ? ya.l2d(val) : val;
38+
return ya.l2d((ya.d2l(shape.y1) + ya.d2l(shape.y0)) / 2);
6039
}
6140

6241
function slopeFn(shape, xa, ya) {
6342
return (shape.type !== 'line') ? undefined : (
64-
(d2l(shape.y1, ya) - d2l(shape.y0, ya)) /
65-
(d2l(shape.x1, xa) - d2l(shape.x0, xa))
43+
dyFn(shape, xa, ya) / dxFn(shape, xa)
6644
);
6745
}
6846

0 commit comments

Comments
 (0)