UNPKG

victory-area

Version:
133 lines (132 loc) 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDataWithBaseline = exports.getBaseProps = void 0; var _victoryCore = require("victory-core"); const getDataWithBaseline = (props, scale) => { let data = _victoryCore.Data.getData(props); if (data.length < 2) { data = []; } const getDefaultMin = axis => { const defaultZero = _victoryCore.Scale.getType(scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0; const domain = scale[axis].domain(); const minY = _victoryCore.Collection.getMinValue(domain); const maxY = _victoryCore.Collection.getMaxValue(domain); let defaultMin = defaultZero; if (minY.valueOf() < 0 && maxY.valueOf() <= 0) { defaultMin = maxY; } else if (minY.valueOf() >= 0 && maxY.valueOf() > 0) { defaultMin = minY; } return _victoryCore.Collection.containsDates(domain) ? new Date(defaultMin) : defaultMin; }; return data.map(datum => { const _y1 = datum._y1 !== undefined ? datum._y1 : datum._y; const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y"); const _x1 = datum._x1 !== undefined ? datum._x1 : datum._x; const _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x"); return Object.assign({}, datum, { _y0, _y1, _x0, _x1 }); }); }; exports.getDataWithBaseline = getDataWithBaseline; const getCalculatedValues = props => { const { polar } = props; const defaultStyles = _victoryCore.Helpers.getDefaultStyles(props, "area"); const style = _victoryCore.Helpers.getStyles(props.style, defaultStyles); const range = { x: _victoryCore.Helpers.getRange(props, "x"), y: _victoryCore.Helpers.getRange(props, "y") }; const domain = { x: _victoryCore.Domain.getDomainWithZero(props, "x"), y: _victoryCore.Domain.getDomainWithZero(props, "y") }; const scale = { x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x), y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y) }; const origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined; const data = getDataWithBaseline(props, scale); return { style, data, scale, domain, origin }; }; const getBaseProps = (initialProps, fallbackProps) => { const modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "area"); const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps)); const { data, domain, events, groupComponent, height, horizontal, interpolation, origin, padding, polar, scale, sharedEvents, standalone, style, theme, width, labels, name, disableInlineStyles } = props; const initialChildProps = { parent: { style: style.parent, width, height, scale, data, domain, standalone, theme, polar, origin, padding, name, horizontal }, all: { data: { horizontal, polar, origin, scale, data, interpolation, groupComponent, style: disableInlineStyles ? {} : style.data, disableInlineStyles } } }; return data.reduce((childProps, datum, index) => { const text = _victoryCore.LabelHelpers.getText(props, datum, index); if (text !== undefined && text !== null || labels && (events || sharedEvents)) { const eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index; childProps[eventKey] = { labels: _victoryCore.LabelHelpers.getProps(props, index) }; } return childProps; }, initialChildProps); }; exports.getBaseProps = getBaseProps;