UNPKG

1.62 kBJavaScriptView Raw
1import { __assign, __extends } from "tslib";
2import { jsx, Component } from '@antv/f-engine';
3var getPoint = function getPoint(cener, angle, r) {
4 var x = cener.x + Math.cos(angle) * r;
5 var y = cener.y + Math.sin(angle) * r;
6 return {
7 x: x,
8 y: y
9 };
10};
11var getTicks = function getTicks(start, end, tickCount, center, r, tickOffset, tickLength) {
12 var ticks = [];
13 var diff = end - start;
14 for (var i = 0; i <= tickCount; i++) {
15 var tickValue = start + diff * i / tickCount;
16 var startPoint = getPoint(center, tickValue, r + tickOffset - tickLength);
17 var endPoint = getPoint(center, tickValue, r + tickOffset);
18 ticks.push({
19 tickValue: tickValue,
20 start: startPoint,
21 end: endPoint
22 });
23 }
24 return ticks;
25};
26var withGauge = function withGauge(View) {
27 return /** @class */function (_super) {
28 __extends(Gauge, _super);
29 function Gauge() {
30 return _super !== null && _super.apply(this, arguments) || this;
31 }
32 Gauge.prototype.render = function () {
33 var _a = this,
34 props = _a.props,
35 context = _a.context;
36 var startAngle = props.startAngle,
37 endAngle = props.endAngle,
38 tickCount = props.tickCount,
39 center = props.center,
40 r = props.r,
41 tickOffset = props.tickOffset,
42 tickLength = props.tickLength;
43 var ticks = getTicks(startAngle, endAngle, tickCount, center, context.px2hd(r), context.px2hd(tickOffset), context.px2hd(tickLength));
44 return jsx(View, __assign({}, props, {
45 ticks: ticks
46 }));
47 };
48 return Gauge;
49 }(Component);
50};
51export default withGauge;
\No newline at end of file