UNPKG

@antv/g2

Version:

the Grammar of Graphics in Javascript

28 lines 925 B
import { maxIndex } from 'd3-array'; import { sub, angle } from '../../../utils/vector'; /** * Only for Area label. */ export function area(position, points, value, coordinate) { const l = points.length / 2; const Y1 = points.slice(0, l); const Y0 = points.slice(l); // Get the maximal space for label. let idx = maxIndex(Y1, (p, i) => Math.abs(p[1] - Y0[i][1])); // Do not show label at first and last. idx = Math.max(Math.min(idx, l - 2), 1); const mid = (i) => [Y1[i][0], (Y1[i][1] + Y0[i][1]) / 2]; const point = mid(idx); const prev = mid(idx - 1); const next = mid(idx + 1); // todo: G rotate only support deg. const rotate = (angle(sub(next, prev)) / Math.PI) * 180; return { x: point[0], y: point[1], transform: `rotate(${rotate})`, textAlign: 'center', textBaseline: 'middle', }; } //# sourceMappingURL=area.js.map