UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

128 lines 4.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTooltip = exports.getAxisYOptions = exports.getScaleY = exports.getAxisXOptions = exports.getCoordinate = exports.getAxisStyle = exports.getTheme = void 0; const s2_1 = require("@antv/s2"); const lodash_1 = require("lodash"); const constant_1 = require("../constant"); function getTheme(s2) { var _a; const themeName = s2.getThemeName(); return { theme: { type: (_a = s2_1.G2_THEME_TYPE[themeName]) !== null && _a !== void 0 ? _a : 'light', }, }; } exports.getTheme = getTheme; 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, }; } exports.getAxisStyle = getAxisStyle; 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, }, }; } exports.getCoordinate = getCoordinate; function getAxisXOptions(meta, s2) { const domain = (0, lodash_1.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], }, }, }; } exports.getAxisXOptions = getAxisXOptions; 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], }, }, }; } exports.getScaleY = getScaleY; 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: (0, lodash_1.unary)(formatter), title: (_a = s2.dataSet.getFieldFormatter(field)) === null || _a === void 0 ? void 0 : _a(value) }); } exports.getAxisYOptions = getAxisYOptions; function getTooltip(viewMeta, s2) { const { xField, yField } = viewMeta; const dataSet = s2.dataSet; return { tooltip: { title: (data) => { var _a; return data[constant_1.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(s2_1.EXTRA_FIELD)) === null || _a === void 0 ? void 0 : _a(yField), value: (_b = dataSet.getFieldFormatter(yField)) === null || _b === void 0 ? void 0 : _b(data[yField]), }; }, ], }, }; } exports.getTooltip = getTooltip; //# sourceMappingURL=chart-options.js.map