UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

81 lines (65 loc) 3.59 kB
import { get } from "@visactor/vutils"; import { mergeSpec } from "@visactor/vutils-extension"; import { transformComponentStyle } from "../../util/style"; import { isXAxis, isYAxis } from "./cartesian/util/common"; import { getComponentThemeFromOption } from "../util"; export const DEFAULT_TITLE_STYLE = { left: { textAlign: "center", textBaseline: "bottom" }, right: { textAlign: "center", textBaseline: "bottom" }, radius: {}, angle: {} }; export function transformAxisLineStyle(lineCfg) { return (lineCfg = transformComponentStyle(lineCfg)).startSymbol = transformComponentStyle(lineCfg.startSymbol), lineCfg.endSymbol = transformComponentStyle(lineCfg.endSymbol), lineCfg; } export function getAxisLabelOffset(axisSpec) { let labelOffset = 0; return get(axisSpec, "tick.visible") && (labelOffset += get(axisSpec, "tick.tickSize")), get(axisSpec, "label.visible") && (labelOffset += get(axisSpec, "label.space")), labelOffset; } export function getLinearAxisSpecDomain(axisSpec, defaultDomain) { var _a, _b, _c, _d, _e, _f; return { min: null !== (_c = null !== (_a = axisSpec.min) && void 0 !== _a ? _a : null === (_b = axisSpec.range) || void 0 === _b ? void 0 : _b.min) && void 0 !== _c ? _c : null == defaultDomain ? void 0 : defaultDomain.min, max: null !== (_f = null !== (_d = axisSpec.max) && void 0 !== _d ? _d : null === (_e = axisSpec.range) || void 0 === _e ? void 0 : _e.max) && void 0 !== _f ? _f : null == defaultDomain ? void 0 : defaultDomain.max }; } export function isValidCartesianAxis(spec) { const orient = null == spec ? void 0 : spec.orient; return "top" === orient || "bottom" === orient || "left" === orient || "right" === orient || "z" === orient; } export function isValidPolarAxis(spec) { const orient = null == spec ? void 0 : spec.orient; return "angle" === orient || "radius" === orient; } export const getCartesianAxisTheme = (orient, type, chartTheme) => { var _a; const axisTypeTheme = null !== (_a = "band" === type ? getComponentThemeFromOption("axisBand", chartTheme) : [ "linear", "log", "symlog" ].includes(type) ? getComponentThemeFromOption("axisLinear", chartTheme) : {}) && void 0 !== _a ? _a : {}, axisTheme = isXAxis(orient) ? getComponentThemeFromOption("axisX", chartTheme) : isYAxis(orient) ? getComponentThemeFromOption("axisY", chartTheme) : getComponentThemeFromOption("axisZ", chartTheme); return mergeSpec({}, getComponentThemeFromOption("axis", chartTheme), axisTypeTheme, axisTheme); }; export const getPolarAxisTheme = (orient, type, chartTheme) => { var _a; const axisTypeTheme = null !== (_a = "band" === type ? getComponentThemeFromOption("axisBand", chartTheme) : "linear" === type ? getComponentThemeFromOption("axisLinear", chartTheme) : {}) && void 0 !== _a ? _a : {}, axisTheme = getComponentThemeFromOption("angle" === orient ? "axisAngle" : "axisRadius", chartTheme); return mergeSpec({}, getComponentThemeFromOption("axis", chartTheme), axisTypeTheme, axisTheme); }; export const isDiscreteAxis = axisType => "band" === axisType || "ordinal" === axisType || "point" === axisType; export function getAxisItem(value, normalizedValue) { return { id: value, label: value, value: normalizedValue, rawValue: value }; } export function shouldUpdateAxis(preHelper, curHelper, forceUpdate) { return forceUpdate || !preHelper || preHelper.getAxisId() === curHelper.getAxisId(); } //# sourceMappingURL=util.js.map