@antv/f2
Version:
Charts for mobile visualization.
115 lines • 3.04 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { jsx } from '../../../jsx';
export default (function (props, context) {
var ticks = props.ticks,
coord = props.coord,
style = props.style,
animation = props.animation;
var px2hd = context.px2hd;
var left = coord.left,
right = coord.right,
bottom = coord.bottom;
var grid = style.grid,
tickLine = style.tickLine,
line = style.line,
labelOffset = style.labelOffset,
label = style.label;
return jsx("group", null, grid ? ticks.map(function (tick) {
var points = tick.points,
tickValue = tick.tickValue,
gridStyle = tick.gridStyle;
var start = points[0];
var end = points[points.length - 1];
return jsx("line", {
key: tickValue,
attrs: _objectSpread(_objectSpread({
x1: start.x,
y1: start.y,
x2: end.x,
y2: end.y
}, grid), gridStyle)
});
}) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
var points = tick.points,
tickValue = tick.tickValue;
var start = points[0];
return jsx("line", {
key: tickValue,
attrs: _objectSpread({
x1: start.x,
y1: start.y,
x2: start.x,
y2: start.y + px2hd(tickLine.length)
}, tickLine)
});
}) : null, line ? jsx("line", {
attrs: _objectSpread({
x1: left,
y1: bottom,
x2: right,
y2: bottom
}, line)
}) : null, label ? ticks.map(function (tick, index) {
var points = tick.points,
text = tick.text,
tickValue = tick.tickValue,
labelStyle = tick.labelStyle;
var start = points[0];
var _ref = labelStyle || label || {},
_ref$align = _ref.align,
align = _ref$align === void 0 ? 'center' : _ref$align;
var textAttrs = _objectSpread(_objectSpread({
x: start.x,
y: start.y + labelOffset,
textBaseline: 'top',
text: text
}, label), labelStyle);
if (align === 'between') {
if (index === 0) {
textAttrs.textAlign = 'start';
} else if (index === ticks.length - 1) {
textAttrs.textAlign = 'end';
} else {
textAttrs.textAlign = 'center';
}
} else {
textAttrs.textAlign = align;
}
return jsx("text", {
key: tickValue,
attrs: textAttrs,
animation: animation || {
appear: {
easing: 'linear',
duration: 300,
delay: 0,
property: ['fillOpacity'],
start: {
fillOpacity: 0
},
end: {
fillOpacity: 1
}
},
update: {
easing: 'linear',
duration: 450,
delay: 0,
property: ['x', 'y']
},
leave: {
easing: 'linear',
duration: 450,
delay: 0,
property: ['fillOpacity'],
start: {
fillOpacity: 1
},
end: {
fillOpacity: 0
}
}
}
});
}) : null);
});