UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

118 lines 3.96 kB
import { EXTRA_FIELD, G2_THEME_TYPE, } from '@antv/s2'; import { map, unary } from 'lodash'; import { X_FIELD_FORMATTER } from '../constant'; export function getTheme(s2) { var _a; const themeName = s2.getThemeName(); return { theme: { type: (_a = G2_THEME_TYPE[themeName]) !== null && _a !== void 0 ? _a : 'light', }, }; } export function getAxisStyle(cellStyle) { return { // title titleSpacing: 0, titleFontSize: cellStyle.bolderText.fontSize, titleFontFamily: cellStyle.bolderText.fontFamily, titleFontWeight: cellStyle.bolderText.fontWeight, titleFill: cellStyle.bolderText.fill, titleFillOpacity: cellStyle.bolderText.opacity, // label labelAlign: 'horizontal', labelAutoRotate: false, labelFontSize: cellStyle.text.fontSize, labelFontFamily: cellStyle.text.fontFamily, labelFontWeight: cellStyle.text.fontWeight, labelFill: cellStyle.text.fill, labelFillOpacity: cellStyle.text.opacity, labelStroke: cellStyle.text.fill, labelStrokeOpacity: cellStyle.text.fill, // tick tick: true, tickStroke: cellStyle.text.fill, tickStrokeOpacity: cellStyle.text.opacity, // line line: false, lineStroke: cellStyle.text.fill, lineStrokeOpacity: cellStyle.text.opacity, // grid grid: false, }; } export function getCoordinate(s2) { var _a, _b; if ((_b = (_a = s2).isPolarCoordinate) === null || _b === void 0 ? void 0 : _b.call(_a)) { return {}; } return { coordinate: { transform: s2.isValueInCols() ? [{ type: 'transpose' }] : undefined, }, }; } export function getAxisXOptions(meta, s2) { const domain = map(meta.children, (child) => { const formatter = s2.dataSet.getFieldFormatter(child.field); return !child.isTotalRoot && formatter ? formatter(child.value, undefined, child) : child.value; }); return { type: 'axisX', scale: { x: { type: 'band', domain, range: [0, 1], }, }, }; } export function getScaleY(value, s2) { var _a, _b; if ((_b = (_a = s2).isPolarCoordinate) === null || _b === void 0 ? void 0 : _b.call(_a)) { return {}; } const range = s2.dataSet.getValueRangeByField(value); return { scale: { y: { type: 'linear', domain: [range.minValue, range.maxValue], range: [1, 0], }, }, }; } export function getAxisYOptions(meta, s2) { var _a; const { field, value } = meta; const formatter = s2.dataSet.getFieldFormatter(value); return Object.assign(Object.assign({ type: 'axisY' }, getScaleY(value, s2)), { labelFormatter: unary(formatter), title: (_a = s2.dataSet.getFieldFormatter(field)) === null || _a === void 0 ? void 0 : _a(value) }); } export function getTooltip(viewMeta, s2) { const { xField, yField } = viewMeta; const dataSet = s2.dataSet; return { tooltip: { title: (data) => { var _a; return data[X_FIELD_FORMATTER] ? (_a = dataSet.getFieldFormatter(xField)) === null || _a === void 0 ? void 0 : _a(data[xField]) : data[xField]; }, items: [ (data) => { var _a, _b; return { name: (_a = dataSet.getFieldFormatter(EXTRA_FIELD)) === null || _a === void 0 ? void 0 : _a(yField), value: (_b = dataSet.getFieldFormatter(yField)) === null || _b === void 0 ? void 0 : _b(data[yField]), }; }, ], }, }; } //# sourceMappingURL=chart-options.js.map