import { jsx, TextStyleProps } from '@antv/f-engine'; import { RectProps } from '../types'; import { isArray } from '@antv/util'; export default (props: RectProps<'bottom'>, context) => { const { ticks, coord, style, animation } = props; const { px2hd, measureText } = context; const { left, right, bottom } = coord; const { grid, tickLine, line, labelOffset, label, symbol } = style; const filterTicks = ticks.filter((d) => !isNaN(d.value)); const symbols = isArray(symbol) ? symbol : [symbol]; const { length: tickLineLength, ...tickLineStyle } = tickLine || {}; return ( {grid ? filterTicks.map((tick) => { const { points, tickValue, gridStyle } = tick; const start = points[0]; const end = points[points.length - 1]; return ( ); }) : null} {tickLineLength ? filterTicks.map((tick) => { const { points, tickValue } = tick; const start = points[0]; return ( ); }) : null} {symbols[0] ? ( ) : null} {line ? ( ) : null} {symbols[1] ? ( ) : null} {label ? filterTicks.map((tick, index) => { const { points, text, tickValue, labelStyle, visible = true } = tick; if (!visible) return null; const { x, y } = points[0]; const { align = 'center' } = labelStyle || label || {}; const textAttrs: TextStyleProps = { x, y: y + labelOffset, textBaseline: 'top', 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 if (align === 'auto') { textAttrs.textAlign = 'center'; const { width } = measureText(text, textAttrs); const halfWidth = width / 2; if (x - halfWidth < left) { textAttrs.x = left + width / 2; } else if (x + halfWidth > right) { textAttrs.x = right - width / 2; } } else { textAttrs.textAlign = align; } return ( ); }) : null} ); };