UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

60 lines (45 loc) 2.27 kB
import { isValid } from "@visactor/vutils"; import { isValidOrient } from "../../../../util/space"; import { ComponentTypeEnum } from "../../../interface"; import { getComponentThemeFromOption } from "../../../util"; import { mergeSpec } from "@visactor/vutils-extension"; export function isXAxis(orient) { return "bottom" === orient || "top" === orient; } export function isYAxis(orient) { return "left" === orient || "right" === orient; } export function isZAxis(orient) { return "z" === orient; } export function autoAxisType(orient, isHorizontal) { return isHorizontal ? isXAxis(orient) ? "linear" : "band" : isXAxis(orient) ? "band" : "linear"; } export function getOrient(spec, whiteList) { return isValidOrient(spec.orient) || whiteList && whiteList.includes(spec.orient) ? spec.orient : "left"; } export function getDirectionByOrient(orient) { return "top" === orient || "bottom" === orient ? "horizontal" : "vertical"; } export function isOrientInSameDirection(orient1, orient2) { return getDirectionByOrient(orient1) === getDirectionByOrient(orient2); } export function transformInverse(spec, isHorizontal) { let inverse = spec.inverse; return isHorizontal && !isXAxis(spec.orient) && (inverse = !isValid(spec.inverse) || !spec.inverse), inverse; } export function getCartesianAxisInfo(spec, isHorizontal) { var _a; const axisType = null !== (_a = spec.type) && void 0 !== _a ? _a : autoAxisType(spec.orient, isHorizontal); return { axisType: axisType, componentName: `${ComponentTypeEnum.cartesianAxis}-${axisType}` }; } export const getCartesianAxisTheme = (orient, type, getTheme) => { var _a; const axisTypeTheme = null !== (_a = "band" === type ? getComponentThemeFromOption("axisBand", getTheme) : [ "linear", "log", "symlog" ].includes(type) ? getComponentThemeFromOption("axisLinear", getTheme) : {}) && void 0 !== _a ? _a : {}, axisTheme = isXAxis(orient) ? getComponentThemeFromOption("axisX", getTheme) : isYAxis(orient) ? getComponentThemeFromOption("axisY", getTheme) : getComponentThemeFromOption("axisZ", getTheme); return mergeSpec({}, getComponentThemeFromOption("axis", getTheme), axisTypeTheme, axisTheme); }; //# sourceMappingURL=common.js.map