New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

victory-chart

Package Overview
Dependencies
Maintainers
7
Versions
290
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

victory-chart - npm Package Compare versions

Comparing version 25.1.1 to 25.2.0

es/components/victory-boxplot/helper-methods.js

16

CHANGELOG.md
# VictoryChart Changelog
## 25.1.1 (2016-02-14)
## 25.2.0 (2018-03-27)
-[557](https://github.com/FormidableLabs/victory-chart/pull/557) `VictoryBoxPlot`
-[575](https://github.com/FormidableLabs/victory-chart/pull/575) Stack datasets with differeing domains
-[574](https://github.com/FormidableLabs/victory-chart/pull/574) Refactor helper method exports
## 25.1.1 (2018-02-14)
-[573](https://github.com/FormidableLabs/victory-chart/pull/573) Use fallback styles in VictoryBrushLine
## 25.1.0 (2016-02-12)
## 25.1.0 (2018-02-12)

@@ -16,3 +22,3 @@ -[571](https://github.com/FormidableLabs/victory-chart/pull/571)

## 25.0.6 (2016-02-09)
## 25.0.6 (2018-02-09)

@@ -24,7 +30,7 @@ -[570](https://github.com/FormidableLabs/victory-chart/pull/570) Add "minus" option for `VictoryScatter` `symbol` prop

## 25.0.5 (2016-02-07)
## 25.0.5 (2018-02-07)
-[565](https://github.com/FormidableLabs/victory-chart/pull/565) Prevent re-renders with disable prop
## 25.0.4 (2016-02-07)
## 25.0.4 (2018-02-07)

@@ -31,0 +37,0 @@ -[564](https://github.com/FormidableLabs/victory-chart/pull/564) Adds `disable` prop to all interactive containers and addon components

@@ -7,79 +7,81 @@ import _assign from "lodash/assign";

export default {
getBaseProps: function (props, fallbackProps) {
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "area");
props = _assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getDataWithBaseline = function (props, scale) {
var data = Data.getData(props);
var initialChildProps = {
parent: {
style: style.parent, width: width, height: height, scale: scale, data: data, domain: domain,
standalone: standalone, theme: theme, polar: polar, origin: origin, padding: padding
},
all: {
data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, style: style.data }
}
};
return data.reduce(function (childProps, datum, index) {
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
},
getCalculatedValues: function (props) {
var theme = props.theme,
polar = props.polar;
if (data.length < 2) {
data = [];
}
var defaultMin = Scale.getType(scale.y) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
var domainY = scale.y.domain();
var minY = Math.min.apply(Math, _toConsumableArray(domainY)) > 0 ? Math.min.apply(Math, _toConsumableArray(domainY)) : defaultMin;
var defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
var data = this.getDataWithBaseline(props, scale);
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
},
getDataWithBaseline: function (props, scale) {
var data = Data.getData(props);
return data.map(function (datum) {
var _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
var _y0 = datum._y0 !== undefined ? datum._y0 : minY;
return _assign({}, datum, { _y0: _y0, _y1: _y1 });
});
};
if (data.length < 2) {
data = [];
var getCalculatedValues = function (props) {
var theme = props.theme,
polar = props.polar;
var defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
var data = getDataWithBaseline(props, scale);
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
};
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "area");
props = _assign({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var initialChildProps = {
parent: {
style: style.parent, width: width, height: height, scale: scale, data: data, domain: domain,
standalone: standalone, theme: theme, polar: polar, origin: origin, padding: padding
},
all: {
data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, style: style.data }
}
var defaultMin = Scale.getType(scale.y) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
var domainY = scale.y.domain();
var minY = Math.min.apply(Math, _toConsumableArray(domainY)) > 0 ? Math.min.apply(Math, _toConsumableArray(domainY)) : defaultMin;
};
return data.reduce(function (childProps, datum, index) {
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
};
return data.map(function (datum) {
var _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
var _y0 = datum._y0 !== undefined ? datum._y0 : minY;
return _assign({}, datum, { _y0: _y0, _y1: _y1 });
});
}
};
export { getBaseProps, getDataWithBaseline };

@@ -15,3 +15,3 @@ import _partialRight from "lodash/partialRight";

import React from "react";
import AreaHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import { PropTypes as CustomPropTypes, Helpers, VictoryLabel, VictoryContainer, DefaultTransitions, Area, VictoryClipContainer, addEvents, VictoryTheme, Data, Domain } from "victory-core";

@@ -91,3 +91,3 @@ import { BaseProps, DataProps } from "../../helpers/common-props";

VictoryArea.getData = Data.getData.bind(Data);
VictoryArea.getBaseProps = _partialRight(AreaHelpers.getBaseProps.bind(AreaHelpers), fallbackProps);
VictoryArea.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryArea.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];

@@ -94,0 +94,0 @@

@@ -11,100 +11,101 @@ import _isNaN from "lodash/isNaN";

export default {
getBarPosition: function (props, datum) {
var getDefaultMin = function (axis) {
var defaultMin = Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
return datum["_" + axis] instanceof Date ? new Date(defaultMin) : defaultMin;
};
var _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
var _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
return Helpers.scalePoint(props, _assign({}, datum, { _y0: _y0, _x0: _x0 }));
},
getBarStyle: function (datum, baseStyle) {
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "y", "y0", "_x", "_y", "_y0", "name", "label", "eventKey"];
var styleData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return _defaults({}, styleData, baseStyle);
},
getCalculatedValues: function (props) {
var theme = props.theme,
horizontal = props.horizontal,
polar = props.polar;
var getBarPosition = function (props, datum) {
var getDefaultMin = function (axis) {
var defaultMin = Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
return datum["_" + axis] instanceof Date ? new Date(defaultMin) : defaultMin;
};
var _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
var _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
return Helpers.scalePoint(props, _assign({}, datum, { _y0: _y0, _x0: _x0 }));
};
var defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
var data = Data.getData(props);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
var xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
var yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
var scale = {
x: horizontal ? yScale : xScale,
y: horizontal ? xScale : yScale
};
var origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
},
getBaseProps: function (props, fallbackProps) {
var _this = this;
var getBarStyle = function (datum, baseStyle) {
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "y", "y0", "_x", "_y", "_y0", "name", "label", "eventKey"];
var styleData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return _defaults({}, styleData, baseStyle);
};
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "bar");
props = _assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
alignment = _props.alignment,
barRatio = _props.barRatio,
cornerRadius = _props.cornerRadius,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
horizontal = _props.horizontal,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getCalculatedValues = function (props) {
var theme = props.theme,
horizontal = props.horizontal,
polar = props.polar;
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone,
theme: theme, polar: polar, origin: origin, padding: padding, style: style.parent
} };
var defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
var data = Data.getData(props);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
var xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
var yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
var scale = {
x: horizontal ? yScale : xScale,
y: horizontal ? xScale : yScale
};
var origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
};
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "bar");
props = _assign({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
alignment = _props.alignment,
barRatio = _props.barRatio,
cornerRadius = _props.cornerRadius,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
horizontal = _props.horizontal,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var _getBarPosition = _this.getBarPosition(props, datum),
x = _getBarPosition.x,
y = _getBarPosition.y,
y0 = _getBarPosition.y0,
x0 = _getBarPosition.x0;
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone,
theme: theme, polar: polar, origin: origin, padding: padding, style: style.parent
} };
var barStyle = _this.getBarStyle(datum, style.data);
var dataProps = {
alignment: alignment, barRatio: barRatio, cornerRadius: cornerRadius, data: data, datum: datum, horizontal: horizontal, index: index, padding: padding, polar: polar, origin: origin,
scale: scale, style: barStyle, width: width, height: height, x: x, y: y, y0: y0, x0: x0
};
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = {
data: dataProps
};
var _getBarPosition = getBarPosition(props, datum),
x = _getBarPosition.x,
y = _getBarPosition.y,
y0 = _getBarPosition.y0,
x0 = _getBarPosition.x0;
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
}
};
var barStyle = getBarStyle(datum, style.data);
var dataProps = {
alignment: alignment, barRatio: barRatio, cornerRadius: cornerRadius, data: data, datum: datum, horizontal: horizontal, index: index, padding: padding, polar: polar, origin: origin,
scale: scale, style: barStyle, width: width, height: height, x: x, y: y, y0: y0, x0: x0
};
childProps[eventKey] = {
data: dataProps
};
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
};
export { getBaseProps };

@@ -15,3 +15,3 @@ import _partialRight from "lodash/partialRight";

import React from "react";
import BarHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";

@@ -113,3 +113,3 @@ import { Helpers, VictoryLabel, VictoryContainer, VictoryTheme, Bar, addEvents, Data, Domain } from "victory-core";

VictoryBar.getData = Data.getData.bind(Data);
VictoryBar.getBaseProps = _partialRight(BarHelpers.getBaseProps.bind(BarHelpers), fallbackProps);
VictoryBar.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryBar.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];

@@ -116,0 +116,0 @@

@@ -12,193 +12,198 @@ import _isNaN from "lodash/isNaN";

export default {
getBaseProps: function (props, fallbackProps) {
var _this = this;
var sortData = function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
// eslint-disable-line max-statements
props = Helpers.modifyProps(props, fallbackProps, "candlestick");
var calculatedValues = this.getCalculatedValues(props);
var data = calculatedValues.data,
style = calculatedValues.style,
scale = calculatedValues.scale,
domain = calculatedValues.domain,
origin = calculatedValues.origin;
var _props = props,
groupComponent = _props.groupComponent,
width = _props.width,
height = _props.height,
padding = _props.padding,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
wickStrokeWidth = _props.wickStrokeWidth;
if (!sortKey) {
return dataset;
}
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone, theme: theme, polar: polar, origin: origin,
style: style.parent, padding: padding
} };
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
}
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var high = scale.y(datum._high);
var close = scale.y(datum._close);
var open = scale.y(datum._open);
var low = scale.y(datum._low);
var candleHeight = Math.abs(scale.y(datum._open) - scale.y(datum._close));
var dataStyle = _this.getDataStyles(datum, style.data, props);
var dataProps = {
x: x, high: high, low: low, candleHeight: candleHeight, scale: scale, data: data, datum: datum, groupComponent: groupComponent, index: index,
style: dataStyle, padding: padding, width: width, polar: polar, origin: origin, wickStrokeWidth: wickStrokeWidth, open: open, close: close
};
var sortedData = _sortBy(dataset, sortKey);
childProps[eventKey] = {
data: dataProps
};
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = _this.getLabelProps(dataProps, text, style);
}
if (sortOrder === "descending") {
return sortedData.reverse();
}
return childProps;
}, initialChildProps);
},
getLabelProps: function (dataProps, text, style) {
var x = dataProps.x,
high = dataProps.high,
index = dataProps.index,
scale = dataProps.scale,
datum = dataProps.datum,
data = dataProps.data;
return sortedData;
};
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: high - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: datum,
data: data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
},
getCalculatedValues: function (props) {
var theme = props.theme,
polar = props.polar;
var getData = function (props) {
if (!props.data || Data.getLength(props.data) < 1) {
return [];
}
var stringMap = {
x: Data.createStringMap(props, "x")
};
var defaultStyle = theme && theme.candlestick && theme.candlestick.style ? theme.candlestick.style : {};
var style = Helpers.getStyles(props.style, defaultStyle);
var data = Data.addEventKeys(props, this.getData(props));
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: this.getDomain(props, "x"),
y: this.getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
},
getData: function (props) {
if (!props.data || Data.getLength(props.data) < 1) {
return [];
}
var stringMap = {
x: Data.createStringMap(props, "x")
};
var accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
open: Helpers.createAccessor(props.open !== undefined ? props.open : "open"),
close: Helpers.createAccessor(props.close !== undefined ? props.close : "close"),
high: Helpers.createAccessor(props.high !== undefined ? props.high : "high"),
low: Helpers.createAccessor(props.low !== undefined ? props.low : "low")
};
var accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
open: Helpers.createAccessor(props.open !== undefined ? props.open : "open"),
close: Helpers.createAccessor(props.close !== undefined ? props.close : "close"),
high: Helpers.createAccessor(props.high !== undefined ? props.high : "high"),
low: Helpers.createAccessor(props.low !== undefined ? props.low : "low")
};
var formattedData = props.data.reduce(function (dataArr, datum, index) {
datum = Data.parseDatum(datum);
var formattedData = props.data.reduce(function (dataArr, datum, index) {
datum = Data.parseDatum(datum);
var evaluatedX = accessor.x(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _open = accessor.open(datum);
var _close = accessor.close(datum);
var _high = accessor.high(datum);
var _low = accessor.low(datum);
var _y = [_open, _close, _high, _low];
var evaluatedX = accessor.x(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _open = accessor.open(datum);
var _close = accessor.close(datum);
var _high = accessor.high(datum);
var _low = accessor.low(datum);
var _y = [_open, _close, _high, _low];
dataArr.push(_assign({}, datum, { _x: _x, _y: _y, _open: _open, _close: _close, _high: _high, _low: _low }, typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}));
dataArr.push(_assign({}, datum, { _x: _x, _y: _y, _open: _open, _close: _close, _high: _high, _low: _low }, typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}));
return dataArr;
}, []);
return dataArr;
return sortData(formattedData, props.sortKey, props.sortOrder);
};
var getDomain = function (props, axis) {
var domain = void 0;
if (props.domain && props.domain[axis]) {
domain = props.domain[axis];
} else if (props.domain && Array.isArray(props.domain)) {
domain = props.domain;
} else {
var dataset = getData(props);
var allData = dataset.reduce(function (memo, datum) {
return Array.isArray(datum["_" + axis]) ? memo.concat.apply(memo, _toConsumableArray(datum["_" + axis])) : memo.concat(datum["_" + axis]);
}, []);
return this.sortData(formattedData, props.sortKey, props.sortOrder);
},
sortData: function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
if (!sortKey) {
return dataset;
if (allData.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
domain = [min, max];
}
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
};
var sortedData = _sortBy(dataset, sortKey);
var getCalculatedValues = function (props) {
var theme = props.theme,
polar = props.polar;
if (sortOrder === "descending") {
return sortedData.reverse();
}
var defaultStyle = theme && theme.candlestick && theme.candlestick.style ? theme.candlestick.style : {};
var style = Helpers.getStyles(props.style, defaultStyle);
var data = Data.addEventKeys(props, getData(props));
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: getDomain(props, "x"),
y: getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
};
return sortedData;
},
getDomain: function (props, axis) {
var domain = void 0;
if (props.domain && props.domain[axis]) {
domain = props.domain[axis];
} else if (props.domain && Array.isArray(props.domain)) {
domain = props.domain;
} else {
var dataset = this.getData(props);
var allData = dataset.reduce(function (memo, datum) {
return Array.isArray(datum["_" + axis]) ? memo.concat.apply(memo, _toConsumableArray(datum["_" + axis])) : memo.concat(datum["_" + axis]);
}, []);
var isTransparent = function (attr) {
return attr === "none" || attr === "transparent";
};
if (allData.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
var getDataStyles = function (datum, style, props) {
style = style || {};
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "_x", "_y", "_y0", "size", "name", "label", "open", "close", "high", "low", "eventKey"];
var stylesFromData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
var candleColor = datum.open > datum.close ? props.candleColors.negative : props.candleColors.positive;
var fill = datum.fill || style.fill || candleColor;
var strokeColor = datum.stroke || style.stroke;
var stroke = isTransparent(strokeColor) ? fill : strokeColor || "black";
return _defaults({}, stylesFromData, { stroke: stroke, fill: fill }, style);
};
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
domain = [min, max];
var getLabelProps = function (dataProps, text, style) {
var x = dataProps.x,
high = dataProps.high,
index = dataProps.index,
scale = dataProps.scale,
datum = dataProps.datum,
data = dataProps.data;
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: high - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: datum,
data: data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
};
var getBaseProps = function (props, fallbackProps) {
// eslint-disable-line max-statements
props = Helpers.modifyProps(props, fallbackProps, "candlestick");
var calculatedValues = getCalculatedValues(props);
var data = calculatedValues.data,
style = calculatedValues.style,
scale = calculatedValues.scale,
domain = calculatedValues.domain,
origin = calculatedValues.origin;
var _props = props,
groupComponent = _props.groupComponent,
width = _props.width,
height = _props.height,
padding = _props.padding,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
wickStrokeWidth = _props.wickStrokeWidth;
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone, theme: theme, polar: polar, origin: origin,
style: style.parent, padding: padding
} };
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var high = scale.y(datum._high);
var close = scale.y(datum._close);
var open = scale.y(datum._open);
var low = scale.y(datum._low);
var candleHeight = Math.abs(scale.y(datum._open) - scale.y(datum._close));
var dataStyle = getDataStyles(datum, style.data, props);
var dataProps = {
x: x, high: high, low: low, candleHeight: candleHeight, scale: scale, data: data, datum: datum, groupComponent: groupComponent, index: index,
style: dataStyle, padding: padding, width: width, polar: polar, origin: origin, wickStrokeWidth: wickStrokeWidth, open: open, close: close
};
childProps[eventKey] = {
data: dataProps
};
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
},
isTransparent: function (attr) {
return attr === "none" || attr === "transparent";
},
getDataStyles: function (datum, style, props) {
style = style || {};
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "_x", "_y", "_y0", "size", "name", "label", "open", "close", "high", "low", "eventKey"];
var stylesFromData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
var candleColor = datum.open > datum.close ? props.candleColors.negative : props.candleColors.positive;
var fill = datum.fill || style.fill || candleColor;
var strokeColor = datum.stroke || style.stroke;
var stroke = this.isTransparent(strokeColor) ? fill : strokeColor || "black";
return _defaults({}, stylesFromData, { stroke: stroke, fill: fill }, style);
}
};
return childProps;
}, initialChildProps);
};
export { getBaseProps, getDomain, getData };

@@ -17,3 +17,3 @@ import _partialRight from "lodash/partialRight";

import { PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents, VictoryContainer, VictoryTheme, DefaultTransitions, Candle } from "victory-core";
import CandlestickHelpers from "./helper-methods";
import { getDomain, getData, getBaseProps } from "./helper-methods";
import { BaseProps, DataProps } from "../../helpers/common-props";

@@ -94,5 +94,5 @@

};
VictoryCandlestick.getDomain = CandlestickHelpers.getDomain.bind(CandlestickHelpers);
VictoryCandlestick.getData = CandlestickHelpers.getData.bind(CandlestickHelpers);
VictoryCandlestick.getBaseProps = _partialRight(CandlestickHelpers.getBaseProps.bind(CandlestickHelpers), fallbackProps);
VictoryCandlestick.getDomain = getDomain;
VictoryCandlestick.getData = getData;
VictoryCandlestick.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryCandlestick.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];

@@ -99,0 +99,0 @@

@@ -8,110 +8,113 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

export default {
getChildComponents: function (props, defaultAxes) {
var childComponents = React.Children.toArray(props.children);
if (childComponents.length === 0) {
return [defaultAxes.independent, defaultAxes.dependent];
}
var getDataComponents = function (childComponents) {
var findDataComponents = function (children) {
return children.reduce(function (memo, child) {
if (child.type && child.type.role === "axis") {
return memo;
} else if (child.props && child.props.children) {
return memo.concat(findDataComponents(React.Children.toArray(child.props.children)));
}
return memo.concat(child);
}, []);
};
var axisComponents = {
dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"),
independent: Axis.getAxisComponentsWithParent(childComponents, "independent")
};
return findDataComponents(childComponents);
};
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
if (axisComponents.independent.length > 1) {
var msg = "Only one independent VictoryAxis component is allowed when " + "using the VictoryChart wrapper. Only the first axis will be used. Please compose " + "multi-axis charts manually";
Log.warn(msg);
var dataComponents = this.getDataComponents(childComponents);
return Collection.removeUndefined(dataComponents.concat([].concat(_toConsumableArray(axisComponents.dependent), [axisComponents.independent[0]])));
}
return childComponents;
},
getDefaultDomainPadding: function (childComponents, horizontal) {
var groupComponent = childComponents.filter(function (child) {
return child.type && child.type.role && child.type.role === "group-wrapper";
});
var getChildComponents = function (props, defaultAxes) {
var childComponents = React.Children.toArray(props.children);
if (childComponents.length === 0) {
return [defaultAxes.independent, defaultAxes.dependent];
}
if (groupComponent.length < 1) {
return undefined;
}
var axisComponents = {
dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"),
independent: Axis.getAxisComponentsWithParent(childComponents, "independent")
};
var _groupComponent$0$pro = groupComponent[0].props,
offset = _groupComponent$0$pro.offset,
children = _groupComponent$0$pro.children;
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
if (axisComponents.independent.length > 1) {
var msg = "Only one independent VictoryAxis component is allowed when " + "using the VictoryChart wrapper. Only the first axis will be used. Please compose " + "multi-axis charts manually";
Log.warn(msg);
var dataComponents = getDataComponents(childComponents);
return Collection.removeUndefined(dataComponents.concat([].concat(_toConsumableArray(axisComponents.dependent), [axisComponents.independent[0]])));
}
return childComponents;
};
return horizontal ? { y: offset * children.length / 2 } : { x: offset * children.length / 2 };
},
getDataComponents: function (childComponents) {
var findDataComponents = function (children) {
return children.reduce(function (memo, child) {
if (child.type && child.type.role === "axis") {
return memo;
} else if (child.props && child.props.children) {
return memo.concat(findDataComponents(React.Children.toArray(child.props.children)));
}
return memo.concat(child);
}, []);
};
var getDefaultDomainPadding = function (childComponents, horizontal) {
var groupComponent = childComponents.filter(function (child) {
return child.type && child.type.role && child.type.role === "group-wrapper";
});
return findDataComponents(childComponents);
},
getDomain: function (props, axis, childComponents) {
childComponents = childComponents || React.Children.toArray(props.children);
var domain = Wrapper.getDomain(props, axis, childComponents);
var axisComponent = Axis.getAxisComponent(childComponents, axis);
var invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis;
return invertDomain ? domain.concat().reverse() : domain;
},
if (groupComponent.length < 1) {
return undefined;
}
var _groupComponent$0$pro = groupComponent[0].props,
offset = _groupComponent$0$pro.offset,
children = _groupComponent$0$pro.children;
// eslint-disable-next-line complexity
getAxisOffset: function (props, calculatedProps) {
var axisComponents = calculatedProps.axisComponents,
scale = calculatedProps.scale,
origin = calculatedProps.origin,
domain = calculatedProps.domain,
originSign = calculatedProps.originSign,
padding = calculatedProps.padding;
var top = padding.top,
bottom = padding.bottom,
left = padding.left,
right = padding.right;
// make the axes line up, and cross when appropriate
return horizontal ? { y: offset * children.length / 2 } : { x: offset * children.length / 2 };
};
var axisOrientations = {
x: Axis.getOrientation(axisComponents.x, "x", originSign.y),
y: Axis.getOrientation(axisComponents.y, "y", originSign.x)
};
var orientationOffset = {
y: axisOrientations.x === "bottom" ? bottom : top,
x: axisOrientations.y === "left" ? left : right
};
var originOffset = {
x: axisOrientations.y === "left" ? 0 : props.width,
y: axisOrientations.x === "bottom" ? props.height : 0
};
var originPosition = {
x: origin.x === domain.x[0] || origin.x === domain.x[1] ? 0 : scale.x(origin.x),
y: origin.y === domain.y[0] || origin.y === domain.y[1] ? 0 : scale.y(origin.y)
};
var calculatedOffset = {
x: originPosition.x ? Math.abs(originOffset.x - originPosition.x) : orientationOffset.x,
y: originPosition.y ? Math.abs(originOffset.y - originPosition.y) : orientationOffset.y
};
var getDomain = function (props, axis, childComponents) {
childComponents = childComponents || React.Children.toArray(props.children);
var domain = Wrapper.getDomain(props, axis, childComponents);
var axisComponent = Axis.getAxisComponent(childComponents, axis);
var invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis;
return invertDomain ? domain.concat().reverse() : domain;
};
return {
x: axisComponents.x && axisComponents.x.offsetX !== undefined ? axisComponents.x.offsetX : calculatedOffset.x,
y: axisComponents.y && axisComponents.y.offsetY !== undefined ? axisComponents.y.offsetY : calculatedOffset.y
};
},
createStringMap: function (props, axis, childComponents) {
var allStrings = Wrapper.getStringsFromChildren(props, axis, childComponents);
return allStrings.length === 0 ? null : allStrings.reduce(function (memo, string, index) {
memo[string] = index + 1;
return memo;
}, {});
}
};
// eslint-disable-next-line complexity
var getAxisOffset = function (props, calculatedProps) {
var axisComponents = calculatedProps.axisComponents,
scale = calculatedProps.scale,
origin = calculatedProps.origin,
domain = calculatedProps.domain,
originSign = calculatedProps.originSign,
padding = calculatedProps.padding;
var top = padding.top,
bottom = padding.bottom,
left = padding.left,
right = padding.right;
// make the axes line up, and cross when appropriate
var axisOrientations = {
x: Axis.getOrientation(axisComponents.x, "x", originSign.y),
y: Axis.getOrientation(axisComponents.y, "y", originSign.x)
};
var orientationOffset = {
y: axisOrientations.x === "bottom" ? bottom : top,
x: axisOrientations.y === "left" ? left : right
};
var originOffset = {
x: axisOrientations.y === "left" ? 0 : props.width,
y: axisOrientations.x === "bottom" ? props.height : 0
};
var originPosition = {
x: origin.x === domain.x[0] || origin.x === domain.x[1] ? 0 : scale.x(origin.x),
y: origin.y === domain.y[0] || origin.y === domain.y[1] ? 0 : scale.y(origin.y)
};
var calculatedOffset = {
x: originPosition.x ? Math.abs(originOffset.x - originPosition.x) : orientationOffset.x,
y: originPosition.y ? Math.abs(originOffset.y - originPosition.y) : orientationOffset.y
};
return {
x: axisComponents.x && axisComponents.x.offsetX !== undefined ? axisComponents.x.offsetX : calculatedOffset.x,
y: axisComponents.y && axisComponents.y.offsetY !== undefined ? axisComponents.y.offsetY : calculatedOffset.y
};
};
var createStringMap = function (props, axis, childComponents) {
var allStrings = Wrapper.getStringsFromChildren(props, axis, childComponents);
return allStrings.length === 0 ? null : allStrings.reduce(function (memo, string, index) {
memo[string] = index + 1;
return memo;
}, {});
};
export { getDomain, getAxisOffset, getDataComponents, getChildComponents, getDefaultDomainPadding, createStringMap };

@@ -18,3 +18,3 @@ import _defaults from "lodash/defaults";

import VictoryPolarAxis from "../victory-polar-axis/victory-polar-axis";
import ChartHelpers from "./helper-methods";
import { getDomain, getAxisOffset, getChildComponents, getDefaultDomainPadding, createStringMap } from "./helper-methods";
import Axis from "../../helpers/axis";

@@ -89,3 +89,3 @@ import Wrapper from "../../helpers/wrapper";

var otherAxis = axis === "x" ? "y" : "x";
var axisOffset = ChartHelpers.getAxisOffset(props, calculatedProps);
var axisOffset = getAxisOffset(props, calculatedProps);
var offsetY = axis === "y" ? undefined : axisOffset.y;

@@ -135,4 +135,4 @@ var offsetX = axis === "x" ? undefined : axisOffset.x;

var domain = {
x: ChartHelpers.getDomain(props, "x", childComponents),
y: ChartHelpers.getDomain(props, "y", childComponents)
x: getDomain(props, "x", childComponents),
y: getDomain(props, "y", childComponents)
};

@@ -166,7 +166,7 @@ var range = {

var stringMap = {
x: ChartHelpers.createStringMap(props, "x", childComponents),
y: ChartHelpers.createStringMap(props, "y", childComponents)
x: createStringMap(props, "x", childComponents),
y: createStringMap(props, "y", childComponents)
};
var defaultDomainPadding = ChartHelpers.getDefaultDomainPadding(childComponents, horizontal);
var defaultDomainPadding = getDefaultDomainPadding(childComponents, horizontal);

@@ -245,3 +245,3 @@ var padding = Helpers.getPadding(props);

var axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes;
var childComponents = ChartHelpers.getChildComponents(modifiedProps, axes);
var childComponents = getChildComponents(modifiedProps, axes);
var calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);

@@ -248,0 +248,0 @@ var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);

@@ -14,248 +14,255 @@ import _isNaN from "lodash/isNaN";

export default {
getBaseProps: function (props, fallbackProps) {
var _this = this;
var getErrors = function (datum, scale, axis) {
/**
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
* and the first value is the positive error, the second is the negative error
* @param {Boolean} isArray(errorX)
* @return {String or Array}
*/
props = Helpers.modifyProps(props, fallbackProps, "errorbar");
var errorNames = { x: "errorX", y: "errorY" };
var errors = datum[errorNames[axis]];
if (errors === 0) {
return false;
}
var _getCalculatedValues = this.getCalculatedValues(props, fallbackProps),
data = _getCalculatedValues.data,
style = _getCalculatedValues.style,
scale = _getCalculatedValues.scale,
domain = _getCalculatedValues.domain,
origin = _getCalculatedValues.origin;
return _isArray(errors) ? [errors[0] === 0 ? false : scale[axis](errors[0] + datum["_" + axis]), errors[1] === 0 ? false : scale[axis](datum["_" + axis] - errors[1])] : [scale[axis](errors + datum["_" + axis]), scale[axis](datum["_" + axis] - errors)];
};
var _props = props,
groupComponent = _props.groupComponent,
height = _props.height,
width = _props.width,
borderWidth = _props.borderWidth,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
padding = _props.padding;
var sortData = function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
var initialChildProps = { parent: {
domain: domain, scale: scale, data: data, height: height, width: width, standalone: standalone, theme: theme, polar: polar, origin: origin,
padding: padding, style: style.parent
} };
if (!sortKey) {
return dataset;
}
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
}
var dataProps = {
x: x, y: y, scale: scale, datum: datum, data: data, index: index, groupComponent: groupComponent, borderWidth: borderWidth,
style: _this.getDataStyles(datum, style.data),
errorX: _this.getErrors(datum, scale, "x"),
errorY: _this.getErrors(datum, scale, "y")
};
var sortedData = _sortBy(dataset, sortKey);
childProps[eventKey] = {
data: dataProps
};
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = _this.getLabelProps(dataProps, text, style);
}
if (sortOrder === "descending") {
return sortedData.reverse();
}
return childProps;
}, initialChildProps);
},
getLabelProps: function (dataProps, text, style) {
var x = dataProps.x,
index = dataProps.index,
scale = dataProps.scale,
errorY = dataProps.errorY;
return sortedData;
};
var error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
var y = error || dataProps.y;
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: y - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: dataProps.datum,
data: dataProps.data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
var formatErrorData = function (dataset, props) {
if (!dataset || Data.getLength(dataset) < 1) {
return [];
}
var accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
errorX: Helpers.createAccessor(props.errorX !== undefined ? props.errorX : "errorX"),
errorY: Helpers.createAccessor(props.errorY !== undefined ? props.errorY : "errorY")
};
var replaceNegatives = function (errors) {
// check if the value is negative, if it is set to 0
var replaceNeg = function (val) {
return !val || val < 0 ? 0 : val;
};
},
getErrorData: function (props) {
if (props.data) {
if (Data.getLength(props.data) < 1) {
return [];
}
return _isArray(errors) ? errors.map(function (err) {
return replaceNeg(err);
}) : replaceNeg(errors);
};
return this.formatErrorData(props.data, props);
} else {
var generatedData = (props.errorX || props.errorY) && this.generateData(props);
return this.formatErrorData(generatedData, props);
}
},
getErrors: function (datum, scale, axis) {
/**
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
* and the first value is the positive error, the second is the negative error
* @param {Boolean} isArray(errorX)
* @return {String or Array}
*/
var stringMap = {
x: Data.createStringMap(props, "x"),
y: Data.createStringMap(props, "y")
};
var errorNames = { x: "errorX", y: "errorY" };
var errors = datum[errorNames[axis]];
if (errors === 0) {
return false;
}
var formattedData = dataset.reduce(function (dataArr, datum, index) {
datum = Data.parseDatum(datum);
return _isArray(errors) ? [errors[0] === 0 ? false : scale[axis](errors[0] + datum["_" + axis]), errors[1] === 0 ? false : scale[axis](datum["_" + axis] - errors[1])] : [scale[axis](errors + datum["_" + axis]), scale[axis](datum["_" + axis] - errors)];
},
formatErrorData: function (dataset, props) {
if (!dataset || Data.getLength(dataset) < 1) {
var evaluatedX = accessor.x(datum);
var evaluatedY = accessor.y(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _y = evaluatedY !== undefined ? evaluatedY : datum;
var errorX = replaceNegatives(accessor.errorX(datum));
var errorY = replaceNegatives(accessor.errorY(datum));
dataArr.push(_assign({}, datum, { _x: _x, _y: _y, errorX: errorX, errorY: errorY },
// map string data to numeric values, and add names
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}, typeof _y === "string" ? { _y: stringMap.y[_y], y: _y } : {}));
return dataArr;
}, []);
return sortData(formattedData, props.sortKey, props.sortOrder);
};
var getErrorData = function (props) {
if (props.data) {
if (Data.getLength(props.data) < 1) {
return [];
}
var accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
errorX: Helpers.createAccessor(props.errorX !== undefined ? props.errorX : "errorX"),
errorY: Helpers.createAccessor(props.errorY !== undefined ? props.errorY : "errorY")
};
var replaceNegatives = function (errors) {
// check if the value is negative, if it is set to 0
var replaceNeg = function (val) {
return !val || val < 0 ? 0 : val;
};
return _isArray(errors) ? errors.map(function (err) {
return replaceNeg(err);
}) : replaceNeg(errors);
};
return formatErrorData(props.data, props);
} else {
var generatedData = (props.errorX || props.errorY) && Data.generateData(props);
return formatErrorData(generatedData, props);
}
};
var stringMap = {
x: Data.createStringMap(props, "x"),
y: Data.createStringMap(props, "y")
};
var getDomainFromData = function (props, axis, dataset) {
var currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
var error = void 0;
if (currentAxis === "x") {
error = "errorX";
} else if (currentAxis === "y") {
error = "errorY";
}
var axisData = _flatten(dataset).map(function (datum) {
return datum["_" + currentAxis];
});
var errorData = _flatten(_flatten(dataset).map(function (datum) {
var errorMax = void 0;
var errorMin = void 0;
if (_isArray(datum[error])) {
errorMax = datum[error][0] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error][1];
} else {
errorMax = datum[error] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error];
}
return [errorMax, errorMin];
}));
var formattedData = dataset.reduce(function (dataArr, datum, index) {
datum = Data.parseDatum(datum);
var allData = axisData.concat(errorData);
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
// TODO: is the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
return [min, max];
};
var evaluatedX = accessor.x(datum);
var evaluatedY = accessor.y(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _y = evaluatedY !== undefined ? evaluatedY : datum;
var errorX = replaceNegatives(accessor.errorX(datum));
var errorY = replaceNegatives(accessor.errorY(datum));
var getDomain = function (props, axis) {
var propsDomain = Domain.getDomainFromProps(props, axis);
if (propsDomain) {
return Domain.padDomain(propsDomain, props, axis);
}
var categoryDomain = Domain.getDomainFromCategories(props, axis);
if (categoryDomain) {
return Domain.padDomain(categoryDomain, props, axis);
}
var dataset = getErrorData(props);
dataArr.push(_assign({}, datum, { _x: _x, _y: _y, errorX: errorX, errorY: errorY },
// map string data to numeric values, and add names
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}, typeof _y === "string" ? { _y: stringMap.y[_y], y: _y } : {}));
if (dataset.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
return dataArr;
}, []);
var domain = getDomainFromData(props, axis, dataset);
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
};
return this.sortData(formattedData, props.sortKey, props.sortOrder);
},
sortData: function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
var getCalculatedValues = function (props) {
var defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ? props.theme.errorbar.style : {};
var style = Helpers.getStyles(props.style, defaultStyles) || {};
var dataWithErrors = _assign(Data.getData(props), getErrorData(props));
var data = Data.addEventKeys(props, dataWithErrors);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: getDomain(props, "x"),
y: getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
};
if (!sortKey) {
return dataset;
}
var getLabelProps = function (dataProps, text, style) {
var x = dataProps.x,
index = dataProps.index,
scale = dataProps.scale,
errorY = dataProps.errorY;
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
}
var error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
var y = error || dataProps.y;
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: y - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: dataProps.datum,
data: dataProps.data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
};
var sortedData = _sortBy(dataset, sortKey);
var getDataStyles = function (datum, style) {
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "y", "_x", "_y", "name", "errorX", "errorY", "eventKey", "label"];
var stylesFromData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return _defaults({}, stylesFromData, style);
};
if (sortOrder === "descending") {
return sortedData.reverse();
}
var getBaseProps = function (props, fallbackProps) {
props = Helpers.modifyProps(props, fallbackProps, "errorbar");
return sortedData;
},
getDomain: function (props, axis) {
var propsDomain = Domain.getDomainFromProps(props, axis);
if (propsDomain) {
return Domain.padDomain(propsDomain, props, axis);
}
var categoryDomain = Domain.getDomainFromCategories(props, axis);
if (categoryDomain) {
return Domain.padDomain(categoryDomain, props, axis);
}
var dataset = this.getErrorData(props);
var _getCalculatedValues = getCalculatedValues(props, fallbackProps),
data = _getCalculatedValues.data,
style = _getCalculatedValues.style,
scale = _getCalculatedValues.scale,
domain = _getCalculatedValues.domain,
origin = _getCalculatedValues.origin;
if (dataset.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
var _props = props,
groupComponent = _props.groupComponent,
height = _props.height,
width = _props.width,
borderWidth = _props.borderWidth,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
padding = _props.padding;
var domain = this.getDomainFromData(props, axis, dataset);
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
},
getDomainFromData: function (props, axis, dataset) {
var currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
var error = void 0;
if (currentAxis === "x") {
error = "errorX";
} else if (currentAxis === "y") {
error = "errorY";
}
var axisData = _flatten(dataset).map(function (datum) {
return datum["_" + currentAxis];
});
var errorData = _flatten(_flatten(dataset).map(function (datum) {
var errorMax = void 0;
var errorMin = void 0;
if (_isArray(datum[error])) {
errorMax = datum[error][0] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error][1];
} else {
errorMax = datum[error] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error];
}
return [errorMax, errorMin];
}));
var initialChildProps = { parent: {
domain: domain, scale: scale, data: data, height: height, width: width, standalone: standalone, theme: theme, polar: polar, origin: origin,
padding: padding, style: style.parent
} };
var allData = axisData.concat(errorData);
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
// TODO: is this the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
return [min, max];
},
getCalculatedValues: function (props) {
var defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ? props.theme.errorbar.style : {};
var style = Helpers.getStyles(props.style, defaultStyles) || {};
var dataWithErrors = _assign(Data.getData(props), this.getErrorData(props));
var data = Data.addEventKeys(props, dataWithErrors);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
var dataProps = {
x: x, y: y, scale: scale, datum: datum, data: data, index: index, groupComponent: groupComponent, borderWidth: borderWidth,
style: getDataStyles(datum, style.data),
errorX: getErrors(datum, scale, "x"),
errorY: getErrors(datum, scale, "y")
};
var domain = {
x: this.getDomain(props, "x"),
y: this.getDomain(props, "y")
childProps[eventKey] = {
data: dataProps
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
},
getDataStyles: function (datum, style) {
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "y", "_x", "_y", "name", "errorX", "errorY", "eventKey", "label"];
var stylesFromData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return _defaults({}, stylesFromData, style);
}
};
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}
return childProps;
}, initialChildProps);
};
export { getBaseProps, getDomain };

@@ -17,3 +17,3 @@ import _partialRight from "lodash/partialRight";

import ErrorBarHelpers from "./helper-methods";
import { getBaseProps, getDomain } from "./helper-methods";
import { BaseProps, DataProps } from "../../helpers/common-props";

@@ -86,5 +86,5 @@

};
VictoryErrorBar.getDomain = ErrorBarHelpers.getDomain.bind(ErrorBarHelpers);
VictoryErrorBar.getDomain = getDomain;
VictoryErrorBar.getData = Data.getData.bind(Data);
VictoryErrorBar.getBaseProps = _partialRight(ErrorBarHelpers.getBaseProps.bind(ErrorBarHelpers), fallbackProps);
VictoryErrorBar.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryErrorBar.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];

@@ -91,0 +91,0 @@

@@ -5,64 +5,65 @@ import _assign from "lodash/assign";

export default {
getBaseProps: function (props, fallbackProps) {
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "line");
props = _assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getCalculatedValues = function (props) {
var data = Data.getData(props);
var initialChildProps = {
parent: {
style: style.parent, scale: scale, data: data, height: height, width: width, domain: domain, standalone: standalone, polar: polar, origin: origin, padding: padding
},
all: { data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, theme: theme, style: style.data }
}
};
return data.reduce(function (childProps, datum, index) {
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
},
getCalculatedValues: function (props) {
var data = Data.getData(props);
if (data.length < 2) {
data = [];
}
if (data.length < 2) {
data = [];
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
var defaultStyles = props.theme && props.theme.line && props.theme.line.style ? props.theme.line.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
};
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "line");
props = _assign({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var initialChildProps = {
parent: {
style: style.parent, scale: scale, data: data, height: height, width: width, domain: domain, standalone: standalone, polar: polar, origin: origin, padding: padding
},
all: { data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, theme: theme, style: style.data }
}
};
return data.reduce(function (childProps, datum, index) {
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
};
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
var defaultStyles = props.theme && props.theme.line && props.theme.line.style ? props.theme.line.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
}
};
export { getBaseProps };

@@ -15,3 +15,3 @@ import _partialRight from "lodash/partialRight";

import React from "react";
import LineHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import { PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents, VictoryContainer, VictoryTheme, DefaultTransitions, Curve, VictoryClipContainer, Data, Domain } from "victory-core";

@@ -90,5 +90,5 @@ import { BaseProps, DataProps } from "../../helpers/common-props";

VictoryLine.getData = Data.getData.bind(Data);
VictoryLine.getBaseProps = _partialRight(LineHelpers.getBaseProps.bind(LineHelpers), fallbackProps);
VictoryLine.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryLine.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
export default addEvents(VictoryLine, options);

@@ -10,370 +10,384 @@ import _isFunction from "lodash/isFunction";

export default {
getCalculatedValues: function (props) {
var defaultStyles = this.getStyleObject(props);
var style = this.getStyles(props, defaultStyles);
var padding = Helpers.getPadding(props);
var axis = this.getAxis(props);
var axisType = this.getAxisType(props);
var stringTicks = Helpers.stringTicks(props) ? props.tickValues : undefined;
var domain = this.getDomain(props, axis);
var range = this.getRange(props, axis);
var scale = this.getScale(props);
var initialTicks = Axis.getTicks(props, scale);
var ticks = axisType === "angular" ? this.filterTicks(initialTicks, scale) : initialTicks;
var tickFormat = Axis.getTickFormat(props, scale);
var radius = this.getRadius(props);
return {
axis: axis, style: style, padding: padding, stringTicks: stringTicks, axisType: axisType, scale: scale, ticks: ticks, tickFormat: tickFormat, domain: domain, range: range, radius: radius
};
},
evaluateProp: function (prop, data, index) {
return _isFunction(prop) ? prop(data, index) : prop;
},
evaluateStyle: function (style, data, index) {
var _this = this;
// exposed for use by VictoryChart
var getAxis = function (props, flipped) {
var typicalAxis = props.dependentAxis ? "y" : "x";
var invertedAxis = typicalAxis === "x" ? "y" : "x";
return flipped ? invertedAxis : typicalAxis;
};
if (!style || !Object.keys(style).some(function (value) {
return _isFunction(style[value]);
})) {
return style;
}
return Object.keys(style).reduce(function (prev, curr) {
prev[curr] = _this.evaluateProp(style[curr], data, index);
return prev;
}, {});
},
var getPosition = function (r, angle, axis) {
return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle);
};
var getAxisType = function (props) {
var typicalType = props.dependentAxis ? "radial" : "angular";
var invertedType = typicalType === "angular" ? "radial" : "angular";
return props.horizontal ? invertedType : typicalType;
};
// exposed for use by VictoryChart
getDomain: function (props, axis) {
var inherentAxis = this.getAxis(props);
if (axis && axis !== inherentAxis) {
return undefined;
}
var domain = void 0;
if (Array.isArray(props.domain)) {
domain = props.domain;
} else if (props.domain && props.domain[inherentAxis]) {
domain = props.domain[inherentAxis];
} else if (Array.isArray(props.tickValues) && props.tickValues.length > 1) {
domain = this.getDomainFromTickValues(props, axis);
}
var paddedDomain = Domain.padDomain(domain, props, inherentAxis);
return domain ? Domain.cleanDomain(paddedDomain, props, inherentAxis) : undefined;
},
getDomainFromTickValues: function (props, axis) {
var tickValues = props.tickValues,
_props$startAngle = props.startAngle,
startAngle = _props$startAngle === undefined ? 0 : _props$startAngle,
_props$endAngle = props.endAngle,
endAngle = _props$endAngle === undefined ? 360 : _props$endAngle;
var filterTicks = function (ticks, scale) {
var compareTicks = function (t) {
return scale(t) % (2 * Math.PI);
};
return _uniqBy(ticks, compareTicks);
};
if (Helpers.stringTicks(props)) {
return [1, tickValues.length];
} else {
var ticks = tickValues.map(function (value) {
return +value;
});
var domain = [Collection.getMinValue(ticks), Collection.getMaxValue(ticks)];
return axis === "x" && Math.abs(startAngle - endAngle) === 360 ? Domain.getSymmetricDomain(domain, ticks) : domain;
}
},
getRadius: function (props) {
var _Helpers$getPadding = Helpers.getPadding(props),
left = _Helpers$getPadding.left,
right = _Helpers$getPadding.right,
top = _Helpers$getPadding.top,
bottom = _Helpers$getPadding.bottom;
var evaluateProp = function (prop, data, index) {
return _isFunction(prop) ? prop(data, index) : prop;
};
var width = props.width,
height = props.height;
var evaluateStyle = function (style, data, index) {
if (!style || !Object.keys(style).some(function (value) {
return _isFunction(style[value]);
})) {
return style;
}
return Object.keys(style).reduce(function (prev, curr) {
prev[curr] = evaluateProp(style[curr], data, index);
return prev;
}, {});
};
return Math.min(width - left - right, height - top - bottom) / 2;
},
getRange: function (props, axis) {
// Return the range from props if one is given.
if (props.range && props.range[axis]) {
return props.range[axis];
} else if (props.range && Array.isArray(props.range)) {
return props.range;
}
var axisType = this.getAxisType(props);
if (axisType === "angular") {
var startAngle = Helpers.degreesToRadians(props.startAngle);
var endAngle = Helpers.degreesToRadians(props.endAngle);
return [startAngle, endAngle];
}
var radius = this.getRadius(props);
return [props.innerRadius || 0, radius];
},
var getEvaluatedStyles = function (style, tick, index) {
return {
tickStyle: evaluateStyle(style.ticks, tick, index),
labelStyle: evaluateStyle(style.tickLabels, tick, index),
gridStyle: evaluateStyle(style.grid, tick, index)
};
};
var getDomainFromTickValues = function (props, axis) {
var tickValues = props.tickValues,
_props$startAngle = props.startAngle,
startAngle = _props$startAngle === undefined ? 0 : _props$startAngle,
_props$endAngle = props.endAngle,
endAngle = _props$endAngle === undefined ? 360 : _props$endAngle;
// exposed for use by VictoryChart
getAxis: function (props, flipped) {
var typicalAxis = props.dependentAxis ? "y" : "x";
var invertedAxis = typicalAxis === "x" ? "y" : "x";
return flipped ? invertedAxis : typicalAxis;
},
getAxisType: function (props) {
var typicalType = props.dependentAxis ? "radial" : "angular";
var invertedType = typicalType === "angular" ? "radial" : "angular";
return props.horizontal ? invertedType : typicalType;
},
if (Helpers.stringTicks(props)) {
return [1, tickValues.length];
} else {
var ticks = tickValues.map(function (value) {
return +value;
});
var domain = [Collection.getMinValue(ticks), Collection.getMaxValue(ticks)];
return axis === "x" && Math.abs(startAngle - endAngle) === 360 ? Domain.getSymmetricDomain(domain, ticks) : domain;
}
};
// exposed for use by VictoryChart
var getDomain = function (props, axis) {
var inherentAxis = getAxis(props);
if (axis && axis !== inherentAxis) {
return undefined;
}
var domain = void 0;
if (Array.isArray(props.domain)) {
domain = props.domain;
} else if (props.domain && props.domain[inherentAxis]) {
domain = props.domain[inherentAxis];
} else if (Array.isArray(props.tickValues) && props.tickValues.length > 1) {
domain = getDomainFromTickValues(props, axis);
}
var paddedDomain = Domain.padDomain(domain, props, inherentAxis);
return domain ? Domain.cleanDomain(paddedDomain, props, inherentAxis) : undefined;
};
// exposed for use by VictoryChart (necessary?)
getScale: function (props) {
var axis = this.getAxis(props);
var scale = Scale.getBaseScale(props, axis);
var domain = this.getDomain(props, axis) || scale.domain();
var range = this.getRange(props, axis);
scale.range(range);
scale.domain(domain);
return scale;
},
getStyleObject: function (props) {
var theme = props.theme,
dependentAxis = props.dependentAxis;
var getStyleObject = function (props) {
var theme = props.theme,
dependentAxis = props.dependentAxis;
var generalAxisStyle = theme && theme.axis && theme.axis.style;
var axisType = dependentAxis ? "dependentAxis" : "independentAxis";
var specificAxisStyle = theme && theme[axisType] && theme[axisType].style;
var generalAxisStyle = theme && theme.axis && theme.axis.style;
var axisType = dependentAxis ? "dependentAxis" : "independentAxis";
var specificAxisStyle = theme && theme[axisType] && theme[axisType].style;
return generalAxisStyle && specificAxisStyle ? _defaultsDeep({}, specificAxisStyle, generalAxisStyle) : specificAxisStyle || generalAxisStyle;
},
getStyles: function (props, styleObject) {
var style = props.style || {};
styleObject = styleObject || {};
var parentStyleProps = { height: "auto", width: "100%" };
return {
parent: _defaults(parentStyleProps, style.parent, styleObject.parent),
axis: _defaults({}, style.axis, styleObject.axis),
axisLabel: _defaults({}, style.axisLabel, styleObject.axisLabel),
grid: _defaults({}, style.grid, styleObject.grid),
ticks: _defaults({}, style.ticks, styleObject.ticks),
tickLabels: _defaults({}, style.tickLabels, styleObject.tickLabels)
};
},
getAxisAngle: function (props) {
var axisAngle = props.axisAngle,
startAngle = props.startAngle,
axisValue = props.axisValue,
dependentAxis = props.dependentAxis,
scale = props.scale;
return generalAxisStyle && specificAxisStyle ? _defaultsDeep({}, specificAxisStyle, generalAxisStyle) : specificAxisStyle || generalAxisStyle;
};
var otherAxis = this.getAxis(props) === "y" ? "x" : "y";
if (axisValue === undefined || !dependentAxis || scale[otherAxis] === undefined) {
return axisAngle || startAngle;
}
return Helpers.radiansToDegrees(scale.x(axisValue));
},
getTickProps: function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale,
style = calculatedValues.style,
stringTicks = calculatedValues.stringTicks;
var getRadius = function (props) {
var _Helpers$getPadding = Helpers.getPadding(props),
left = _Helpers$getPadding.left,
right = _Helpers$getPadding.right,
top = _Helpers$getPadding.top,
bottom = _Helpers$getPadding.bottom;
var originalTick = stringTicks ? stringTicks[index] : tick;
var width = props.width,
height = props.height;
var _getEvaluatedStyles = this.getEvaluatedStyles(style, originalTick, index),
tickStyle = _getEvaluatedStyles.tickStyle;
return Math.min(width - left - right, height - top - bottom) / 2;
};
var tickPadding = tickStyle.padding || 0;
var angularPadding = tickPadding; // TODO: do some geometry
var axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
return axisType === "angular" ? {
index: index, datum: tick, style: tickStyle,
x1: radius * Math.cos(scale(tick)),
y1: -radius * Math.sin(scale(tick)),
x2: (radius + tickPadding) * Math.cos(scale(tick)),
y2: -(radius + tickPadding) * Math.sin(scale(tick))
} : {
style: style, index: index, datum: tick,
x1: scale(tick) / 2 * Math.cos(axisAngle - angularPadding),
x2: scale(tick) / 2 * Math.cos(axisAngle + angularPadding),
y1: -(scale(tick) / 2) * Math.sin(axisAngle - angularPadding),
y2: -(scale(tick) / 2) * Math.sin(axisAngle + angularPadding)
};
},
getTickLabelProps: function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
tickFormat = calculatedValues.tickFormat,
style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
stringTicks = calculatedValues.stringTicks;
var getRange = function (props, axis) {
// Return the range from props if one is given.
if (props.range && props.range[axis]) {
return props.range[axis];
} else if (props.range && Array.isArray(props.range)) {
return props.range;
}
var axisType = getAxisType(props);
if (axisType === "angular") {
var startAngle = Helpers.degreesToRadians(props.startAngle);
var endAngle = Helpers.degreesToRadians(props.endAngle);
return [startAngle, endAngle];
}
var radius = getRadius(props);
return [props.innerRadius || 0, radius];
};
var originalTick = stringTicks ? stringTicks[index] : tick;
// exposed for use by VictoryChart (necessary?)
var getScale = function (props) {
var axis = getAxis(props);
var scale = Scale.getBaseScale(props, axis);
var domain = getDomain(props, axis) || scale.domain();
var range = getRange(props, axis);
scale.range(range);
scale.domain(domain);
return scale;
};
var _getEvaluatedStyles2 = this.getEvaluatedStyles(style, originalTick, index),
labelStyle = _getEvaluatedStyles2.labelStyle;
var getStyles = function (props, styleObject) {
var style = props.style || {};
styleObject = styleObject || {};
var parentStyleProps = { height: "auto", width: "100%" };
return {
parent: _defaults(parentStyleProps, style.parent, styleObject.parent),
axis: _defaults({}, style.axis, styleObject.axis),
axisLabel: _defaults({}, style.axisLabel, styleObject.axisLabel),
grid: _defaults({}, style.grid, styleObject.grid),
ticks: _defaults({}, style.ticks, styleObject.ticks),
tickLabels: _defaults({}, style.tickLabels, styleObject.tickLabels)
};
};
var tickLabelComponent = props.tickLabelComponent;
var getAxisAngle = function (props) {
var axisAngle = props.axisAngle,
startAngle = props.startAngle,
axisValue = props.axisValue,
dependentAxis = props.dependentAxis,
scale = props.scale;
var labelPlacement = tickLabelComponent.props && tickLabelComponent.props.labelPlacement ? tickLabelComponent.props.labelPlacement : props.labelPlacement;
var tickPadding = labelStyle.padding || 0;
var angularPadding = 0; // TODO: do some geometry
var axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
var labelAngle = axisType === "angular" ? Helpers.radiansToDegrees(scale(tick)) : axisAngle + angularPadding;
var textAngle = labelStyle.angle || LabelHelpers.getPolarAngle(_assign({}, props, { labelPlacement: labelPlacement }), labelAngle);
var labelRadius = axisType === "angular" ? radius + tickPadding : scale(tick);
var textAnchor = labelStyle.textAnchor || LabelHelpers.getPolarTextAnchor(_assign({}, props, { labelPlacement: labelPlacement }), labelAngle);
return {
index: index, datum: tick, style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
text: tickFormat(tick, index, ticks),
x: labelRadius * Math.cos(Helpers.degreesToRadians(labelAngle)),
y: -labelRadius * Math.sin(Helpers.degreesToRadians(labelAngle))
};
},
getGridProps: function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale,
stringTicks = calculatedValues.stringTicks;
var startAngle = props.startAngle,
endAngle = props.endAngle,
_props$innerRadius = props.innerRadius,
innerRadius = _props$innerRadius === undefined ? 0 : _props$innerRadius;
var otherAxis = getAxis(props) === "y" ? "x" : "y";
if (axisValue === undefined || !dependentAxis || scale[otherAxis] === undefined) {
return axisAngle || startAngle;
}
return Helpers.radiansToDegrees(scale.x(axisValue));
};
var originalTick = stringTicks ? stringTicks[index] : tick;
var getTickProps = function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale,
style = calculatedValues.style,
stringTicks = calculatedValues.stringTicks;
var _getEvaluatedStyles3 = this.getEvaluatedStyles(style, originalTick, index),
gridStyle = _getEvaluatedStyles3.gridStyle;
var originalTick = stringTicks ? stringTicks[index] : tick;
var angle = scale(tick);
return axisType === "angular" ? {
index: index, datum: tick, style: gridStyle,
x1: this.getPosition(radius, angle, "x"),
y1: this.getPosition(radius, angle, "y"),
x2: this.getPosition(innerRadius, angle, "x"),
y2: this.getPosition(innerRadius, angle, "y")
} : {
style: gridStyle, index: index, datum: tick,
cx: 0, cy: 0, r: scale(tick), startAngle: startAngle, endAngle: endAngle
};
},
getAxisLabelProps: function (props, calculatedValues) {
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale;
var axisLabelComponent = props.axisLabelComponent;
var _getEvaluatedStyles = getEvaluatedStyles(style, originalTick, index),
tickStyle = _getEvaluatedStyles.tickStyle;
if (axisType !== "radial") {
return {};
}
var labelPlacement = axisLabelComponent.props && axisLabelComponent.props.labelPlacement ? axisLabelComponent.props.labelPlacement : props.labelPlacement;
var labelStyle = style && style.axisLabel || {};
var axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
var textAngle = labelStyle.angle || LabelHelpers.getPolarAngle(_assign({}, props, { labelPlacement: labelPlacement }), axisAngle);
var labelRadius = radius + (labelStyle.padding || 0);
var textAnchor = labelStyle.textAnchor || LabelHelpers.getTextPolarAnchor(_assign({}, props, { labelPlacement: labelPlacement }), axisAngle);
var verticalAnchor = labelStyle.verticalAnchor || LabelHelpers.getPolarVerticalAnchor(_assign({}, props, { labelPlacement: labelPlacement }), axisAngle);
return {
style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
verticalAnchor: verticalAnchor,
text: props.label,
x: this.getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "x"),
y: this.getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "y")
};
},
getPosition: function (r, angle, axis) {
return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle);
},
getAxisProps: function (modifiedProps, calculatedValues) {
var style = calculatedValues.style,
axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale;
var startAngle = modifiedProps.startAngle,
endAngle = modifiedProps.endAngle,
_modifiedProps$innerR = modifiedProps.innerRadius,
innerRadius = _modifiedProps$innerR === undefined ? 0 : _modifiedProps$innerR;
var tickPadding = tickStyle.padding || 0;
var angularPadding = tickPadding; // TODO: do some geometry
var axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
return axisType === "angular" ? {
index: index, datum: tick, style: tickStyle,
x1: radius * Math.cos(scale(tick)),
y1: -radius * Math.sin(scale(tick)),
x2: (radius + tickPadding) * Math.cos(scale(tick)),
y2: -(radius + tickPadding) * Math.sin(scale(tick))
} : {
style: style, index: index, datum: tick,
x1: scale(tick) / 2 * Math.cos(axisAngle - angularPadding),
x2: scale(tick) / 2 * Math.cos(axisAngle + angularPadding),
y1: -(scale(tick) / 2) * Math.sin(axisAngle - angularPadding),
y2: -(scale(tick) / 2) * Math.sin(axisAngle + angularPadding)
};
};
var axisAngle = axisType === "radial" ? Helpers.degreesToRadians(this.getAxisAngle(modifiedProps, scale)) : undefined;
return axisType === "radial" ? {
style: style.axis,
x1: this.getPosition(innerRadius, axisAngle, "x"),
x2: this.getPosition(radius, axisAngle, "x"),
y1: this.getPosition(innerRadius, axisAngle, "y"),
y2: this.getPosition(radius, axisAngle, "y")
} : {
style: style.axis,
cx: 0, cy: 0, r: radius, startAngle: startAngle, endAngle: endAngle
};
},
getEvaluatedStyles: function (style, tick, index) {
return {
tickStyle: this.evaluateStyle(style.ticks, tick, index),
labelStyle: this.evaluateStyle(style.tickLabels, tick, index),
gridStyle: this.evaluateStyle(style.grid, tick, index)
};
},
getRole: function (props) {
if (props.dependentAxis) {
return props.theme && props.theme.dependentAxis ? "dependentAxis" : "axis";
}
//eslint-disable-next-line max-params
var getTickLabelProps = function (props, calculatedValues, tick, index) {
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
tickFormat = calculatedValues.tickFormat,
style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
stringTicks = calculatedValues.stringTicks;
return props.theme && props.theme.independentAxis ? "independentAxis" : "axis";
},
getShallowMergedThemeProps: function (props, role) {
var axisTheme = props.theme.axis || {};
return _defaults({}, props.theme[role], axisTheme);
},
modifyProps: function (props, fallbackProps, role) {
if (role !== "axis") {
props.theme[role] = this.getShallowMergedThemeProps(props, role);
}
return Helpers.modifyProps(props, fallbackProps, role);
},
getBaseProps: function (props, fallbackProps) {
var _this2 = this;
var originalTick = stringTicks ? stringTicks[index] : tick;
var role = this.getRole(props);
props = this.modifyProps(props, fallbackProps, role);
var calculatedValues = this.getCalculatedValues(props);
var style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
domain = calculatedValues.domain;
var _props = props,
width = _props.width,
height = _props.height,
standalone = _props.standalone,
theme = _props.theme;
var _getEvaluatedStyles2 = getEvaluatedStyles(style, originalTick, index),
labelStyle = _getEvaluatedStyles2.labelStyle;
var axisProps = this.getAxisProps(props, calculatedValues);
var axisLabelProps = this.getAxisLabelProps(props, calculatedValues);
var initialChildProps = { parent: { style: style.parent, ticks: ticks, scale: scale, width: width, height: height, domain: domain, standalone: standalone, theme: theme }
var tickLabelComponent = props.tickLabelComponent;
var labelPlacement = tickLabelComponent.props && tickLabelComponent.props.labelPlacement ? tickLabelComponent.props.labelPlacement : props.labelPlacement;
var tickPadding = labelStyle.padding || 0;
var angularPadding = 0; // TODO: do some geometry
var axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
var labelAngle = axisType === "angular" ? Helpers.radiansToDegrees(scale(tick)) : axisAngle + angularPadding;
var textAngle = labelStyle.angle || LabelHelpers.getPolarAngle(_assign({}, props, { labelPlacement: labelPlacement }), labelAngle);
var labelRadius = axisType === "angular" ? radius + tickPadding : scale(tick);
var textAnchor = labelStyle.textAnchor || LabelHelpers.getPolarTextAnchor(_assign({}, props, { labelPlacement: labelPlacement }), labelAngle);
return {
index: index, datum: tick, style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
text: tickFormat(tick, index, ticks),
x: labelRadius * Math.cos(Helpers.degreesToRadians(labelAngle)),
y: -labelRadius * Math.sin(Helpers.degreesToRadians(labelAngle))
};
};
var getGridProps = function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale,
stringTicks = calculatedValues.stringTicks;
var startAngle = props.startAngle,
endAngle = props.endAngle,
_props$innerRadius = props.innerRadius,
innerRadius = _props$innerRadius === undefined ? 0 : _props$innerRadius;
var originalTick = stringTicks ? stringTicks[index] : tick;
var _getEvaluatedStyles3 = getEvaluatedStyles(style, originalTick, index),
gridStyle = _getEvaluatedStyles3.gridStyle;
var angle = scale(tick);
return axisType === "angular" ? {
index: index, datum: tick, style: gridStyle,
x1: getPosition(radius, angle, "x"),
y1: getPosition(radius, angle, "y"),
x2: getPosition(innerRadius, angle, "x"),
y2: getPosition(innerRadius, angle, "y")
} : {
style: gridStyle, index: index, datum: tick,
cx: 0, cy: 0, r: scale(tick), startAngle: startAngle, endAngle: endAngle
};
};
var getAxisLabelProps = function (props, calculatedValues) {
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale;
var axisLabelComponent = props.axisLabelComponent;
if (axisType !== "radial") {
return {};
}
var labelPlacement = axisLabelComponent.props && axisLabelComponent.props.labelPlacement ? axisLabelComponent.props.labelPlacement : props.labelPlacement;
var labelStyle = style && style.axisLabel || {};
var axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
var textAngle = labelStyle.angle || LabelHelpers.getPolarAngle(_assign({}, props, { labelPlacement: labelPlacement }), axisAngle);
var labelRadius = radius + (labelStyle.padding || 0);
var textAnchor = labelStyle.textAnchor || LabelHelpers.getTextPolarAnchor(_assign({}, props, { labelPlacement: labelPlacement }), axisAngle);
var verticalAnchor = labelStyle.verticalAnchor || LabelHelpers.getPolarVerticalAnchor(_assign({}, props, { labelPlacement: labelPlacement }), axisAngle);
return {
style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
verticalAnchor: verticalAnchor,
text: props.label,
x: getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "x"),
y: getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "y")
};
};
var getAxisProps = function (modifiedProps, calculatedValues) {
var style = calculatedValues.style,
axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale;
var startAngle = modifiedProps.startAngle,
endAngle = modifiedProps.endAngle,
_modifiedProps$innerR = modifiedProps.innerRadius,
innerRadius = _modifiedProps$innerR === undefined ? 0 : _modifiedProps$innerR;
var axisAngle = axisType === "radial" ? Helpers.degreesToRadians(getAxisAngle(modifiedProps, scale)) : undefined;
return axisType === "radial" ? {
style: style.axis,
x1: getPosition(innerRadius, axisAngle, "x"),
x2: getPosition(radius, axisAngle, "x"),
y1: getPosition(innerRadius, axisAngle, "y"),
y2: getPosition(radius, axisAngle, "y")
} : {
style: style.axis,
cx: 0, cy: 0, r: radius, startAngle: startAngle, endAngle: endAngle
};
};
var getRole = function (props) {
if (props.dependentAxis) {
return props.theme && props.theme.dependentAxis ? "dependentAxis" : "axis";
}
return props.theme && props.theme.independentAxis ? "independentAxis" : "axis";
};
var getShallowMergedThemeProps = function (props, role) {
var axisTheme = props.theme.axis || {};
return _defaults({}, props.theme[role], axisTheme);
};
var modifyProps = function (props, fallbackProps, role) {
if (role !== "axis") {
props.theme[role] = getShallowMergedThemeProps(props, role);
}
return Helpers.modifyProps(props, fallbackProps, role);
};
var getCalculatedValues = function (props) {
var defaultStyles = getStyleObject(props);
var style = getStyles(props, defaultStyles);
var padding = Helpers.getPadding(props);
var axis = getAxis(props);
var axisType = getAxisType(props);
var stringTicks = Helpers.stringTicks(props) ? props.tickValues : undefined;
var domain = getDomain(props, axis);
var range = getRange(props, axis);
var scale = getScale(props);
var initialTicks = Axis.getTicks(props, scale);
var ticks = axisType === "angular" ? filterTicks(initialTicks, scale) : initialTicks;
var tickFormat = Axis.getTickFormat(props, scale);
var radius = getRadius(props);
return {
axis: axis, style: style, padding: padding, stringTicks: stringTicks, axisType: axisType, scale: scale, ticks: ticks, tickFormat: tickFormat, domain: domain, range: range, radius: radius
};
};
var getBaseProps = function (props, fallbackProps) {
var role = getRole(props);
props = modifyProps(props, fallbackProps, role);
var calculatedValues = getCalculatedValues(props);
var style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
domain = calculatedValues.domain;
var _props = props,
width = _props.width,
height = _props.height,
standalone = _props.standalone,
theme = _props.theme;
var axisProps = getAxisProps(props, calculatedValues);
var axisLabelProps = getAxisLabelProps(props, calculatedValues);
var initialChildProps = { parent: { style: style.parent, ticks: ticks, scale: scale, width: width, height: height, domain: domain, standalone: standalone, theme: theme }
};
return ticks.reduce(function (childProps, tick, index) {
childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
ticks: getTickProps(props, calculatedValues, tick, index),
tickLabels: getTickLabelProps(props, calculatedValues, tick, index),
grid: getGridProps(props, calculatedValues, tick, index)
};
return ticks.reduce(function (childProps, tick, index) {
childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
ticks: _this2.getTickProps(props, calculatedValues, tick, index),
tickLabels: _this2.getTickLabelProps(props, calculatedValues, tick, index),
grid: _this2.getGridProps(props, calculatedValues, tick, index)
};
return childProps;
}, initialChildProps);
};
return childProps;
}, initialChildProps);
},
filterTicks: function (ticks, scale) {
var compareTicks = function (t) {
return scale(t) % (2 * Math.PI);
};
return _uniqBy(ticks, compareTicks);
}
};
export { getDomain, getAxis, getScale, getStyles, getBaseProps };

@@ -20,3 +20,3 @@ import _partialRight from "lodash/partialRight";

import { PropTypes as CustomPropTypes, Helpers, VictoryLabel, VictoryContainer, VictoryTheme, Grid, addEvents, Arc } from "victory-core";
import AxisHelpers from "./helper-methods";
import { getDomain, getAxis, getScale, getStyles, getBaseProps } from "./helper-methods";
import { BaseProps } from "../../helpers/common-props";

@@ -189,7 +189,7 @@

};
VictoryPolarAxis.getDomain = AxisHelpers.getDomain.bind(AxisHelpers);
VictoryPolarAxis.getAxis = AxisHelpers.getAxis.bind(AxisHelpers);
VictoryPolarAxis.getScale = AxisHelpers.getScale.bind(AxisHelpers);
VictoryPolarAxis.getStyles = _partialRight(AxisHelpers.getStyles.bind(AxisHelpers), fallbackProps.style);
VictoryPolarAxis.getBaseProps = _partialRight(AxisHelpers.getBaseProps.bind(AxisHelpers), fallbackProps);
VictoryPolarAxis.getDomain = getDomain;
VictoryPolarAxis.getAxis = getAxis;
VictoryPolarAxis.getScale = getScale;
VictoryPolarAxis.getStyles = _partialRight(getStyles, fallbackProps.style);
VictoryPolarAxis.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryPolarAxis.expectedComponents = ["axisComponent", "circularAxisComponent", "groupComponent", "containerComponent", "tickComponent", "tickLabelComponent", "gridComponent", "circularGridComponent"];

@@ -196,0 +196,0 @@

@@ -13,97 +13,98 @@ import _isNaN from "lodash/isNaN";

export default {
getBaseProps: function (props, fallbackProps) {
var _this = this;
var getVoronoi = function (props, range, scale) {
var minRange = [Math.min.apply(Math, _toConsumableArray(range.x)), Math.min.apply(Math, _toConsumableArray(range.y))];
var maxRange = [Math.max.apply(Math, _toConsumableArray(range.x)), Math.max.apply(Math, _toConsumableArray(range.y))];
var angleAccessor = function (d) {
var x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
return -1 * x + Math.PI / 2;
};
var xAccessor = function (d) {
return scale.x(d._x1 !== undefined ? d._x1 : d._x);
};
return d3Voronoi().x(function (d) {
return props.polar ? angleAccessor(d) : xAccessor(d);
}).y(function (d) {
return scale.y(d._y1 !== undefined ? d._y1 : d._y);
}).extent([minRange, maxRange]);
};
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "scatter");
props = _assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
polygons = _props.polygons,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getDataStyles = function (datum, style) {
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "y", "_x", "_y", "eventKey", "label"];
var stylesFromData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return _defaults({}, stylesFromData, style);
};
var initialChildProps = { parent: {
style: style.parent, scale: scale, domain: domain, data: data, standalone: standalone, height: height, width: width, theme: theme,
origin: origin, polar: polar, padding: padding
} };
var getCalculatedValues = function (props) {
var defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ? props.theme.voronoi.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
var data = Data.getData(props);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
var domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var voronoi = getVoronoi(props, range, scale);
var polygons = voronoi.polygons(data);
var origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, polygons: polygons, origin: origin };
};
return data.reduce(function (childProps, datum, index) {
var polygon = _without(polygons[index], "data");
var eventKey = datum.eventKey;
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = Helpers.modifyProps(props, fallbackProps, "scatter");
props = _assign({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
polygons = _props.polygons,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var _Helpers$scalePoint = Helpers.scalePoint(props, datum),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
var initialChildProps = { parent: {
style: style.parent, scale: scale, domain: domain, data: data, standalone: standalone, height: height, width: width, theme: theme,
origin: origin, polar: polar, padding: padding
} };
var dataProps = {
x: x, y: y, datum: datum, data: data, index: index, scale: scale, polygon: polygon, origin: origin,
size: props.size,
style: _this.getDataStyles(datum, style.data)
};
return data.reduce(function (childProps, datum, index) {
var polygon = _without(polygons[index], "data");
var eventKey = datum.eventKey;
childProps[eventKey] = { data: dataProps };
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
var _Helpers$scalePoint = Helpers.scalePoint(props, datum),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
return childProps;
}, initialChildProps);
},
getCalculatedValues: function (props) {
var defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ? props.theme.voronoi.style : {};
var style = Helpers.getStyles(props.style, defaultStyles);
var data = Data.getData(props);
var range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
var dataProps = {
x: x, y: y, datum: datum, data: data, index: index, scale: scale, polygon: polygon, origin: origin,
size: props.size,
style: getDataStyles(datum, style.data)
};
var domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var voronoi = this.getVoronoi(props, range, scale);
var polygons = voronoi.polygons(data);
var origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, polygons: polygons, origin: origin };
},
getVoronoi: function (props, range, scale) {
var minRange = [Math.min.apply(Math, _toConsumableArray(range.x)), Math.min.apply(Math, _toConsumableArray(range.y))];
var maxRange = [Math.max.apply(Math, _toConsumableArray(range.x)), Math.max.apply(Math, _toConsumableArray(range.y))];
var angleAccessor = function (d) {
var x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
return -1 * x + Math.PI / 2;
};
var xAccessor = function (d) {
return scale.x(d._x1 !== undefined ? d._x1 : d._x);
};
return d3Voronoi().x(function (d) {
return props.polar ? angleAccessor(d) : xAccessor(d);
}).y(function (d) {
return scale.y(d._y1 !== undefined ? d._y1 : d._y);
}).extent([minRange, maxRange]);
},
getDataStyles: function (datum, style) {
var numKeys = _keys(datum).filter(function (k) {
return _isNaN(k);
});
var omitKeys = ["x", "y", "_x", "_y", "eventKey", "label"];
var stylesFromData = _omit(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return _defaults({}, stylesFromData, style);
}
};
childProps[eventKey] = { data: dataProps };
var text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
};
export { getBaseProps };

@@ -16,3 +16,3 @@ import _partialRight from "lodash/partialRight";

import { PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents, VictoryContainer, VictoryTheme, DefaultTransitions, Voronoi, Data, Domain } from "victory-core";
import VoronoiHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import { BaseProps, DataProps } from "../../helpers/common-props";

@@ -81,3 +81,3 @@

VictoryVoronoi.getData = Data.getData.bind(Data);
VictoryVoronoi.getBaseProps = _partialRight(VoronoiHelpers.getBaseProps.bind(VoronoiHelpers), fallbackProps);
VictoryVoronoi.getBaseProps = _partialRight(getBaseProps, fallbackProps);
VictoryVoronoi.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];

@@ -84,0 +84,0 @@

@@ -229,19 +229,27 @@ import _sortBy from "lodash/sortBy";

var xArr = _sortBy(xKeys);
return datasets.map(function (dataset) {
var indexOffset = 0;
var isDate = dataset[0] && dataset[0]._x instanceof Date;
var filledInData = xArr.map(function (x, index) {
x = +x;
var datum = dataset[index - indexOffset];
var isDate = datum._x instanceof Date;
var x1 = isDate ? datum._x.getTime() : datum._x;
x = +x;
if (x1 === x) {
return datum;
if (datum) {
var x1 = isDate ? datum._x.getTime() : datum._x;
if (x1 === x) {
return datum;
} else {
indexOffset++;
var y = fillInMissingData ? 0 : null;
x = isDate ? new Date(x) : x;
return { x: x, y: y, _x: x, _y: y };
}
} else {
indexOffset++;
var y = fillInMissingData ? 0 : null;
var _y = fillInMissingData ? 0 : null;
x = isDate ? new Date(x) : x;
return { x: x, y: y, _x: x, _y: y };
return { x: x, y: _y, _x: x, _y: _y };
}
});
return filledInData;

@@ -248,0 +256,0 @@ });

@@ -7,2 +7,3 @@ export { default as VictoryChart } from "./components/victory-chart/victory-chart";

export { default as VictoryBar } from "./components/victory-bar/victory-bar";
export { default as VictoryBoxPlot } from "./components/victory-boxplot/victory-boxplot";
export { default as VictoryScatter } from "./components/victory-scatter/victory-scatter";

@@ -9,0 +10,0 @@ export { default as VictoryGroup } from "./components/victory-group/victory-group";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDataWithBaseline = exports.getBaseProps = undefined;

@@ -15,79 +16,82 @@ var _assign2 = require("lodash/assign");

exports.default = {
getBaseProps: function (props, fallbackProps) {
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "area");
props = (0, _assign3.default)({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getDataWithBaseline = function (props, scale) {
var data = _victoryCore.Data.getData(props);
var initialChildProps = {
parent: {
style: style.parent, width: width, height: height, scale: scale, data: data, domain: domain,
standalone: standalone, theme: theme, polar: polar, origin: origin, padding: padding
},
all: {
data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, style: style.data }
}
};
return data.reduce(function (childProps, datum, index) {
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: _victoryCore.LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
},
getCalculatedValues: function (props) {
var theme = props.theme,
polar = props.polar;
if (data.length < 2) {
data = [];
}
var defaultMin = _victoryCore.Scale.getType(scale.y) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
var domainY = scale.y.domain();
var minY = Math.min.apply(Math, _toConsumableArray(domainY)) > 0 ? Math.min.apply(Math, _toConsumableArray(domainY)) : defaultMin;
var defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomainWithZero(props, "x"),
y: _victoryCore.Domain.getDomainWithZero(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
var data = this.getDataWithBaseline(props, scale);
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
},
getDataWithBaseline: function (props, scale) {
var data = _victoryCore.Data.getData(props);
return data.map(function (datum) {
var _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
var _y0 = datum._y0 !== undefined ? datum._y0 : minY;
return (0, _assign3.default)({}, datum, { _y0: _y0, _y1: _y1 });
});
};
if (data.length < 2) {
data = [];
var getCalculatedValues = function (props) {
var theme = props.theme,
polar = props.polar;
var defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomainWithZero(props, "x"),
y: _victoryCore.Domain.getDomainWithZero(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
var data = getDataWithBaseline(props, scale);
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
};
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "area");
props = (0, _assign3.default)({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var initialChildProps = {
parent: {
style: style.parent, width: width, height: height, scale: scale, data: data, domain: domain,
standalone: standalone, theme: theme, polar: polar, origin: origin, padding: padding
},
all: {
data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, style: style.data }
}
var defaultMin = _victoryCore.Scale.getType(scale.y) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
var domainY = scale.y.domain();
var minY = Math.min.apply(Math, _toConsumableArray(domainY)) > 0 ? Math.min.apply(Math, _toConsumableArray(domainY)) : defaultMin;
};
return data.reduce(function (childProps, datum, index) {
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: _victoryCore.LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
};
return data.map(function (datum) {
var _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
var _y0 = datum._y0 !== undefined ? datum._y0 : minY;
return (0, _assign3.default)({}, datum, { _y0: _y0, _y1: _y1 });
});
}
};
exports.getBaseProps = getBaseProps;
exports.getDataWithBaseline = getDataWithBaseline;

@@ -23,4 +23,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _victoryCore = require("victory-core");

@@ -109,4 +107,4 @@

VictoryArea.getData = _victoryCore.Data.getData.bind(_victoryCore.Data);
VictoryArea.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryArea.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryArea.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryArea, options);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBaseProps = undefined;

@@ -31,100 +32,101 @@ var _isNaN2 = require("lodash/isNaN");

exports.default = {
getBarPosition: function (props, datum) {
var getDefaultMin = function (axis) {
var defaultMin = _victoryCore.Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
return datum["_" + axis] instanceof Date ? new Date(defaultMin) : defaultMin;
};
var _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
var _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
return _victoryCore.Helpers.scalePoint(props, (0, _assign3.default)({}, datum, { _y0: _y0, _x0: _x0 }));
},
getBarStyle: function (datum, baseStyle) {
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "y", "y0", "_x", "_y", "_y0", "name", "label", "eventKey"];
var styleData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return (0, _defaults3.default)({}, styleData, baseStyle);
},
getCalculatedValues: function (props) {
var theme = props.theme,
horizontal = props.horizontal,
polar = props.polar;
var getBarPosition = function (props, datum) {
var getDefaultMin = function (axis) {
var defaultMin = _victoryCore.Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
return datum["_" + axis] instanceof Date ? new Date(defaultMin) : defaultMin;
};
var _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
var _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
return _victoryCore.Helpers.scalePoint(props, (0, _assign3.default)({}, datum, { _y0: _y0, _x0: _x0 }));
};
var defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
var data = _victoryCore.Data.getData(props);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomainWithZero(props, "x"),
y: _victoryCore.Domain.getDomainWithZero(props, "y")
};
var xScale = _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
var yScale = _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
var scale = {
x: horizontal ? yScale : xScale,
y: horizontal ? xScale : yScale
};
var origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
},
getBaseProps: function (props, fallbackProps) {
var _this = this;
var getBarStyle = function (datum, baseStyle) {
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "y", "y0", "_x", "_y", "_y0", "name", "label", "eventKey"];
var styleData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return (0, _defaults3.default)({}, styleData, baseStyle);
};
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "bar");
props = (0, _assign3.default)({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
alignment = _props.alignment,
barRatio = _props.barRatio,
cornerRadius = _props.cornerRadius,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
horizontal = _props.horizontal,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getCalculatedValues = function (props) {
var theme = props.theme,
horizontal = props.horizontal,
polar = props.polar;
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone,
theme: theme, polar: polar, origin: origin, padding: padding, style: style.parent
} };
var defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
var data = _victoryCore.Data.getData(props);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomainWithZero(props, "x"),
y: _victoryCore.Domain.getDomainWithZero(props, "y")
};
var xScale = _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
var yScale = _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
var scale = {
x: horizontal ? yScale : xScale,
y: horizontal ? xScale : yScale
};
var origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { style: style, data: data, scale: scale, domain: domain, origin: origin };
};
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "bar");
props = (0, _assign3.default)({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
alignment = _props.alignment,
barRatio = _props.barRatio,
cornerRadius = _props.cornerRadius,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
horizontal = _props.horizontal,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var _getBarPosition = _this.getBarPosition(props, datum),
x = _getBarPosition.x,
y = _getBarPosition.y,
y0 = _getBarPosition.y0,
x0 = _getBarPosition.x0;
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone,
theme: theme, polar: polar, origin: origin, padding: padding, style: style.parent
} };
var barStyle = _this.getBarStyle(datum, style.data);
var dataProps = {
alignment: alignment, barRatio: barRatio, cornerRadius: cornerRadius, data: data, datum: datum, horizontal: horizontal, index: index, padding: padding, polar: polar, origin: origin,
scale: scale, style: barStyle, width: width, height: height, x: x, y: y, y0: y0, x0: x0
};
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = {
data: dataProps
};
var _getBarPosition = getBarPosition(props, datum),
x = _getBarPosition.x,
y = _getBarPosition.y,
y0 = _getBarPosition.y0,
x0 = _getBarPosition.x0;
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
}
};
var barStyle = getBarStyle(datum, style.data);
var dataProps = {
alignment: alignment, barRatio: barRatio, cornerRadius: cornerRadius, data: data, datum: datum, horizontal: horizontal, index: index, padding: padding, polar: polar, origin: origin,
scale: scale, style: barStyle, width: width, height: height, x: x, y: y, y0: y0, x0: x0
};
childProps[eventKey] = {
data: dataProps
};
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
};
exports.getBaseProps = getBaseProps;

@@ -23,4 +23,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _victoryCore = require("victory-core");

@@ -130,4 +128,4 @@

VictoryBar.getData = _victoryCore.Data.getData.bind(_victoryCore.Data);
VictoryBar.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryBar.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryBar.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryBar);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getData = exports.getDomain = exports.getBaseProps = undefined;

@@ -35,193 +36,200 @@ var _isNaN2 = require("lodash/isNaN");

exports.default = {
getBaseProps: function (props, fallbackProps) {
var _this = this;
var sortData = function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
// eslint-disable-line max-statements
props = _victoryCore.Helpers.modifyProps(props, fallbackProps, "candlestick");
var calculatedValues = this.getCalculatedValues(props);
var data = calculatedValues.data,
style = calculatedValues.style,
scale = calculatedValues.scale,
domain = calculatedValues.domain,
origin = calculatedValues.origin;
var _props = props,
groupComponent = _props.groupComponent,
width = _props.width,
height = _props.height,
padding = _props.padding,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
wickStrokeWidth = _props.wickStrokeWidth;
if (!sortKey) {
return dataset;
}
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone, theme: theme, polar: polar, origin: origin,
style: style.parent, padding: padding
} };
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
}
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var high = scale.y(datum._high);
var close = scale.y(datum._close);
var open = scale.y(datum._open);
var low = scale.y(datum._low);
var candleHeight = Math.abs(scale.y(datum._open) - scale.y(datum._close));
var dataStyle = _this.getDataStyles(datum, style.data, props);
var dataProps = {
x: x, high: high, low: low, candleHeight: candleHeight, scale: scale, data: data, datum: datum, groupComponent: groupComponent, index: index,
style: dataStyle, padding: padding, width: width, polar: polar, origin: origin, wickStrokeWidth: wickStrokeWidth, open: open, close: close
};
var sortedData = (0, _sortBy3.default)(dataset, sortKey);
childProps[eventKey] = {
data: dataProps
};
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = _this.getLabelProps(dataProps, text, style);
}
if (sortOrder === "descending") {
return sortedData.reverse();
}
return childProps;
}, initialChildProps);
},
getLabelProps: function (dataProps, text, style) {
var x = dataProps.x,
high = dataProps.high,
index = dataProps.index,
scale = dataProps.scale,
datum = dataProps.datum,
data = dataProps.data;
return sortedData;
};
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: high - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: datum,
data: data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
},
getCalculatedValues: function (props) {
var theme = props.theme,
polar = props.polar;
var getData = function (props) {
if (!props.data || _victoryCore.Data.getLength(props.data) < 1) {
return [];
}
var stringMap = {
x: _victoryCore.Data.createStringMap(props, "x")
};
var defaultStyle = theme && theme.candlestick && theme.candlestick.style ? theme.candlestick.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyle);
var data = _victoryCore.Data.addEventKeys(props, this.getData(props));
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: this.getDomain(props, "x"),
y: this.getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
},
getData: function (props) {
if (!props.data || _victoryCore.Data.getLength(props.data) < 1) {
return [];
}
var stringMap = {
x: _victoryCore.Data.createStringMap(props, "x")
};
var accessor = {
x: _victoryCore.Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
open: _victoryCore.Helpers.createAccessor(props.open !== undefined ? props.open : "open"),
close: _victoryCore.Helpers.createAccessor(props.close !== undefined ? props.close : "close"),
high: _victoryCore.Helpers.createAccessor(props.high !== undefined ? props.high : "high"),
low: _victoryCore.Helpers.createAccessor(props.low !== undefined ? props.low : "low")
};
var accessor = {
x: _victoryCore.Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
open: _victoryCore.Helpers.createAccessor(props.open !== undefined ? props.open : "open"),
close: _victoryCore.Helpers.createAccessor(props.close !== undefined ? props.close : "close"),
high: _victoryCore.Helpers.createAccessor(props.high !== undefined ? props.high : "high"),
low: _victoryCore.Helpers.createAccessor(props.low !== undefined ? props.low : "low")
};
var formattedData = props.data.reduce(function (dataArr, datum, index) {
datum = _victoryCore.Data.parseDatum(datum);
var formattedData = props.data.reduce(function (dataArr, datum, index) {
datum = _victoryCore.Data.parseDatum(datum);
var evaluatedX = accessor.x(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _open = accessor.open(datum);
var _close = accessor.close(datum);
var _high = accessor.high(datum);
var _low = accessor.low(datum);
var _y = [_open, _close, _high, _low];
var evaluatedX = accessor.x(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _open = accessor.open(datum);
var _close = accessor.close(datum);
var _high = accessor.high(datum);
var _low = accessor.low(datum);
var _y = [_open, _close, _high, _low];
dataArr.push((0, _assign3.default)({}, datum, { _x: _x, _y: _y, _open: _open, _close: _close, _high: _high, _low: _low }, typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}));
dataArr.push((0, _assign3.default)({}, datum, { _x: _x, _y: _y, _open: _open, _close: _close, _high: _high, _low: _low }, typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}));
return dataArr;
}, []);
return dataArr;
return sortData(formattedData, props.sortKey, props.sortOrder);
};
var getDomain = function (props, axis) {
var domain = void 0;
if (props.domain && props.domain[axis]) {
domain = props.domain[axis];
} else if (props.domain && Array.isArray(props.domain)) {
domain = props.domain;
} else {
var dataset = getData(props);
var allData = dataset.reduce(function (memo, datum) {
return Array.isArray(datum["_" + axis]) ? memo.concat.apply(memo, _toConsumableArray(datum["_" + axis])) : memo.concat(datum["_" + axis]);
}, []);
return this.sortData(formattedData, props.sortKey, props.sortOrder);
},
sortData: function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
if (!sortKey) {
return dataset;
if (allData.length < 1) {
return _victoryCore.Scale.getBaseScale(props, axis).domain();
}
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
if (+min === +max) {
return _victoryCore.Domain.getSinglePointDomain(max);
}
domain = [min, max];
}
return _victoryCore.Domain.cleanDomain(_victoryCore.Domain.padDomain(domain, props, axis), props);
};
var sortedData = (0, _sortBy3.default)(dataset, sortKey);
var getCalculatedValues = function (props) {
var theme = props.theme,
polar = props.polar;
if (sortOrder === "descending") {
return sortedData.reverse();
}
var defaultStyle = theme && theme.candlestick && theme.candlestick.style ? theme.candlestick.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyle);
var data = _victoryCore.Data.addEventKeys(props, getData(props));
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: getDomain(props, "x"),
y: getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
};
return sortedData;
},
getDomain: function (props, axis) {
var domain = void 0;
if (props.domain && props.domain[axis]) {
domain = props.domain[axis];
} else if (props.domain && Array.isArray(props.domain)) {
domain = props.domain;
} else {
var dataset = this.getData(props);
var allData = dataset.reduce(function (memo, datum) {
return Array.isArray(datum["_" + axis]) ? memo.concat.apply(memo, _toConsumableArray(datum["_" + axis])) : memo.concat(datum["_" + axis]);
}, []);
var isTransparent = function (attr) {
return attr === "none" || attr === "transparent";
};
if (allData.length < 1) {
return _victoryCore.Scale.getBaseScale(props, axis).domain();
}
var getDataStyles = function (datum, style, props) {
style = style || {};
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "_x", "_y", "_y0", "size", "name", "label", "open", "close", "high", "low", "eventKey"];
var stylesFromData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
var candleColor = datum.open > datum.close ? props.candleColors.negative : props.candleColors.positive;
var fill = datum.fill || style.fill || candleColor;
var strokeColor = datum.stroke || style.stroke;
var stroke = isTransparent(strokeColor) ? fill : strokeColor || "black";
return (0, _defaults3.default)({}, stylesFromData, { stroke: stroke, fill: fill }, style);
};
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
if (+min === +max) {
return _victoryCore.Domain.getSinglePointDomain(max);
}
domain = [min, max];
var getLabelProps = function (dataProps, text, style) {
var x = dataProps.x,
high = dataProps.high,
index = dataProps.index,
scale = dataProps.scale,
datum = dataProps.datum,
data = dataProps.data;
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: high - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: datum,
data: data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
};
var getBaseProps = function (props, fallbackProps) {
// eslint-disable-line max-statements
props = _victoryCore.Helpers.modifyProps(props, fallbackProps, "candlestick");
var calculatedValues = getCalculatedValues(props);
var data = calculatedValues.data,
style = calculatedValues.style,
scale = calculatedValues.scale,
domain = calculatedValues.domain,
origin = calculatedValues.origin;
var _props = props,
groupComponent = _props.groupComponent,
width = _props.width,
height = _props.height,
padding = _props.padding,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
wickStrokeWidth = _props.wickStrokeWidth;
var initialChildProps = { parent: {
domain: domain, scale: scale, width: width, height: height, data: data, standalone: standalone, theme: theme, polar: polar, origin: origin,
style: style.parent, padding: padding
} };
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var high = scale.y(datum._high);
var close = scale.y(datum._close);
var open = scale.y(datum._open);
var low = scale.y(datum._low);
var candleHeight = Math.abs(scale.y(datum._open) - scale.y(datum._close));
var dataStyle = getDataStyles(datum, style.data, props);
var dataProps = {
x: x, high: high, low: low, candleHeight: candleHeight, scale: scale, data: data, datum: datum, groupComponent: groupComponent, index: index,
style: dataStyle, padding: padding, width: width, polar: polar, origin: origin, wickStrokeWidth: wickStrokeWidth, open: open, close: close
};
childProps[eventKey] = {
data: dataProps
};
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}
return _victoryCore.Domain.cleanDomain(_victoryCore.Domain.padDomain(domain, props, axis), props);
},
isTransparent: function (attr) {
return attr === "none" || attr === "transparent";
},
getDataStyles: function (datum, style, props) {
style = style || {};
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "_x", "_y", "_y0", "size", "name", "label", "open", "close", "high", "low", "eventKey"];
var stylesFromData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
var candleColor = datum.open > datum.close ? props.candleColors.negative : props.candleColors.positive;
var fill = datum.fill || style.fill || candleColor;
var strokeColor = datum.stroke || style.stroke;
var stroke = this.isTransparent(strokeColor) ? fill : strokeColor || "black";
return (0, _defaults3.default)({}, stylesFromData, { stroke: stroke, fill: fill }, style);
}
};
return childProps;
}, initialChildProps);
};
exports.getBaseProps = getBaseProps;
exports.getDomain = getDomain;
exports.getData = getData;

@@ -25,4 +25,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _commonProps = require("../../helpers/common-props");

@@ -111,6 +109,6 @@

};
VictoryCandlestick.getDomain = _helperMethods2.default.getDomain.bind(_helperMethods2.default);
VictoryCandlestick.getData = _helperMethods2.default.getData.bind(_helperMethods2.default);
VictoryCandlestick.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryCandlestick.getDomain = _helperMethods.getDomain;
VictoryCandlestick.getData = _helperMethods.getData;
VictoryCandlestick.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryCandlestick.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryCandlestick);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createStringMap = exports.getDefaultDomainPadding = exports.getChildComponents = exports.getDataComponents = exports.getAxisOffset = exports.getDomain = undefined;

@@ -23,110 +24,118 @@ var _axis = require("../../helpers/axis");

exports.default = {
getChildComponents: function (props, defaultAxes) {
var childComponents = _react2.default.Children.toArray(props.children);
if (childComponents.length === 0) {
return [defaultAxes.independent, defaultAxes.dependent];
}
var getDataComponents = function (childComponents) {
var findDataComponents = function (children) {
return children.reduce(function (memo, child) {
if (child.type && child.type.role === "axis") {
return memo;
} else if (child.props && child.props.children) {
return memo.concat(findDataComponents(_react2.default.Children.toArray(child.props.children)));
}
return memo.concat(child);
}, []);
};
var axisComponents = {
dependent: _axis2.default.getAxisComponentsWithParent(childComponents, "dependent"),
independent: _axis2.default.getAxisComponentsWithParent(childComponents, "independent")
};
return findDataComponents(childComponents);
};
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
if (axisComponents.independent.length > 1) {
var msg = "Only one independent VictoryAxis component is allowed when " + "using the VictoryChart wrapper. Only the first axis will be used. Please compose " + "multi-axis charts manually";
_victoryCore.Log.warn(msg);
var dataComponents = this.getDataComponents(childComponents);
return _victoryCore.Collection.removeUndefined(dataComponents.concat([].concat(_toConsumableArray(axisComponents.dependent), [axisComponents.independent[0]])));
}
return childComponents;
},
getDefaultDomainPadding: function (childComponents, horizontal) {
var groupComponent = childComponents.filter(function (child) {
return child.type && child.type.role && child.type.role === "group-wrapper";
});
var getChildComponents = function (props, defaultAxes) {
var childComponents = _react2.default.Children.toArray(props.children);
if (childComponents.length === 0) {
return [defaultAxes.independent, defaultAxes.dependent];
}
if (groupComponent.length < 1) {
return undefined;
}
var axisComponents = {
dependent: _axis2.default.getAxisComponentsWithParent(childComponents, "dependent"),
independent: _axis2.default.getAxisComponentsWithParent(childComponents, "independent")
};
var _groupComponent$0$pro = groupComponent[0].props,
offset = _groupComponent$0$pro.offset,
children = _groupComponent$0$pro.children;
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
if (axisComponents.independent.length > 1) {
var msg = "Only one independent VictoryAxis component is allowed when " + "using the VictoryChart wrapper. Only the first axis will be used. Please compose " + "multi-axis charts manually";
_victoryCore.Log.warn(msg);
var dataComponents = getDataComponents(childComponents);
return _victoryCore.Collection.removeUndefined(dataComponents.concat([].concat(_toConsumableArray(axisComponents.dependent), [axisComponents.independent[0]])));
}
return childComponents;
};
return horizontal ? { y: offset * children.length / 2 } : { x: offset * children.length / 2 };
},
getDataComponents: function (childComponents) {
var findDataComponents = function (children) {
return children.reduce(function (memo, child) {
if (child.type && child.type.role === "axis") {
return memo;
} else if (child.props && child.props.children) {
return memo.concat(findDataComponents(_react2.default.Children.toArray(child.props.children)));
}
return memo.concat(child);
}, []);
};
var getDefaultDomainPadding = function (childComponents, horizontal) {
var groupComponent = childComponents.filter(function (child) {
return child.type && child.type.role && child.type.role === "group-wrapper";
});
return findDataComponents(childComponents);
},
getDomain: function (props, axis, childComponents) {
childComponents = childComponents || _react2.default.Children.toArray(props.children);
var domain = _wrapper2.default.getDomain(props, axis, childComponents);
var axisComponent = _axis2.default.getAxisComponent(childComponents, axis);
var invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis;
return invertDomain ? domain.concat().reverse() : domain;
},
if (groupComponent.length < 1) {
return undefined;
}
var _groupComponent$0$pro = groupComponent[0].props,
offset = _groupComponent$0$pro.offset,
children = _groupComponent$0$pro.children;
// eslint-disable-next-line complexity
getAxisOffset: function (props, calculatedProps) {
var axisComponents = calculatedProps.axisComponents,
scale = calculatedProps.scale,
origin = calculatedProps.origin,
domain = calculatedProps.domain,
originSign = calculatedProps.originSign,
padding = calculatedProps.padding;
var top = padding.top,
bottom = padding.bottom,
left = padding.left,
right = padding.right;
// make the axes line up, and cross when appropriate
return horizontal ? { y: offset * children.length / 2 } : { x: offset * children.length / 2 };
};
var axisOrientations = {
x: _axis2.default.getOrientation(axisComponents.x, "x", originSign.y),
y: _axis2.default.getOrientation(axisComponents.y, "y", originSign.x)
};
var orientationOffset = {
y: axisOrientations.x === "bottom" ? bottom : top,
x: axisOrientations.y === "left" ? left : right
};
var originOffset = {
x: axisOrientations.y === "left" ? 0 : props.width,
y: axisOrientations.x === "bottom" ? props.height : 0
};
var originPosition = {
x: origin.x === domain.x[0] || origin.x === domain.x[1] ? 0 : scale.x(origin.x),
y: origin.y === domain.y[0] || origin.y === domain.y[1] ? 0 : scale.y(origin.y)
};
var calculatedOffset = {
x: originPosition.x ? Math.abs(originOffset.x - originPosition.x) : orientationOffset.x,
y: originPosition.y ? Math.abs(originOffset.y - originPosition.y) : orientationOffset.y
};
var getDomain = function (props, axis, childComponents) {
childComponents = childComponents || _react2.default.Children.toArray(props.children);
var domain = _wrapper2.default.getDomain(props, axis, childComponents);
var axisComponent = _axis2.default.getAxisComponent(childComponents, axis);
var invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis;
return invertDomain ? domain.concat().reverse() : domain;
};
return {
x: axisComponents.x && axisComponents.x.offsetX !== undefined ? axisComponents.x.offsetX : calculatedOffset.x,
y: axisComponents.y && axisComponents.y.offsetY !== undefined ? axisComponents.y.offsetY : calculatedOffset.y
};
},
createStringMap: function (props, axis, childComponents) {
var allStrings = _wrapper2.default.getStringsFromChildren(props, axis, childComponents);
return allStrings.length === 0 ? null : allStrings.reduce(function (memo, string, index) {
memo[string] = index + 1;
return memo;
}, {});
}
};
// eslint-disable-next-line complexity
var getAxisOffset = function (props, calculatedProps) {
var axisComponents = calculatedProps.axisComponents,
scale = calculatedProps.scale,
origin = calculatedProps.origin,
domain = calculatedProps.domain,
originSign = calculatedProps.originSign,
padding = calculatedProps.padding;
var top = padding.top,
bottom = padding.bottom,
left = padding.left,
right = padding.right;
// make the axes line up, and cross when appropriate
var axisOrientations = {
x: _axis2.default.getOrientation(axisComponents.x, "x", originSign.y),
y: _axis2.default.getOrientation(axisComponents.y, "y", originSign.x)
};
var orientationOffset = {
y: axisOrientations.x === "bottom" ? bottom : top,
x: axisOrientations.y === "left" ? left : right
};
var originOffset = {
x: axisOrientations.y === "left" ? 0 : props.width,
y: axisOrientations.x === "bottom" ? props.height : 0
};
var originPosition = {
x: origin.x === domain.x[0] || origin.x === domain.x[1] ? 0 : scale.x(origin.x),
y: origin.y === domain.y[0] || origin.y === domain.y[1] ? 0 : scale.y(origin.y)
};
var calculatedOffset = {
x: originPosition.x ? Math.abs(originOffset.x - originPosition.x) : orientationOffset.x,
y: originPosition.y ? Math.abs(originOffset.y - originPosition.y) : orientationOffset.y
};
return {
x: axisComponents.x && axisComponents.x.offsetX !== undefined ? axisComponents.x.offsetX : calculatedOffset.x,
y: axisComponents.y && axisComponents.y.offsetY !== undefined ? axisComponents.y.offsetY : calculatedOffset.y
};
};
var createStringMap = function (props, axis, childComponents) {
var allStrings = _wrapper2.default.getStringsFromChildren(props, axis, childComponents);
return allStrings.length === 0 ? null : allStrings.reduce(function (memo, string, index) {
memo[string] = index + 1;
return memo;
}, {});
};
exports.getDomain = getDomain;
exports.getAxisOffset = getAxisOffset;
exports.getDataComponents = getDataComponents;
exports.getChildComponents = getChildComponents;
exports.getDefaultDomainPadding = getDefaultDomainPadding;
exports.createStringMap = createStringMap;

@@ -33,4 +33,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _axis = require("../../helpers/axis");

@@ -119,3 +117,3 @@

var otherAxis = axis === "x" ? "y" : "x";
var axisOffset = _helperMethods2.default.getAxisOffset(props, calculatedProps);
var axisOffset = (0, _helperMethods.getAxisOffset)(props, calculatedProps);
var offsetY = axis === "y" ? undefined : axisOffset.y;

@@ -165,4 +163,4 @@ var offsetX = axis === "x" ? undefined : axisOffset.x;

var domain = {
x: _helperMethods2.default.getDomain(props, "x", childComponents),
y: _helperMethods2.default.getDomain(props, "y", childComponents)
x: (0, _helperMethods.getDomain)(props, "x", childComponents),
y: (0, _helperMethods.getDomain)(props, "y", childComponents)
};

@@ -196,7 +194,7 @@ var range = {

var stringMap = {
x: _helperMethods2.default.createStringMap(props, "x", childComponents),
y: _helperMethods2.default.createStringMap(props, "y", childComponents)
x: (0, _helperMethods.createStringMap)(props, "x", childComponents),
y: (0, _helperMethods.createStringMap)(props, "y", childComponents)
};
var defaultDomainPadding = _helperMethods2.default.getDefaultDomainPadding(childComponents, horizontal);
var defaultDomainPadding = (0, _helperMethods.getDefaultDomainPadding)(childComponents, horizontal);

@@ -275,3 +273,3 @@ var padding = _victoryCore.Helpers.getPadding(props);

var axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes;
var childComponents = _helperMethods2.default.getChildComponents(modifiedProps, axes);
var childComponents = (0, _helperMethods.getChildComponents)(modifiedProps, axes);
var calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);

@@ -278,0 +276,0 @@ var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDomain = exports.getBaseProps = undefined;

@@ -43,248 +44,256 @@ var _isNaN2 = require("lodash/isNaN");

exports.default = {
getBaseProps: function (props, fallbackProps) {
var _this = this;
var getErrors = function (datum, scale, axis) {
/**
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
* and the first value is the positive error, the second is the negative error
* @param {Boolean} isArray(errorX)
* @return {String or Array}
*/
props = _victoryCore.Helpers.modifyProps(props, fallbackProps, "errorbar");
var errorNames = { x: "errorX", y: "errorY" };
var errors = datum[errorNames[axis]];
if (errors === 0) {
return false;
}
var _getCalculatedValues = this.getCalculatedValues(props, fallbackProps),
data = _getCalculatedValues.data,
style = _getCalculatedValues.style,
scale = _getCalculatedValues.scale,
domain = _getCalculatedValues.domain,
origin = _getCalculatedValues.origin;
return (0, _isArray3.default)(errors) ? [errors[0] === 0 ? false : scale[axis](errors[0] + datum["_" + axis]), errors[1] === 0 ? false : scale[axis](datum["_" + axis] - errors[1])] : [scale[axis](errors + datum["_" + axis]), scale[axis](datum["_" + axis] - errors)];
};
var _props = props,
groupComponent = _props.groupComponent,
height = _props.height,
width = _props.width,
borderWidth = _props.borderWidth,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
padding = _props.padding;
var sortData = function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
var initialChildProps = { parent: {
domain: domain, scale: scale, data: data, height: height, width: width, standalone: standalone, theme: theme, polar: polar, origin: origin,
padding: padding, style: style.parent
} };
if (!sortKey) {
return dataset;
}
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
}
var dataProps = {
x: x, y: y, scale: scale, datum: datum, data: data, index: index, groupComponent: groupComponent, borderWidth: borderWidth,
style: _this.getDataStyles(datum, style.data),
errorX: _this.getErrors(datum, scale, "x"),
errorY: _this.getErrors(datum, scale, "y")
};
var sortedData = (0, _sortBy3.default)(dataset, sortKey);
childProps[eventKey] = {
data: dataProps
};
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = _this.getLabelProps(dataProps, text, style);
}
if (sortOrder === "descending") {
return sortedData.reverse();
}
return childProps;
}, initialChildProps);
},
getLabelProps: function (dataProps, text, style) {
var x = dataProps.x,
index = dataProps.index,
scale = dataProps.scale,
errorY = dataProps.errorY;
return sortedData;
};
var error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
var y = error || dataProps.y;
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: y - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: dataProps.datum,
data: dataProps.data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
var formatErrorData = function (dataset, props) {
if (!dataset || _victoryCore.Data.getLength(dataset) < 1) {
return [];
}
var accessor = {
x: _victoryCore.Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: _victoryCore.Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
errorX: _victoryCore.Helpers.createAccessor(props.errorX !== undefined ? props.errorX : "errorX"),
errorY: _victoryCore.Helpers.createAccessor(props.errorY !== undefined ? props.errorY : "errorY")
};
var replaceNegatives = function (errors) {
// check if the value is negative, if it is set to 0
var replaceNeg = function (val) {
return !val || val < 0 ? 0 : val;
};
},
getErrorData: function (props) {
if (props.data) {
if (_victoryCore.Data.getLength(props.data) < 1) {
return [];
}
return (0, _isArray3.default)(errors) ? errors.map(function (err) {
return replaceNeg(err);
}) : replaceNeg(errors);
};
return this.formatErrorData(props.data, props);
} else {
var generatedData = (props.errorX || props.errorY) && this.generateData(props);
return this.formatErrorData(generatedData, props);
}
},
getErrors: function (datum, scale, axis) {
/**
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
* and the first value is the positive error, the second is the negative error
* @param {Boolean} isArray(errorX)
* @return {String or Array}
*/
var stringMap = {
x: _victoryCore.Data.createStringMap(props, "x"),
y: _victoryCore.Data.createStringMap(props, "y")
};
var errorNames = { x: "errorX", y: "errorY" };
var errors = datum[errorNames[axis]];
if (errors === 0) {
return false;
}
var formattedData = dataset.reduce(function (dataArr, datum, index) {
datum = _victoryCore.Data.parseDatum(datum);
return (0, _isArray3.default)(errors) ? [errors[0] === 0 ? false : scale[axis](errors[0] + datum["_" + axis]), errors[1] === 0 ? false : scale[axis](datum["_" + axis] - errors[1])] : [scale[axis](errors + datum["_" + axis]), scale[axis](datum["_" + axis] - errors)];
},
formatErrorData: function (dataset, props) {
if (!dataset || _victoryCore.Data.getLength(dataset) < 1) {
var evaluatedX = accessor.x(datum);
var evaluatedY = accessor.y(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _y = evaluatedY !== undefined ? evaluatedY : datum;
var errorX = replaceNegatives(accessor.errorX(datum));
var errorY = replaceNegatives(accessor.errorY(datum));
dataArr.push((0, _assign3.default)({}, datum, { _x: _x, _y: _y, errorX: errorX, errorY: errorY },
// map string data to numeric values, and add names
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}, typeof _y === "string" ? { _y: stringMap.y[_y], y: _y } : {}));
return dataArr;
}, []);
return sortData(formattedData, props.sortKey, props.sortOrder);
};
var getErrorData = function (props) {
if (props.data) {
if (_victoryCore.Data.getLength(props.data) < 1) {
return [];
}
var accessor = {
x: _victoryCore.Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: _victoryCore.Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
errorX: _victoryCore.Helpers.createAccessor(props.errorX !== undefined ? props.errorX : "errorX"),
errorY: _victoryCore.Helpers.createAccessor(props.errorY !== undefined ? props.errorY : "errorY")
};
var replaceNegatives = function (errors) {
// check if the value is negative, if it is set to 0
var replaceNeg = function (val) {
return !val || val < 0 ? 0 : val;
};
return (0, _isArray3.default)(errors) ? errors.map(function (err) {
return replaceNeg(err);
}) : replaceNeg(errors);
};
return formatErrorData(props.data, props);
} else {
var generatedData = (props.errorX || props.errorY) && _victoryCore.Data.generateData(props);
return formatErrorData(generatedData, props);
}
};
var stringMap = {
x: _victoryCore.Data.createStringMap(props, "x"),
y: _victoryCore.Data.createStringMap(props, "y")
};
var getDomainFromData = function (props, axis, dataset) {
var currentAxis = _victoryCore.Helpers.getCurrentAxis(axis, props.horizontal);
var error = void 0;
if (currentAxis === "x") {
error = "errorX";
} else if (currentAxis === "y") {
error = "errorY";
}
var axisData = (0, _flatten3.default)(dataset).map(function (datum) {
return datum["_" + currentAxis];
});
var errorData = (0, _flatten3.default)((0, _flatten3.default)(dataset).map(function (datum) {
var errorMax = void 0;
var errorMin = void 0;
if ((0, _isArray3.default)(datum[error])) {
errorMax = datum[error][0] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error][1];
} else {
errorMax = datum[error] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error];
}
return [errorMax, errorMin];
}));
var formattedData = dataset.reduce(function (dataArr, datum, index) {
datum = _victoryCore.Data.parseDatum(datum);
var allData = axisData.concat(errorData);
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
// TODO: is the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (+min === +max) {
return _victoryCore.Domain.getSinglePointDomain(max);
}
return [min, max];
};
var evaluatedX = accessor.x(datum);
var evaluatedY = accessor.y(datum);
var _x = evaluatedX !== undefined ? evaluatedX : index;
var _y = evaluatedY !== undefined ? evaluatedY : datum;
var errorX = replaceNegatives(accessor.errorX(datum));
var errorY = replaceNegatives(accessor.errorY(datum));
var getDomain = function (props, axis) {
var propsDomain = _victoryCore.Domain.getDomainFromProps(props, axis);
if (propsDomain) {
return _victoryCore.Domain.padDomain(propsDomain, props, axis);
}
var categoryDomain = _victoryCore.Domain.getDomainFromCategories(props, axis);
if (categoryDomain) {
return _victoryCore.Domain.padDomain(categoryDomain, props, axis);
}
var dataset = getErrorData(props);
dataArr.push((0, _assign3.default)({}, datum, { _x: _x, _y: _y, errorX: errorX, errorY: errorY },
// map string data to numeric values, and add names
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}, typeof _y === "string" ? { _y: stringMap.y[_y], y: _y } : {}));
if (dataset.length < 1) {
return _victoryCore.Scale.getBaseScale(props, axis).domain();
}
return dataArr;
}, []);
var domain = getDomainFromData(props, axis, dataset);
return _victoryCore.Domain.cleanDomain(_victoryCore.Domain.padDomain(domain, props, axis), props);
};
return this.sortData(formattedData, props.sortKey, props.sortOrder);
},
sortData: function (dataset, sortKey) {
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
var getCalculatedValues = function (props) {
var defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ? props.theme.errorbar.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles) || {};
var dataWithErrors = (0, _assign3.default)(_victoryCore.Data.getData(props), getErrorData(props));
var data = _victoryCore.Data.addEventKeys(props, dataWithErrors);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: getDomain(props, "x"),
y: getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
};
if (!sortKey) {
return dataset;
}
var getLabelProps = function (dataProps, text, style) {
var x = dataProps.x,
index = dataProps.index,
scale = dataProps.scale,
errorY = dataProps.errorY;
if (sortKey === "x" || sortKey === "y") {
sortKey = "_" + sortKey;
}
var error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
var y = error || dataProps.y;
var labelStyle = style.labels || {};
return {
style: labelStyle,
y: y - (labelStyle.padding || 0),
x: x,
text: text,
index: index,
scale: scale,
datum: dataProps.datum,
data: dataProps.data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
};
var sortedData = (0, _sortBy3.default)(dataset, sortKey);
var getDataStyles = function (datum, style) {
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "y", "_x", "_y", "name", "errorX", "errorY", "eventKey", "label"];
var stylesFromData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return (0, _defaults3.default)({}, stylesFromData, style);
};
if (sortOrder === "descending") {
return sortedData.reverse();
}
var getBaseProps = function (props, fallbackProps) {
props = _victoryCore.Helpers.modifyProps(props, fallbackProps, "errorbar");
return sortedData;
},
getDomain: function (props, axis) {
var propsDomain = _victoryCore.Domain.getDomainFromProps(props, axis);
if (propsDomain) {
return _victoryCore.Domain.padDomain(propsDomain, props, axis);
}
var categoryDomain = _victoryCore.Domain.getDomainFromCategories(props, axis);
if (categoryDomain) {
return _victoryCore.Domain.padDomain(categoryDomain, props, axis);
}
var dataset = this.getErrorData(props);
var _getCalculatedValues = getCalculatedValues(props, fallbackProps),
data = _getCalculatedValues.data,
style = _getCalculatedValues.style,
scale = _getCalculatedValues.scale,
domain = _getCalculatedValues.domain,
origin = _getCalculatedValues.origin;
if (dataset.length < 1) {
return _victoryCore.Scale.getBaseScale(props, axis).domain();
}
var _props = props,
groupComponent = _props.groupComponent,
height = _props.height,
width = _props.width,
borderWidth = _props.borderWidth,
standalone = _props.standalone,
theme = _props.theme,
polar = _props.polar,
padding = _props.padding;
var domain = this.getDomainFromData(props, axis, dataset);
return _victoryCore.Domain.cleanDomain(_victoryCore.Domain.padDomain(domain, props, axis), props);
},
getDomainFromData: function (props, axis, dataset) {
var currentAxis = _victoryCore.Helpers.getCurrentAxis(axis, props.horizontal);
var error = void 0;
if (currentAxis === "x") {
error = "errorX";
} else if (currentAxis === "y") {
error = "errorY";
}
var axisData = (0, _flatten3.default)(dataset).map(function (datum) {
return datum["_" + currentAxis];
});
var errorData = (0, _flatten3.default)((0, _flatten3.default)(dataset).map(function (datum) {
var errorMax = void 0;
var errorMin = void 0;
if ((0, _isArray3.default)(datum[error])) {
errorMax = datum[error][0] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error][1];
} else {
errorMax = datum[error] + datum["_" + currentAxis];
errorMin = datum["_" + currentAxis] - datum[error];
}
return [errorMax, errorMin];
}));
var initialChildProps = { parent: {
domain: domain, scale: scale, data: data, height: height, width: width, standalone: standalone, theme: theme, polar: polar, origin: origin,
padding: padding, style: style.parent
} };
var allData = axisData.concat(errorData);
var min = Math.min.apply(Math, _toConsumableArray(allData));
var max = Math.max.apply(Math, _toConsumableArray(allData));
// TODO: is this the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (+min === +max) {
return _victoryCore.Domain.getSinglePointDomain(max);
}
return [min, max];
},
getCalculatedValues: function (props) {
var defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ? props.theme.errorbar.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles) || {};
var dataWithErrors = (0, _assign3.default)(_victoryCore.Data.getData(props), this.getErrorData(props));
var data = _victoryCore.Data.addEventKeys(props, dataWithErrors);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
return data.reduce(function (childProps, datum, index) {
var eventKey = datum.eventKey || index;
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
var y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
var dataProps = {
x: x, y: y, scale: scale, datum: datum, data: data, index: index, groupComponent: groupComponent, borderWidth: borderWidth,
style: getDataStyles(datum, style.data),
errorX: getErrors(datum, scale, "x"),
errorY: getErrors(datum, scale, "y")
};
var domain = {
x: this.getDomain(props, "x"),
y: this.getDomain(props, "y")
childProps[eventKey] = {
data: dataProps
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
},
getDataStyles: function (datum, style) {
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "y", "_x", "_y", "name", "errorX", "errorY", "eventKey", "label"];
var stylesFromData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return (0, _defaults3.default)({}, stylesFromData, style);
}
};
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}
return childProps;
}, initialChildProps);
};
exports.getBaseProps = getBaseProps;
exports.getDomain = getDomain;

@@ -25,4 +25,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _commonProps = require("../../helpers/common-props");

@@ -103,6 +101,6 @@

};
VictoryErrorBar.getDomain = _helperMethods2.default.getDomain.bind(_helperMethods2.default);
VictoryErrorBar.getDomain = _helperMethods.getDomain;
VictoryErrorBar.getData = _victoryCore.Data.getData.bind(_victoryCore.Data);
VictoryErrorBar.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryErrorBar.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryErrorBar.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryErrorBar);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBaseProps = undefined;

@@ -13,64 +14,65 @@ var _assign2 = require("lodash/assign");

exports.default = {
getBaseProps: function (props, fallbackProps) {
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "line");
props = (0, _assign3.default)({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getCalculatedValues = function (props) {
var data = _victoryCore.Data.getData(props);
var initialChildProps = {
parent: {
style: style.parent, scale: scale, data: data, height: height, width: width, domain: domain, standalone: standalone, polar: polar, origin: origin, padding: padding
},
all: { data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, theme: theme, style: style.data }
}
};
return data.reduce(function (childProps, datum, index) {
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: _victoryCore.LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
},
getCalculatedValues: function (props) {
var data = _victoryCore.Data.getData(props);
if (data.length < 2) {
data = [];
}
if (data.length < 2) {
data = [];
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomain(props, "x"),
y: _victoryCore.Domain.getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
var defaultStyles = props.theme && props.theme.line && props.theme.line.style ? props.theme.line.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
};
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "line");
props = (0, _assign3.default)({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
groupComponent = _props.groupComponent,
height = _props.height,
interpolation = _props.interpolation,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var initialChildProps = {
parent: {
style: style.parent, scale: scale, data: data, height: height, width: width, domain: domain, standalone: standalone, polar: polar, origin: origin, padding: padding
},
all: { data: { polar: polar, origin: origin, scale: scale, data: data, interpolation: interpolation, groupComponent: groupComponent, theme: theme, style: style.data }
}
};
return data.reduce(function (childProps, datum, index) {
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
var eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: _victoryCore.LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
};
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomain(props, "x"),
y: _victoryCore.Domain.getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var origin = props.polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
var defaultStyles = props.theme && props.theme.line && props.theme.line.style ? props.theme.line.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
return { domain: domain, data: data, scale: scale, style: style, origin: origin };
}
};
exports.getBaseProps = getBaseProps;

@@ -23,4 +23,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _victoryCore = require("victory-core");

@@ -108,4 +106,4 @@

VictoryLine.getData = _victoryCore.Data.getData.bind(_victoryCore.Data);
VictoryLine.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryLine.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryLine.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryLine, options);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBaseProps = exports.getStyles = exports.getScale = exports.getAxis = exports.getDomain = undefined;

@@ -33,370 +34,388 @@ var _isFunction2 = require("lodash/isFunction");

exports.default = {
getCalculatedValues: function (props) {
var defaultStyles = this.getStyleObject(props);
var style = this.getStyles(props, defaultStyles);
var padding = _victoryCore.Helpers.getPadding(props);
var axis = this.getAxis(props);
var axisType = this.getAxisType(props);
var stringTicks = _victoryCore.Helpers.stringTicks(props) ? props.tickValues : undefined;
var domain = this.getDomain(props, axis);
var range = this.getRange(props, axis);
var scale = this.getScale(props);
var initialTicks = _axis2.default.getTicks(props, scale);
var ticks = axisType === "angular" ? this.filterTicks(initialTicks, scale) : initialTicks;
var tickFormat = _axis2.default.getTickFormat(props, scale);
var radius = this.getRadius(props);
return {
axis: axis, style: style, padding: padding, stringTicks: stringTicks, axisType: axisType, scale: scale, ticks: ticks, tickFormat: tickFormat, domain: domain, range: range, radius: radius
};
},
evaluateProp: function (prop, data, index) {
return (0, _isFunction3.default)(prop) ? prop(data, index) : prop;
},
evaluateStyle: function (style, data, index) {
var _this = this;
// exposed for use by VictoryChart
var getAxis = function (props, flipped) {
var typicalAxis = props.dependentAxis ? "y" : "x";
var invertedAxis = typicalAxis === "x" ? "y" : "x";
return flipped ? invertedAxis : typicalAxis;
};
if (!style || !Object.keys(style).some(function (value) {
return (0, _isFunction3.default)(style[value]);
})) {
return style;
}
return Object.keys(style).reduce(function (prev, curr) {
prev[curr] = _this.evaluateProp(style[curr], data, index);
return prev;
}, {});
},
var getPosition = function (r, angle, axis) {
return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle);
};
var getAxisType = function (props) {
var typicalType = props.dependentAxis ? "radial" : "angular";
var invertedType = typicalType === "angular" ? "radial" : "angular";
return props.horizontal ? invertedType : typicalType;
};
// exposed for use by VictoryChart
getDomain: function (props, axis) {
var inherentAxis = this.getAxis(props);
if (axis && axis !== inherentAxis) {
return undefined;
}
var domain = void 0;
if (Array.isArray(props.domain)) {
domain = props.domain;
} else if (props.domain && props.domain[inherentAxis]) {
domain = props.domain[inherentAxis];
} else if (Array.isArray(props.tickValues) && props.tickValues.length > 1) {
domain = this.getDomainFromTickValues(props, axis);
}
var paddedDomain = _victoryCore.Domain.padDomain(domain, props, inherentAxis);
return domain ? _victoryCore.Domain.cleanDomain(paddedDomain, props, inherentAxis) : undefined;
},
getDomainFromTickValues: function (props, axis) {
var tickValues = props.tickValues,
_props$startAngle = props.startAngle,
startAngle = _props$startAngle === undefined ? 0 : _props$startAngle,
_props$endAngle = props.endAngle,
endAngle = _props$endAngle === undefined ? 360 : _props$endAngle;
var filterTicks = function (ticks, scale) {
var compareTicks = function (t) {
return scale(t) % (2 * Math.PI);
};
return (0, _uniqBy3.default)(ticks, compareTicks);
};
if (_victoryCore.Helpers.stringTicks(props)) {
return [1, tickValues.length];
} else {
var ticks = tickValues.map(function (value) {
return +value;
});
var domain = [_victoryCore.Collection.getMinValue(ticks), _victoryCore.Collection.getMaxValue(ticks)];
return axis === "x" && Math.abs(startAngle - endAngle) === 360 ? _victoryCore.Domain.getSymmetricDomain(domain, ticks) : domain;
}
},
getRadius: function (props) {
var _Helpers$getPadding = _victoryCore.Helpers.getPadding(props),
left = _Helpers$getPadding.left,
right = _Helpers$getPadding.right,
top = _Helpers$getPadding.top,
bottom = _Helpers$getPadding.bottom;
var evaluateProp = function (prop, data, index) {
return (0, _isFunction3.default)(prop) ? prop(data, index) : prop;
};
var width = props.width,
height = props.height;
var evaluateStyle = function (style, data, index) {
if (!style || !Object.keys(style).some(function (value) {
return (0, _isFunction3.default)(style[value]);
})) {
return style;
}
return Object.keys(style).reduce(function (prev, curr) {
prev[curr] = evaluateProp(style[curr], data, index);
return prev;
}, {});
};
return Math.min(width - left - right, height - top - bottom) / 2;
},
getRange: function (props, axis) {
// Return the range from props if one is given.
if (props.range && props.range[axis]) {
return props.range[axis];
} else if (props.range && Array.isArray(props.range)) {
return props.range;
}
var axisType = this.getAxisType(props);
if (axisType === "angular") {
var startAngle = _victoryCore.Helpers.degreesToRadians(props.startAngle);
var endAngle = _victoryCore.Helpers.degreesToRadians(props.endAngle);
return [startAngle, endAngle];
}
var radius = this.getRadius(props);
return [props.innerRadius || 0, radius];
},
var getEvaluatedStyles = function (style, tick, index) {
return {
tickStyle: evaluateStyle(style.ticks, tick, index),
labelStyle: evaluateStyle(style.tickLabels, tick, index),
gridStyle: evaluateStyle(style.grid, tick, index)
};
};
var getDomainFromTickValues = function (props, axis) {
var tickValues = props.tickValues,
_props$startAngle = props.startAngle,
startAngle = _props$startAngle === undefined ? 0 : _props$startAngle,
_props$endAngle = props.endAngle,
endAngle = _props$endAngle === undefined ? 360 : _props$endAngle;
// exposed for use by VictoryChart
getAxis: function (props, flipped) {
var typicalAxis = props.dependentAxis ? "y" : "x";
var invertedAxis = typicalAxis === "x" ? "y" : "x";
return flipped ? invertedAxis : typicalAxis;
},
getAxisType: function (props) {
var typicalType = props.dependentAxis ? "radial" : "angular";
var invertedType = typicalType === "angular" ? "radial" : "angular";
return props.horizontal ? invertedType : typicalType;
},
if (_victoryCore.Helpers.stringTicks(props)) {
return [1, tickValues.length];
} else {
var ticks = tickValues.map(function (value) {
return +value;
});
var domain = [_victoryCore.Collection.getMinValue(ticks), _victoryCore.Collection.getMaxValue(ticks)];
return axis === "x" && Math.abs(startAngle - endAngle) === 360 ? _victoryCore.Domain.getSymmetricDomain(domain, ticks) : domain;
}
};
// exposed for use by VictoryChart
var getDomain = function (props, axis) {
var inherentAxis = getAxis(props);
if (axis && axis !== inherentAxis) {
return undefined;
}
var domain = void 0;
if (Array.isArray(props.domain)) {
domain = props.domain;
} else if (props.domain && props.domain[inherentAxis]) {
domain = props.domain[inherentAxis];
} else if (Array.isArray(props.tickValues) && props.tickValues.length > 1) {
domain = getDomainFromTickValues(props, axis);
}
var paddedDomain = _victoryCore.Domain.padDomain(domain, props, inherentAxis);
return domain ? _victoryCore.Domain.cleanDomain(paddedDomain, props, inherentAxis) : undefined;
};
// exposed for use by VictoryChart (necessary?)
getScale: function (props) {
var axis = this.getAxis(props);
var scale = _victoryCore.Scale.getBaseScale(props, axis);
var domain = this.getDomain(props, axis) || scale.domain();
var range = this.getRange(props, axis);
scale.range(range);
scale.domain(domain);
return scale;
},
getStyleObject: function (props) {
var theme = props.theme,
dependentAxis = props.dependentAxis;
var getStyleObject = function (props) {
var theme = props.theme,
dependentAxis = props.dependentAxis;
var generalAxisStyle = theme && theme.axis && theme.axis.style;
var axisType = dependentAxis ? "dependentAxis" : "independentAxis";
var specificAxisStyle = theme && theme[axisType] && theme[axisType].style;
var generalAxisStyle = theme && theme.axis && theme.axis.style;
var axisType = dependentAxis ? "dependentAxis" : "independentAxis";
var specificAxisStyle = theme && theme[axisType] && theme[axisType].style;
return generalAxisStyle && specificAxisStyle ? (0, _defaultsDeep3.default)({}, specificAxisStyle, generalAxisStyle) : specificAxisStyle || generalAxisStyle;
},
getStyles: function (props, styleObject) {
var style = props.style || {};
styleObject = styleObject || {};
var parentStyleProps = { height: "auto", width: "100%" };
return {
parent: (0, _defaults3.default)(parentStyleProps, style.parent, styleObject.parent),
axis: (0, _defaults3.default)({}, style.axis, styleObject.axis),
axisLabel: (0, _defaults3.default)({}, style.axisLabel, styleObject.axisLabel),
grid: (0, _defaults3.default)({}, style.grid, styleObject.grid),
ticks: (0, _defaults3.default)({}, style.ticks, styleObject.ticks),
tickLabels: (0, _defaults3.default)({}, style.tickLabels, styleObject.tickLabels)
};
},
getAxisAngle: function (props) {
var axisAngle = props.axisAngle,
startAngle = props.startAngle,
axisValue = props.axisValue,
dependentAxis = props.dependentAxis,
scale = props.scale;
return generalAxisStyle && specificAxisStyle ? (0, _defaultsDeep3.default)({}, specificAxisStyle, generalAxisStyle) : specificAxisStyle || generalAxisStyle;
};
var otherAxis = this.getAxis(props) === "y" ? "x" : "y";
if (axisValue === undefined || !dependentAxis || scale[otherAxis] === undefined) {
return axisAngle || startAngle;
}
return _victoryCore.Helpers.radiansToDegrees(scale.x(axisValue));
},
getTickProps: function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale,
style = calculatedValues.style,
stringTicks = calculatedValues.stringTicks;
var getRadius = function (props) {
var _Helpers$getPadding = _victoryCore.Helpers.getPadding(props),
left = _Helpers$getPadding.left,
right = _Helpers$getPadding.right,
top = _Helpers$getPadding.top,
bottom = _Helpers$getPadding.bottom;
var originalTick = stringTicks ? stringTicks[index] : tick;
var width = props.width,
height = props.height;
var _getEvaluatedStyles = this.getEvaluatedStyles(style, originalTick, index),
tickStyle = _getEvaluatedStyles.tickStyle;
return Math.min(width - left - right, height - top - bottom) / 2;
};
var tickPadding = tickStyle.padding || 0;
var angularPadding = tickPadding; // TODO: do some geometry
var axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
return axisType === "angular" ? {
index: index, datum: tick, style: tickStyle,
x1: radius * Math.cos(scale(tick)),
y1: -radius * Math.sin(scale(tick)),
x2: (radius + tickPadding) * Math.cos(scale(tick)),
y2: -(radius + tickPadding) * Math.sin(scale(tick))
} : {
style: style, index: index, datum: tick,
x1: scale(tick) / 2 * Math.cos(axisAngle - angularPadding),
x2: scale(tick) / 2 * Math.cos(axisAngle + angularPadding),
y1: -(scale(tick) / 2) * Math.sin(axisAngle - angularPadding),
y2: -(scale(tick) / 2) * Math.sin(axisAngle + angularPadding)
};
},
getTickLabelProps: function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
tickFormat = calculatedValues.tickFormat,
style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
stringTicks = calculatedValues.stringTicks;
var getRange = function (props, axis) {
// Return the range from props if one is given.
if (props.range && props.range[axis]) {
return props.range[axis];
} else if (props.range && Array.isArray(props.range)) {
return props.range;
}
var axisType = getAxisType(props);
if (axisType === "angular") {
var startAngle = _victoryCore.Helpers.degreesToRadians(props.startAngle);
var endAngle = _victoryCore.Helpers.degreesToRadians(props.endAngle);
return [startAngle, endAngle];
}
var radius = getRadius(props);
return [props.innerRadius || 0, radius];
};
var originalTick = stringTicks ? stringTicks[index] : tick;
// exposed for use by VictoryChart (necessary?)
var getScale = function (props) {
var axis = getAxis(props);
var scale = _victoryCore.Scale.getBaseScale(props, axis);
var domain = getDomain(props, axis) || scale.domain();
var range = getRange(props, axis);
scale.range(range);
scale.domain(domain);
return scale;
};
var _getEvaluatedStyles2 = this.getEvaluatedStyles(style, originalTick, index),
labelStyle = _getEvaluatedStyles2.labelStyle;
var getStyles = function (props, styleObject) {
var style = props.style || {};
styleObject = styleObject || {};
var parentStyleProps = { height: "auto", width: "100%" };
return {
parent: (0, _defaults3.default)(parentStyleProps, style.parent, styleObject.parent),
axis: (0, _defaults3.default)({}, style.axis, styleObject.axis),
axisLabel: (0, _defaults3.default)({}, style.axisLabel, styleObject.axisLabel),
grid: (0, _defaults3.default)({}, style.grid, styleObject.grid),
ticks: (0, _defaults3.default)({}, style.ticks, styleObject.ticks),
tickLabels: (0, _defaults3.default)({}, style.tickLabels, styleObject.tickLabels)
};
};
var tickLabelComponent = props.tickLabelComponent;
var getAxisAngle = function (props) {
var axisAngle = props.axisAngle,
startAngle = props.startAngle,
axisValue = props.axisValue,
dependentAxis = props.dependentAxis,
scale = props.scale;
var labelPlacement = tickLabelComponent.props && tickLabelComponent.props.labelPlacement ? tickLabelComponent.props.labelPlacement : props.labelPlacement;
var tickPadding = labelStyle.padding || 0;
var angularPadding = 0; // TODO: do some geometry
var axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
var labelAngle = axisType === "angular" ? _victoryCore.Helpers.radiansToDegrees(scale(tick)) : axisAngle + angularPadding;
var textAngle = labelStyle.angle || _victoryCore.LabelHelpers.getPolarAngle((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), labelAngle);
var labelRadius = axisType === "angular" ? radius + tickPadding : scale(tick);
var textAnchor = labelStyle.textAnchor || _victoryCore.LabelHelpers.getPolarTextAnchor((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), labelAngle);
return {
index: index, datum: tick, style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
text: tickFormat(tick, index, ticks),
x: labelRadius * Math.cos(_victoryCore.Helpers.degreesToRadians(labelAngle)),
y: -labelRadius * Math.sin(_victoryCore.Helpers.degreesToRadians(labelAngle))
};
},
getGridProps: function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale,
stringTicks = calculatedValues.stringTicks;
var startAngle = props.startAngle,
endAngle = props.endAngle,
_props$innerRadius = props.innerRadius,
innerRadius = _props$innerRadius === undefined ? 0 : _props$innerRadius;
var otherAxis = getAxis(props) === "y" ? "x" : "y";
if (axisValue === undefined || !dependentAxis || scale[otherAxis] === undefined) {
return axisAngle || startAngle;
}
return _victoryCore.Helpers.radiansToDegrees(scale.x(axisValue));
};
var originalTick = stringTicks ? stringTicks[index] : tick;
var getTickProps = function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale,
style = calculatedValues.style,
stringTicks = calculatedValues.stringTicks;
var _getEvaluatedStyles3 = this.getEvaluatedStyles(style, originalTick, index),
gridStyle = _getEvaluatedStyles3.gridStyle;
var originalTick = stringTicks ? stringTicks[index] : tick;
var angle = scale(tick);
return axisType === "angular" ? {
index: index, datum: tick, style: gridStyle,
x1: this.getPosition(radius, angle, "x"),
y1: this.getPosition(radius, angle, "y"),
x2: this.getPosition(innerRadius, angle, "x"),
y2: this.getPosition(innerRadius, angle, "y")
} : {
style: gridStyle, index: index, datum: tick,
cx: 0, cy: 0, r: scale(tick), startAngle: startAngle, endAngle: endAngle
};
},
getAxisLabelProps: function (props, calculatedValues) {
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale;
var axisLabelComponent = props.axisLabelComponent;
var _getEvaluatedStyles = getEvaluatedStyles(style, originalTick, index),
tickStyle = _getEvaluatedStyles.tickStyle;
if (axisType !== "radial") {
return {};
}
var labelPlacement = axisLabelComponent.props && axisLabelComponent.props.labelPlacement ? axisLabelComponent.props.labelPlacement : props.labelPlacement;
var labelStyle = style && style.axisLabel || {};
var axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
var textAngle = labelStyle.angle || _victoryCore.LabelHelpers.getPolarAngle((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), axisAngle);
var labelRadius = radius + (labelStyle.padding || 0);
var textAnchor = labelStyle.textAnchor || _victoryCore.LabelHelpers.getTextPolarAnchor((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), axisAngle);
var verticalAnchor = labelStyle.verticalAnchor || _victoryCore.LabelHelpers.getPolarVerticalAnchor((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), axisAngle);
return {
style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
verticalAnchor: verticalAnchor,
text: props.label,
x: this.getPosition(labelRadius, _victoryCore.Helpers.degreesToRadians(axisAngle), "x"),
y: this.getPosition(labelRadius, _victoryCore.Helpers.degreesToRadians(axisAngle), "y")
};
},
getPosition: function (r, angle, axis) {
return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle);
},
getAxisProps: function (modifiedProps, calculatedValues) {
var style = calculatedValues.style,
axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale;
var startAngle = modifiedProps.startAngle,
endAngle = modifiedProps.endAngle,
_modifiedProps$innerR = modifiedProps.innerRadius,
innerRadius = _modifiedProps$innerR === undefined ? 0 : _modifiedProps$innerR;
var tickPadding = tickStyle.padding || 0;
var angularPadding = tickPadding; // TODO: do some geometry
var axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
return axisType === "angular" ? {
index: index, datum: tick, style: tickStyle,
x1: radius * Math.cos(scale(tick)),
y1: -radius * Math.sin(scale(tick)),
x2: (radius + tickPadding) * Math.cos(scale(tick)),
y2: -(radius + tickPadding) * Math.sin(scale(tick))
} : {
style: style, index: index, datum: tick,
x1: scale(tick) / 2 * Math.cos(axisAngle - angularPadding),
x2: scale(tick) / 2 * Math.cos(axisAngle + angularPadding),
y1: -(scale(tick) / 2) * Math.sin(axisAngle - angularPadding),
y2: -(scale(tick) / 2) * Math.sin(axisAngle + angularPadding)
};
};
var axisAngle = axisType === "radial" ? _victoryCore.Helpers.degreesToRadians(this.getAxisAngle(modifiedProps, scale)) : undefined;
return axisType === "radial" ? {
style: style.axis,
x1: this.getPosition(innerRadius, axisAngle, "x"),
x2: this.getPosition(radius, axisAngle, "x"),
y1: this.getPosition(innerRadius, axisAngle, "y"),
y2: this.getPosition(radius, axisAngle, "y")
} : {
style: style.axis,
cx: 0, cy: 0, r: radius, startAngle: startAngle, endAngle: endAngle
};
},
getEvaluatedStyles: function (style, tick, index) {
return {
tickStyle: this.evaluateStyle(style.ticks, tick, index),
labelStyle: this.evaluateStyle(style.tickLabels, tick, index),
gridStyle: this.evaluateStyle(style.grid, tick, index)
};
},
getRole: function (props) {
if (props.dependentAxis) {
return props.theme && props.theme.dependentAxis ? "dependentAxis" : "axis";
}
//eslint-disable-next-line max-params
var getTickLabelProps = function (props, calculatedValues, tick, index) {
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
tickFormat = calculatedValues.tickFormat,
style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
stringTicks = calculatedValues.stringTicks;
return props.theme && props.theme.independentAxis ? "independentAxis" : "axis";
},
getShallowMergedThemeProps: function (props, role) {
var axisTheme = props.theme.axis || {};
return (0, _defaults3.default)({}, props.theme[role], axisTheme);
},
modifyProps: function (props, fallbackProps, role) {
if (role !== "axis") {
props.theme[role] = this.getShallowMergedThemeProps(props, role);
}
return _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
},
getBaseProps: function (props, fallbackProps) {
var _this2 = this;
var originalTick = stringTicks ? stringTicks[index] : tick;
var role = this.getRole(props);
props = this.modifyProps(props, fallbackProps, role);
var calculatedValues = this.getCalculatedValues(props);
var style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
domain = calculatedValues.domain;
var _props = props,
width = _props.width,
height = _props.height,
standalone = _props.standalone,
theme = _props.theme;
var _getEvaluatedStyles2 = getEvaluatedStyles(style, originalTick, index),
labelStyle = _getEvaluatedStyles2.labelStyle;
var axisProps = this.getAxisProps(props, calculatedValues);
var axisLabelProps = this.getAxisLabelProps(props, calculatedValues);
var initialChildProps = { parent: { style: style.parent, ticks: ticks, scale: scale, width: width, height: height, domain: domain, standalone: standalone, theme: theme }
var tickLabelComponent = props.tickLabelComponent;
var labelPlacement = tickLabelComponent.props && tickLabelComponent.props.labelPlacement ? tickLabelComponent.props.labelPlacement : props.labelPlacement;
var tickPadding = labelStyle.padding || 0;
var angularPadding = 0; // TODO: do some geometry
var axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
var labelAngle = axisType === "angular" ? _victoryCore.Helpers.radiansToDegrees(scale(tick)) : axisAngle + angularPadding;
var textAngle = labelStyle.angle || _victoryCore.LabelHelpers.getPolarAngle((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), labelAngle);
var labelRadius = axisType === "angular" ? radius + tickPadding : scale(tick);
var textAnchor = labelStyle.textAnchor || _victoryCore.LabelHelpers.getPolarTextAnchor((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), labelAngle);
return {
index: index, datum: tick, style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
text: tickFormat(tick, index, ticks),
x: labelRadius * Math.cos(_victoryCore.Helpers.degreesToRadians(labelAngle)),
y: -labelRadius * Math.sin(_victoryCore.Helpers.degreesToRadians(labelAngle))
};
};
var getGridProps = function (props, calculatedValues, tick, index) {
//eslint-disable-line max-params
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale,
stringTicks = calculatedValues.stringTicks;
var startAngle = props.startAngle,
endAngle = props.endAngle,
_props$innerRadius = props.innerRadius,
innerRadius = _props$innerRadius === undefined ? 0 : _props$innerRadius;
var originalTick = stringTicks ? stringTicks[index] : tick;
var _getEvaluatedStyles3 = getEvaluatedStyles(style, originalTick, index),
gridStyle = _getEvaluatedStyles3.gridStyle;
var angle = scale(tick);
return axisType === "angular" ? {
index: index, datum: tick, style: gridStyle,
x1: getPosition(radius, angle, "x"),
y1: getPosition(radius, angle, "y"),
x2: getPosition(innerRadius, angle, "x"),
y2: getPosition(innerRadius, angle, "y")
} : {
style: gridStyle, index: index, datum: tick,
cx: 0, cy: 0, r: scale(tick), startAngle: startAngle, endAngle: endAngle
};
};
var getAxisLabelProps = function (props, calculatedValues) {
var axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
style = calculatedValues.style,
scale = calculatedValues.scale;
var axisLabelComponent = props.axisLabelComponent;
if (axisType !== "radial") {
return {};
}
var labelPlacement = axisLabelComponent.props && axisLabelComponent.props.labelPlacement ? axisLabelComponent.props.labelPlacement : props.labelPlacement;
var labelStyle = style && style.axisLabel || {};
var axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
var textAngle = labelStyle.angle || _victoryCore.LabelHelpers.getPolarAngle((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), axisAngle);
var labelRadius = radius + (labelStyle.padding || 0);
var textAnchor = labelStyle.textAnchor || _victoryCore.LabelHelpers.getTextPolarAnchor((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), axisAngle);
var verticalAnchor = labelStyle.verticalAnchor || _victoryCore.LabelHelpers.getPolarVerticalAnchor((0, _assign3.default)({}, props, { labelPlacement: labelPlacement }), axisAngle);
return {
style: labelStyle,
angle: textAngle,
textAnchor: textAnchor,
verticalAnchor: verticalAnchor,
text: props.label,
x: getPosition(labelRadius, _victoryCore.Helpers.degreesToRadians(axisAngle), "x"),
y: getPosition(labelRadius, _victoryCore.Helpers.degreesToRadians(axisAngle), "y")
};
};
var getAxisProps = function (modifiedProps, calculatedValues) {
var style = calculatedValues.style,
axisType = calculatedValues.axisType,
radius = calculatedValues.radius,
scale = calculatedValues.scale;
var startAngle = modifiedProps.startAngle,
endAngle = modifiedProps.endAngle,
_modifiedProps$innerR = modifiedProps.innerRadius,
innerRadius = _modifiedProps$innerR === undefined ? 0 : _modifiedProps$innerR;
var axisAngle = axisType === "radial" ? _victoryCore.Helpers.degreesToRadians(getAxisAngle(modifiedProps, scale)) : undefined;
return axisType === "radial" ? {
style: style.axis,
x1: getPosition(innerRadius, axisAngle, "x"),
x2: getPosition(radius, axisAngle, "x"),
y1: getPosition(innerRadius, axisAngle, "y"),
y2: getPosition(radius, axisAngle, "y")
} : {
style: style.axis,
cx: 0, cy: 0, r: radius, startAngle: startAngle, endAngle: endAngle
};
};
var getRole = function (props) {
if (props.dependentAxis) {
return props.theme && props.theme.dependentAxis ? "dependentAxis" : "axis";
}
return props.theme && props.theme.independentAxis ? "independentAxis" : "axis";
};
var getShallowMergedThemeProps = function (props, role) {
var axisTheme = props.theme.axis || {};
return (0, _defaults3.default)({}, props.theme[role], axisTheme);
};
var modifyProps = function (props, fallbackProps, role) {
if (role !== "axis") {
props.theme[role] = getShallowMergedThemeProps(props, role);
}
return _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
};
var getCalculatedValues = function (props) {
var defaultStyles = getStyleObject(props);
var style = getStyles(props, defaultStyles);
var padding = _victoryCore.Helpers.getPadding(props);
var axis = getAxis(props);
var axisType = getAxisType(props);
var stringTicks = _victoryCore.Helpers.stringTicks(props) ? props.tickValues : undefined;
var domain = getDomain(props, axis);
var range = getRange(props, axis);
var scale = getScale(props);
var initialTicks = _axis2.default.getTicks(props, scale);
var ticks = axisType === "angular" ? filterTicks(initialTicks, scale) : initialTicks;
var tickFormat = _axis2.default.getTickFormat(props, scale);
var radius = getRadius(props);
return {
axis: axis, style: style, padding: padding, stringTicks: stringTicks, axisType: axisType, scale: scale, ticks: ticks, tickFormat: tickFormat, domain: domain, range: range, radius: radius
};
};
var getBaseProps = function (props, fallbackProps) {
var role = getRole(props);
props = modifyProps(props, fallbackProps, role);
var calculatedValues = getCalculatedValues(props);
var style = calculatedValues.style,
scale = calculatedValues.scale,
ticks = calculatedValues.ticks,
domain = calculatedValues.domain;
var _props = props,
width = _props.width,
height = _props.height,
standalone = _props.standalone,
theme = _props.theme;
var axisProps = getAxisProps(props, calculatedValues);
var axisLabelProps = getAxisLabelProps(props, calculatedValues);
var initialChildProps = { parent: { style: style.parent, ticks: ticks, scale: scale, width: width, height: height, domain: domain, standalone: standalone, theme: theme }
};
return ticks.reduce(function (childProps, tick, index) {
childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
ticks: getTickProps(props, calculatedValues, tick, index),
tickLabels: getTickLabelProps(props, calculatedValues, tick, index),
grid: getGridProps(props, calculatedValues, tick, index)
};
return ticks.reduce(function (childProps, tick, index) {
childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
ticks: _this2.getTickProps(props, calculatedValues, tick, index),
tickLabels: _this2.getTickLabelProps(props, calculatedValues, tick, index),
grid: _this2.getGridProps(props, calculatedValues, tick, index)
};
return childProps;
}, initialChildProps);
};
return childProps;
}, initialChildProps);
},
filterTicks: function (ticks, scale) {
var compareTicks = function (t) {
return scale(t) % (2 * Math.PI);
};
return (0, _uniqBy3.default)(ticks, compareTicks);
}
};
exports.getDomain = getDomain;
exports.getAxis = getAxis;
exports.getScale = getScale;
exports.getStyles = getStyles;
exports.getBaseProps = getBaseProps;

@@ -29,4 +29,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _commonProps = require("../../helpers/common-props");

@@ -209,8 +207,8 @@

};
VictoryPolarAxis.getDomain = _helperMethods2.default.getDomain.bind(_helperMethods2.default);
VictoryPolarAxis.getAxis = _helperMethods2.default.getAxis.bind(_helperMethods2.default);
VictoryPolarAxis.getScale = _helperMethods2.default.getScale.bind(_helperMethods2.default);
VictoryPolarAxis.getStyles = (0, _partialRight3.default)(_helperMethods2.default.getStyles.bind(_helperMethods2.default), fallbackProps.style);
VictoryPolarAxis.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryPolarAxis.getDomain = _helperMethods.getDomain;
VictoryPolarAxis.getAxis = _helperMethods.getAxis;
VictoryPolarAxis.getScale = _helperMethods.getScale;
VictoryPolarAxis.getStyles = (0, _partialRight3.default)(_helperMethods.getStyles, fallbackProps.style);
VictoryPolarAxis.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryPolarAxis.expectedComponents = ["axisComponent", "circularAxisComponent", "groupComponent", "containerComponent", "tickComponent", "tickLabelComponent", "gridComponent", "circularGridComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryPolarAxis, options);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBaseProps = undefined;

@@ -37,97 +38,98 @@ var _isNaN2 = require("lodash/isNaN");

exports.default = {
getBaseProps: function (props, fallbackProps) {
var _this = this;
var getVoronoi = function (props, range, scale) {
var minRange = [Math.min.apply(Math, _toConsumableArray(range.x)), Math.min.apply(Math, _toConsumableArray(range.y))];
var maxRange = [Math.max.apply(Math, _toConsumableArray(range.x)), Math.max.apply(Math, _toConsumableArray(range.y))];
var angleAccessor = function (d) {
var x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
return -1 * x + Math.PI / 2;
};
var xAccessor = function (d) {
return scale.x(d._x1 !== undefined ? d._x1 : d._x);
};
return (0, _d3Voronoi.voronoi)().x(function (d) {
return props.polar ? angleAccessor(d) : xAccessor(d);
}).y(function (d) {
return scale.y(d._y1 !== undefined ? d._y1 : d._y);
}).extent([minRange, maxRange]);
};
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "scatter");
props = (0, _assign3.default)({}, modifiedProps, this.getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
polygons = _props.polygons,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var getDataStyles = function (datum, style) {
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "y", "_x", "_y", "eventKey", "label"];
var stylesFromData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return (0, _defaults3.default)({}, stylesFromData, style);
};
var initialChildProps = { parent: {
style: style.parent, scale: scale, domain: domain, data: data, standalone: standalone, height: height, width: width, theme: theme,
origin: origin, polar: polar, padding: padding
} };
var getCalculatedValues = function (props) {
var defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ? props.theme.voronoi.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
var data = _victoryCore.Data.getData(props);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
var domain = {
x: _victoryCore.Domain.getDomain(props, "x"),
y: _victoryCore.Domain.getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var voronoi = getVoronoi(props, range, scale);
var polygons = voronoi.polygons(data);
var origin = props.polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, polygons: polygons, origin: origin };
};
return data.reduce(function (childProps, datum, index) {
var polygon = (0, _without3.default)(polygons[index], "data");
var eventKey = datum.eventKey;
var getBaseProps = function (props, fallbackProps) {
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, "scatter");
props = (0, _assign3.default)({}, modifiedProps, getCalculatedValues(modifiedProps));
var _props = props,
data = _props.data,
domain = _props.domain,
events = _props.events,
height = _props.height,
origin = _props.origin,
padding = _props.padding,
polar = _props.polar,
polygons = _props.polygons,
scale = _props.scale,
sharedEvents = _props.sharedEvents,
standalone = _props.standalone,
style = _props.style,
theme = _props.theme,
width = _props.width;
var _Helpers$scalePoint = _victoryCore.Helpers.scalePoint(props, datum),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
var initialChildProps = { parent: {
style: style.parent, scale: scale, domain: domain, data: data, standalone: standalone, height: height, width: width, theme: theme,
origin: origin, polar: polar, padding: padding
} };
var dataProps = {
x: x, y: y, datum: datum, data: data, index: index, scale: scale, polygon: polygon, origin: origin,
size: props.size,
style: _this.getDataStyles(datum, style.data)
};
return data.reduce(function (childProps, datum, index) {
var polygon = (0, _without3.default)(polygons[index], "data");
var eventKey = datum.eventKey;
childProps[eventKey] = { data: dataProps };
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index);
}
var _Helpers$scalePoint = _victoryCore.Helpers.scalePoint(props, datum),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
return childProps;
}, initialChildProps);
},
getCalculatedValues: function (props) {
var defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ? props.theme.voronoi.style : {};
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
var data = _victoryCore.Data.getData(props);
var range = {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
var dataProps = {
x: x, y: y, datum: datum, data: data, index: index, scale: scale, polygon: polygon, origin: origin,
size: props.size,
style: getDataStyles(datum, style.data)
};
var domain = {
x: _victoryCore.Domain.getDomain(props, "x"),
y: _victoryCore.Domain.getDomain(props, "y")
};
var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
var voronoi = this.getVoronoi(props, range, scale);
var polygons = voronoi.polygons(data);
var origin = props.polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
return { domain: domain, data: data, scale: scale, style: style, polygons: polygons, origin: origin };
},
getVoronoi: function (props, range, scale) {
var minRange = [Math.min.apply(Math, _toConsumableArray(range.x)), Math.min.apply(Math, _toConsumableArray(range.y))];
var maxRange = [Math.max.apply(Math, _toConsumableArray(range.x)), Math.max.apply(Math, _toConsumableArray(range.y))];
var angleAccessor = function (d) {
var x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
return -1 * x + Math.PI / 2;
};
var xAccessor = function (d) {
return scale.x(d._x1 !== undefined ? d._x1 : d._x);
};
return (0, _d3Voronoi.voronoi)().x(function (d) {
return props.polar ? angleAccessor(d) : xAccessor(d);
}).y(function (d) {
return scale.y(d._y1 !== undefined ? d._y1 : d._y);
}).extent([minRange, maxRange]);
},
getDataStyles: function (datum, style) {
var numKeys = (0, _keys3.default)(datum).filter(function (k) {
return (0, _isNaN3.default)(k);
});
var omitKeys = ["x", "y", "_x", "_y", "eventKey", "label"];
var stylesFromData = (0, _omit3.default)(datum, [].concat(omitKeys, _toConsumableArray(numKeys)));
return (0, _defaults3.default)({}, stylesFromData, style);
}
};
childProps[eventKey] = { data: dataProps };
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
};
exports.getBaseProps = getBaseProps;

@@ -21,4 +21,2 @@ Object.defineProperty(exports, "__esModule", {

var _helperMethods2 = _interopRequireDefault(_helperMethods);
var _commonProps = require("../../helpers/common-props");

@@ -95,4 +93,4 @@

VictoryVoronoi.getData = _victoryCore.Data.getData.bind(_victoryCore.Data);
VictoryVoronoi.getBaseProps = (0, _partialRight3.default)(_helperMethods2.default.getBaseProps.bind(_helperMethods2.default), fallbackProps);
VictoryVoronoi.getBaseProps = (0, _partialRight3.default)(_helperMethods.getBaseProps, fallbackProps);
VictoryVoronoi.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
exports.default = (0, _victoryCore.addEvents)(VictoryVoronoi);

@@ -267,19 +267,27 @@ Object.defineProperty(exports, "__esModule", {

var xArr = (0, _sortBy3.default)(xKeys);
return datasets.map(function (dataset) {
var indexOffset = 0;
var isDate = dataset[0] && dataset[0]._x instanceof Date;
var filledInData = xArr.map(function (x, index) {
x = +x;
var datum = dataset[index - indexOffset];
var isDate = datum._x instanceof Date;
var x1 = isDate ? datum._x.getTime() : datum._x;
x = +x;
if (x1 === x) {
return datum;
if (datum) {
var x1 = isDate ? datum._x.getTime() : datum._x;
if (x1 === x) {
return datum;
} else {
indexOffset++;
var y = fillInMissingData ? 0 : null;
x = isDate ? new Date(x) : x;
return { x: x, y: y, _x: x, _y: y };
}
} else {
indexOffset++;
var y = fillInMissingData ? 0 : null;
var _y = fillInMissingData ? 0 : null;
x = isDate ? new Date(x) : x;
return { x: x, y: y, _x: x, _y: y };
return { x: x, y: _y, _x: x, _y: _y };
}
});
return filledInData;

@@ -286,0 +294,0 @@ });

@@ -59,2 +59,11 @@ Object.defineProperty(exports, "__esModule", {

var _victoryBoxplot = require("./components/victory-boxplot/victory-boxplot");
Object.defineProperty(exports, "VictoryBoxPlot", {
enumerable: true,
get: function () {
return _interopRequireDefault(_victoryBoxplot).default;
}
});
var _victoryScatter = require("./components/victory-scatter/victory-scatter");

@@ -61,0 +70,0 @@

{
"name": "victory-chart",
"version": "25.1.1",
"version": "25.2.0",
"description": "Chart Component for Victory",

@@ -34,4 +34,4 @@ "main": "lib/index.js",

"d3-voronoi": "^1.1.2",
"lodash": "^4.17.4",
"victory-core": "^21.0.4"
"lodash": "^4.17.5",
"victory-core": "^21.1.0"
},

@@ -38,0 +38,0 @@ "devDependencies": {

import { assign } from "lodash";
import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
export default {
const getDataWithBaseline = (props, scale) => {
let data = Data.getData(props);
getBaseProps(props, fallbackProps) {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "area");
props = assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
const {
data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = {
parent: {
style: style.parent, width, height, scale, data, domain,
standalone, theme, polar, origin, padding
},
all: {
data: { polar, origin, scale, data, interpolation, groupComponent, style: style.data }
}
};
return data.reduce((childProps, datum, index) => {
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
const eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
},
if (data.length < 2) {
data = [];
}
const defaultMin = Scale.getType(scale.y) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
const domainY = scale.y.domain();
const minY = Math.min(...domainY) > 0 ? Math.min(...domainY) : defaultMin;
getCalculatedValues(props) {
const { theme, polar } = props;
const defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
const data = this.getDataWithBaseline(props, scale);
return { style, data, scale, domain, origin };
},
return data.map((datum) => {
const _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
const _y0 = datum._y0 !== undefined ? datum._y0 : minY;
return assign({}, datum, { _y0, _y1 });
});
};
getDataWithBaseline(props, scale) {
let data = Data.getData(props);
const getCalculatedValues = (props) => {
const { theme, polar } = props;
const defaultStyles = theme && theme.area && theme.area.style ? theme.area.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
const data = getDataWithBaseline(props, scale);
return { style, data, scale, domain, origin };
};
if (data.length < 2) {
data = [];
const getBaseProps = (props, fallbackProps) => {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "area");
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = {
parent: {
style: style.parent, width, height, scale, data, domain,
standalone, theme, polar, origin, padding
},
all: {
data: { polar, origin, scale, data, interpolation, groupComponent, style: style.data }
}
const defaultMin = Scale.getType(scale.y) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
const domainY = scale.y.domain();
const minY = Math.min(...domainY) > 0 ? Math.min(...domainY) : defaultMin;
};
return data.reduce((childProps, datum, index) => {
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
const eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
};
return data.map((datum) => {
const _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
const _y0 = datum._y0 !== undefined ? datum._y0 : minY;
return assign({}, datum, { _y0, _y1 });
});
}
};
export { getBaseProps, getDataWithBaseline };
import { partialRight } from "lodash";
import PropTypes from "prop-types";
import React from "react";
import AreaHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import {

@@ -61,3 +61,3 @@ PropTypes as CustomPropTypes, Helpers, VictoryLabel, VictoryContainer,

static getData = Data.getData.bind(Data);
static getBaseProps = partialRight(AreaHelpers.getBaseProps.bind(AreaHelpers), fallbackProps);
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -64,0 +64,0 @@ "dataComponent", "labelComponent", "groupComponent", "containerComponent"

import { assign, defaults, keys, omit, isNaN } from "lodash";
import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
export default {
const getBarPosition = (props, datum) => {
const getDefaultMin = (axis) => {
const defaultMin = Scale.getType(props.scale[axis]) === "log" ?
1 / Number.MAX_SAFE_INTEGER : 0;
return datum[`_${axis}`] instanceof Date ? new Date(defaultMin) : defaultMin;
};
const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
const _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
return Helpers.scalePoint(props, assign({}, datum, { _y0, _x0 }));
};
getBarPosition(props, datum) {
const getDefaultMin = (axis) => {
const defaultMin = Scale.getType(props.scale[axis]) === "log" ?
1 / Number.MAX_SAFE_INTEGER : 0;
return datum[`_${axis}`] instanceof Date ? new Date(defaultMin) : defaultMin;
};
const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
const _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
return Helpers.scalePoint(props, assign({}, datum, { _y0, _x0 }));
},
const getBarStyle = (datum, baseStyle) => {
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "y", "y0", "_x", "_y", "_y0", "name", "label", "eventKey"
];
const styleData = omit(datum, [...omitKeys, ...numKeys]);
return defaults({}, styleData, baseStyle);
};
getBarStyle(datum, baseStyle) {
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "y", "y0", "_x", "_y", "_y0", "name", "label", "eventKey"
];
const styleData = omit(datum, [...omitKeys, ...numKeys]);
return defaults({}, styleData, baseStyle);
},
const getCalculatedValues = (props) => {
const { theme, horizontal, polar } = props;
const defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const data = Data.getData(props);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
};
const xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
const yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
const scale = {
x: horizontal ? yScale : xScale,
y: horizontal ? xScale : yScale
};
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { style, data, scale, domain, origin };
};
getCalculatedValues(props) {
const { theme, horizontal, polar } = props;
const defaultStyles = theme && theme.bar && theme.bar.style ? theme.bar.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const data = Data.getData(props);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
const getBaseProps = (props, fallbackProps) => {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "bar");
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
alignment, barRatio, cornerRadius, data, domain, events, height, horizontal, origin, padding,
polar, scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = { parent: {
domain, scale, width, height, data, standalone,
theme, polar, origin, padding, style: style.parent
} };
return data.reduce((childProps, datum, index) => {
const eventKey = datum.eventKey || index;
const { x, y, y0, x0 } = getBarPosition(props, datum);
const barStyle = getBarStyle(datum, style.data);
const dataProps = {
alignment, barRatio, cornerRadius, data, datum, horizontal, index, padding, polar, origin,
scale, style: barStyle, width, height, x, y, y0, x0
};
const domain = {
x: Domain.getDomainWithZero(props, "x"),
y: Domain.getDomainWithZero(props, "y")
childProps[eventKey] = {
data: dataProps
};
const xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
const yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
const scale = {
x: horizontal ? yScale : xScale,
y: horizontal ? xScale : yScale
};
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { style, data, scale, domain, origin };
},
getBaseProps(props, fallbackProps) {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "bar");
props = assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
const {
alignment, barRatio, cornerRadius, data, domain, events, height, horizontal, origin, padding,
polar, scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = { parent: {
domain, scale, width, height, data, standalone,
theme, polar, origin, padding, style: style.parent
} };
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
};
return data.reduce((childProps, datum, index) => {
const eventKey = datum.eventKey || index;
const { x, y, y0, x0 } = this.getBarPosition(props, datum);
const barStyle = this.getBarStyle(datum, style.data);
const dataProps = {
alignment, barRatio, cornerRadius, data, datum, horizontal, index, padding, polar, origin,
scale, style: barStyle, width, height, x, y, y0, x0
};
childProps[eventKey] = {
data: dataProps
};
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
}
};
export { getBaseProps };
import PropTypes from "prop-types";
import React from "react";
import BarHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import { partialRight } from "lodash";

@@ -71,3 +71,3 @@ import {

static getData = Data.getData.bind(Data);
static getBaseProps = partialRight(BarHelpers.getBaseProps.bind(BarHelpers), fallbackProps);
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -74,0 +74,0 @@ "dataComponent", "labelComponent", "groupComponent", "containerComponent"

import { assign, sortBy, keys, omit, defaults, isNaN } from "lodash";
import { Helpers, LabelHelpers, Scale, Domain, Data } from "victory-core";
export default {
getBaseProps(props, fallbackProps) { // eslint-disable-line max-statements
props = Helpers.modifyProps(props, fallbackProps, "candlestick");
const calculatedValues = this.getCalculatedValues(props);
const { data, style, scale, domain, origin } = calculatedValues;
const {
groupComponent, width, height, padding, standalone,
theme, polar, wickStrokeWidth
} = props;
const initialChildProps = { parent: {
domain, scale, width, height, data, standalone, theme, polar, origin,
style: style.parent, padding
} };
const sortData = (dataset, sortKey, sortOrder = "ascending") => {
if (!sortKey) {
return dataset;
}
return data.reduce((childProps, datum, index) => {
const eventKey = datum.eventKey || index;
const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
const high = scale.y(datum._high);
const close = scale.y(datum._close);
const open = scale.y(datum._open);
const low = scale.y(datum._low);
const candleHeight = Math.abs(scale.y(datum._open) - scale.y(datum._close));
const dataStyle = this.getDataStyles(datum, style.data, props);
const dataProps = {
x, high, low, candleHeight, scale, data, datum, groupComponent, index,
style: dataStyle, padding, width, polar, origin, wickStrokeWidth, open, close
};
if (sortKey === "x" || sortKey === "y") {
sortKey = `_${sortKey}`;
}
childProps[eventKey] = {
data: dataProps
};
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = this.getLabelProps(dataProps, text, style);
}
const sortedData = sortBy(dataset, sortKey);
return childProps;
}, initialChildProps);
},
if (sortOrder === "descending") {
return sortedData.reverse();
}
getLabelProps(dataProps, text, style) {
const { x, high, index, scale, datum, data } = dataProps;
const labelStyle = style.labels || {};
return {
style: labelStyle,
y: high - (labelStyle.padding || 0),
x,
text,
index,
scale,
datum,
data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
},
return sortedData;
};
getCalculatedValues(props) {
const { theme, polar } = props;
const defaultStyle = theme && theme.candlestick && theme.candlestick.style ?
theme.candlestick.style : {};
const style = Helpers.getStyles(props.style, defaultStyle);
const data = Data.addEventKeys(props, this.getData(props));
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: this.getDomain(props, "x"),
y: this.getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain, data, scale, style, origin };
},
const getData = (props) => {
if (!props.data || Data.getLength(props.data) < 1) {
return [];
}
const stringMap = {
x: Data.createStringMap(props, "x")
};
getData(props) {
if (!props.data || Data.getLength(props.data) < 1) {
return [];
}
const stringMap = {
x: Data.createStringMap(props, "x")
};
const accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
open: Helpers.createAccessor(props.open !== undefined ? props.open : "open"),
close: Helpers.createAccessor(props.close !== undefined ? props.close : "close"),
high: Helpers.createAccessor(props.high !== undefined ? props.high : "high"),
low: Helpers.createAccessor(props.low !== undefined ? props.low : "low")
};
const accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
open: Helpers.createAccessor(props.open !== undefined ? props.open : "open"),
close: Helpers.createAccessor(props.close !== undefined ? props.close : "close"),
high: Helpers.createAccessor(props.high !== undefined ? props.high : "high"),
low: Helpers.createAccessor(props.low !== undefined ? props.low : "low")
};
const formattedData = props.data.reduce((dataArr, datum, index) => {
datum = Data.parseDatum(datum);
const formattedData = props.data.reduce((dataArr, datum, index) => {
datum = Data.parseDatum(datum);
const evaluatedX = accessor.x(datum);
const _x = evaluatedX !== undefined ? evaluatedX : index;
const _open = accessor.open(datum);
const _close = accessor.close(datum);
const _high = accessor.high(datum);
const _low = accessor.low(datum);
const _y = [_open, _close, _high, _low];
const evaluatedX = accessor.x(datum);
const _x = evaluatedX !== undefined ? evaluatedX : index;
const _open = accessor.open(datum);
const _close = accessor.close(datum);
const _high = accessor.high(datum);
const _low = accessor.low(datum);
const _y = [_open, _close, _high, _low];
dataArr.push(
assign(
{},
datum,
{ _x, _y, _open, _close, _high, _low },
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}
)
);
dataArr.push(
assign(
{},
datum,
{ _x, _y, _open, _close, _high, _low },
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {}
)
);
return dataArr;
}, []);
return dataArr;
}, []);
return sortData(formattedData, props.sortKey, props.sortOrder);
};
return this.sortData(formattedData, props.sortKey, props.sortOrder);
},
const getDomain = (props, axis) => {
let domain;
if (props.domain && props.domain[axis]) {
domain = props.domain[axis];
} else if (props.domain && Array.isArray(props.domain)) {
domain = props.domain;
} else {
const dataset = getData(props);
const allData = dataset.reduce((memo, datum) => {
return Array.isArray(datum[`_${axis}`]) ?
memo.concat(...datum[`_${axis}`]) : memo.concat(datum[`_${axis}`]);
},
[]);
sortData(dataset, sortKey, sortOrder = "ascending") {
if (!sortKey) {
return dataset;
if (allData.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
if (sortKey === "x" || sortKey === "y") {
sortKey = `_${sortKey}`;
const min = Math.min(...allData);
const max = Math.max(...allData);
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
domain = [min, max];
}
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
};
const sortedData = sortBy(dataset, sortKey);
const getCalculatedValues = (props) => {
const { theme, polar } = props;
const defaultStyle = theme && theme.candlestick && theme.candlestick.style ?
theme.candlestick.style : {};
const style = Helpers.getStyles(props.style, defaultStyle);
const data = Data.addEventKeys(props, getData(props));
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: getDomain(props, "x"),
y: getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain, data, scale, style, origin };
};
if (sortOrder === "descending") {
return sortedData.reverse();
}
return sortedData;
},
const isTransparent = (attr) => {
return attr === "none" || attr === "transparent";
};
getDomain(props, axis) {
let domain;
if (props.domain && props.domain[axis]) {
domain = props.domain[axis];
} else if (props.domain && Array.isArray(props.domain)) {
domain = props.domain;
} else {
const dataset = this.getData(props);
const allData = dataset.reduce((memo, datum) => {
return Array.isArray(datum[`_${axis}`]) ?
memo.concat(...datum[`_${axis}`]) : memo.concat(datum[`_${axis}`]);
},
[]);
const getDataStyles = (datum, style, props) => {
style = style || {};
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "_x", "_y", "_y0", "size", "name", "label", "open", "close", "high", "low", "eventKey"
];
const stylesFromData = omit(datum, [...omitKeys, ...numKeys]);
const candleColor = datum.open > datum.close ?
props.candleColors.negative : props.candleColors.positive;
const fill = datum.fill || style.fill || candleColor;
const strokeColor = datum.stroke || style.stroke;
const stroke = isTransparent(strokeColor) ? fill : strokeColor || "black";
return defaults({}, stylesFromData, { stroke, fill }, style);
};
if (allData.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
const getLabelProps = (dataProps, text, style) => {
const { x, high, index, scale, datum, data } = dataProps;
const labelStyle = style.labels || {};
return {
style: labelStyle,
y: high - (labelStyle.padding || 0),
x,
text,
index,
scale,
datum,
data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
};
const min = Math.min(...allData);
const max = Math.max(...allData);
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
domain = [min, max];
const getBaseProps = (props, fallbackProps) => { // eslint-disable-line max-statements
props = Helpers.modifyProps(props, fallbackProps, "candlestick");
const calculatedValues = getCalculatedValues(props);
const { data, style, scale, domain, origin } = calculatedValues;
const {
groupComponent, width, height, padding, standalone,
theme, polar, wickStrokeWidth
} = props;
const initialChildProps = { parent: {
domain, scale, width, height, data, standalone, theme, polar, origin,
style: style.parent, padding
} };
return data.reduce((childProps, datum, index) => {
const eventKey = datum.eventKey || index;
const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
const high = scale.y(datum._high);
const close = scale.y(datum._close);
const open = scale.y(datum._open);
const low = scale.y(datum._low);
const candleHeight = Math.abs(scale.y(datum._open) - scale.y(datum._close));
const dataStyle = getDataStyles(datum, style.data, props);
const dataProps = {
x, high, low, candleHeight, scale, data, datum, groupComponent, index,
style: dataStyle, padding, width, polar, origin, wickStrokeWidth, open, close
};
childProps[eventKey] = {
data: dataProps
};
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
},
isTransparent(attr) {
return attr === "none" || attr === "transparent";
},
return childProps;
}, initialChildProps);
};
getDataStyles(datum, style, props) {
style = style || {};
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "_x", "_y", "_y0", "size", "name", "label", "open", "close", "high", "low", "eventKey"
];
const stylesFromData = omit(datum, [...omitKeys, ...numKeys]);
const candleColor = datum.open > datum.close ?
props.candleColors.negative : props.candleColors.positive;
const fill = datum.fill || style.fill || candleColor;
const strokeColor = datum.stroke || style.stroke;
const stroke = this.isTransparent(strokeColor) ? fill : strokeColor || "black";
return defaults({}, stylesFromData, { stroke, fill }, style);
}
};
export { getBaseProps, getDomain, getData };

@@ -8,3 +8,3 @@ import PropTypes from "prop-types";

} from "victory-core";
import CandlestickHelpers from "./helper-methods";
import { getDomain, getData, getBaseProps } from "./helper-methods";
import { BaseProps, DataProps } from "../../helpers/common-props";

@@ -88,6 +88,5 @@

static getDomain = CandlestickHelpers.getDomain.bind(CandlestickHelpers);
static getData = CandlestickHelpers.getData.bind(CandlestickHelpers);
static getBaseProps = partialRight(
CandlestickHelpers.getBaseProps.bind(CandlestickHelpers), fallbackProps);
static getDomain = getDomain;
static getData = getData;
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -94,0 +93,0 @@ "dataComponent", "labelComponent", "groupComponent", "containerComponent"

@@ -6,111 +6,116 @@ import Axis from "../../helpers/axis";

const getDataComponents = (childComponents) => {
const findDataComponents = (children) => {
return children.reduce((memo, child) => {
if (child.type && child.type.role === "axis") {
return memo;
} else if (child.props && child.props.children) {
return memo.concat(findDataComponents(React.Children.toArray(child.props.children)));
}
return memo.concat(child);
}, []);
};
export default {
getChildComponents(props, defaultAxes) {
const childComponents = React.Children.toArray(props.children);
if (childComponents.length === 0) {
return [defaultAxes.independent, defaultAxes.dependent];
}
return findDataComponents(childComponents);
};
const axisComponents = {
dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"),
independent: Axis.getAxisComponentsWithParent(childComponents, "independent")
};
const getChildComponents = (props, defaultAxes) => {
const childComponents = React.Children.toArray(props.children);
if (childComponents.length === 0) {
return [defaultAxes.independent, defaultAxes.dependent];
}
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
if (axisComponents.independent.length > 1) {
const msg = "Only one independent VictoryAxis component is allowed when " +
"using the VictoryChart wrapper. Only the first axis will be used. Please compose " +
"multi-axis charts manually";
Log.warn(msg);
const dataComponents = this.getDataComponents(childComponents);
return Collection.removeUndefined(
dataComponents.concat([...axisComponents.dependent, axisComponents.independent[0]])
);
}
return childComponents;
},
const axisComponents = {
dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"),
independent: Axis.getAxisComponentsWithParent(childComponents, "independent")
};
getDefaultDomainPadding(childComponents, horizontal) {
const groupComponent = childComponents.filter((child) => {
return child.type && child.type.role && child.type.role === "group-wrapper";
});
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) {
return childComponents.concat([defaultAxes.independent, defaultAxes.dependent]);
}
if (axisComponents.independent.length > 1) {
const msg = "Only one independent VictoryAxis component is allowed when " +
"using the VictoryChart wrapper. Only the first axis will be used. Please compose " +
"multi-axis charts manually";
Log.warn(msg);
const dataComponents = getDataComponents(childComponents);
return Collection.removeUndefined(
dataComponents.concat([...axisComponents.dependent, axisComponents.independent[0]])
);
}
return childComponents;
};
if (groupComponent.length < 1) {
return undefined;
}
const getDefaultDomainPadding = (childComponents, horizontal) => {
const groupComponent = childComponents.filter((child) => {
return child.type && child.type.role && child.type.role === "group-wrapper";
});
const { offset, children } = groupComponent[0].props;
return horizontal ?
{ y: (offset * children.length) / 2 } :
{ x: (offset * children.length) / 2 };
},
if (groupComponent.length < 1) {
return undefined;
}
getDataComponents(childComponents) {
const findDataComponents = (children) => {
return children.reduce((memo, child) => {
if (child.type && child.type.role === "axis") {
return memo;
} else if (child.props && child.props.children) {
return memo.concat(findDataComponents(React.Children.toArray(child.props.children)));
}
return memo.concat(child);
}, []);
};
const { offset, children } = groupComponent[0].props;
return horizontal ?
{ y: (offset * children.length) / 2 } :
{ x: (offset * children.length) / 2 };
};
return findDataComponents(childComponents);
},
const getDomain = (props, axis, childComponents) => {
childComponents = childComponents || React.Children.toArray(props.children);
const domain = Wrapper.getDomain(props, axis, childComponents);
const axisComponent = Axis.getAxisComponent(childComponents, axis);
const invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis;
return invertDomain ? domain.concat().reverse() : domain;
};
getDomain(props, axis, childComponents) {
childComponents = childComponents || React.Children.toArray(props.children);
const domain = Wrapper.getDomain(props, axis, childComponents);
const axisComponent = Axis.getAxisComponent(childComponents, axis);
const invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis;
return invertDomain ? domain.concat().reverse() : domain;
},
// eslint-disable-next-line complexity
const getAxisOffset = (props, calculatedProps) => {
const { axisComponents, scale, origin, domain, originSign, padding } = calculatedProps;
const { top, bottom, left, right } = padding;
// make the axes line up, and cross when appropriate
const axisOrientations = {
x: Axis.getOrientation(axisComponents.x, "x", originSign.y),
y: Axis.getOrientation(axisComponents.y, "y", originSign.x)
};
const orientationOffset = {
y: axisOrientations.x === "bottom" ? bottom : top,
x: axisOrientations.y === "left" ? left : right
};
const originOffset = {
x: axisOrientations.y === "left" ? 0 : props.width,
y: axisOrientations.x === "bottom" ? props.height : 0
};
const originPosition = {
x: origin.x === domain.x[0] || origin.x === domain.x[1] ? 0 : scale.x(origin.x),
y: origin.y === domain.y[0] || origin.y === domain.y[1] ? 0 : scale.y(origin.y)
};
const calculatedOffset = {
x: originPosition.x ? Math.abs(originOffset.x - originPosition.x) : orientationOffset.x,
y: originPosition.y ? Math.abs(originOffset.y - originPosition.y) : orientationOffset.y
};
// eslint-disable-next-line complexity
getAxisOffset(props, calculatedProps) {
const { axisComponents, scale, origin, domain, originSign, padding } = calculatedProps;
const { top, bottom, left, right } = padding;
// make the axes line up, and cross when appropriate
const axisOrientations = {
x: Axis.getOrientation(axisComponents.x, "x", originSign.y),
y: Axis.getOrientation(axisComponents.y, "y", originSign.x)
};
const orientationOffset = {
y: axisOrientations.x === "bottom" ? bottom : top,
x: axisOrientations.y === "left" ? left : right
};
const originOffset = {
x: axisOrientations.y === "left" ? 0 : props.width,
y: axisOrientations.x === "bottom" ? props.height : 0
};
const originPosition = {
x: origin.x === domain.x[0] || origin.x === domain.x[1] ? 0 : scale.x(origin.x),
y: origin.y === domain.y[0] || origin.y === domain.y[1] ? 0 : scale.y(origin.y)
};
const calculatedOffset = {
x: originPosition.x ? Math.abs(originOffset.x - originPosition.x) : orientationOffset.x,
y: originPosition.y ? Math.abs(originOffset.y - originPosition.y) : orientationOffset.y
};
return {
x: axisComponents.x && axisComponents.x.offsetX !== undefined ?
axisComponents.x.offsetX : calculatedOffset.x,
y: axisComponents.y && axisComponents.y.offsetY !== undefined ?
axisComponents.y.offsetY : calculatedOffset.y
};
};
return {
x: axisComponents.x && axisComponents.x.offsetX !== undefined ?
axisComponents.x.offsetX : calculatedOffset.x,
y: axisComponents.y && axisComponents.y.offsetY !== undefined ?
axisComponents.y.offsetY : calculatedOffset.y
};
},
const createStringMap = (props, axis, childComponents) => {
const allStrings = Wrapper.getStringsFromChildren(props, axis, childComponents);
return allStrings.length === 0 ? null :
allStrings.reduce((memo, string, index) => {
memo[string] = index + 1;
return memo;
}, {});
};
createStringMap(props, axis, childComponents) {
const allStrings = Wrapper.getStringsFromChildren(props, axis, childComponents);
return allStrings.length === 0 ? null :
allStrings.reduce((memo, string, index) => {
memo[string] = index + 1;
return memo;
}, {});
}
export { getDomain,
getAxisOffset,
getDataComponents,
getChildComponents,
getDefaultDomainPadding,
createStringMap
};

@@ -9,3 +9,5 @@ import { defaults } from "lodash";

import VictoryPolarAxis from "../victory-polar-axis/victory-polar-axis";
import ChartHelpers from "./helper-methods";
import {
getDomain, getAxisOffset, getChildComponents, getDefaultDomainPadding, createStringMap
} from "./helper-methods";
import Axis from "../../helpers/axis";

@@ -107,3 +109,3 @@ import Wrapper from "../../helpers/wrapper";

const otherAxis = axis === "x" ? "y" : "x";
const axisOffset = ChartHelpers.getAxisOffset(props, calculatedProps);
const axisOffset = getAxisOffset(props, calculatedProps);
const offsetY = axis === "y" ? undefined : axisOffset.y;

@@ -147,4 +149,4 @@ const offsetX = axis === "x" ? undefined : axisOffset.x;

const domain = {
x: ChartHelpers.getDomain(props, "x", childComponents),
y: ChartHelpers.getDomain(props, "y", childComponents)
x: getDomain(props, "x", childComponents),
y: getDomain(props, "y", childComponents)
};

@@ -182,7 +184,7 @@ const range = {

const stringMap = {
x: ChartHelpers.createStringMap(props, "x", childComponents),
y: ChartHelpers.createStringMap(props, "y", childComponents)
x: createStringMap(props, "x", childComponents),
y: createStringMap(props, "y", childComponents)
};
const defaultDomainPadding = ChartHelpers.getDefaultDomainPadding(childComponents, horizontal);
const defaultDomainPadding = getDefaultDomainPadding(childComponents, horizontal);

@@ -242,3 +244,3 @@ const padding = Helpers.getPadding(props);

const axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes;
const childComponents = ChartHelpers.getChildComponents(modifiedProps, axes);
const childComponents = getChildComponents(modifiedProps, axes);
const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);

@@ -245,0 +247,0 @@ const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);

import { assign, keys, omit, defaults, isArray, flatten, sortBy, isNaN } from "lodash";
import { Helpers, LabelHelpers, Scale, Domain, Data } from "victory-core";
export default {
getBaseProps(props, fallbackProps) {
props = Helpers.modifyProps(props, fallbackProps, "errorbar");
const { data, style, scale, domain, origin } = this.getCalculatedValues(props, fallbackProps);
const { groupComponent, height, width, borderWidth, standalone, theme, polar, padding } = props;
const initialChildProps = { parent: {
domain, scale, data, height, width, standalone, theme, polar, origin,
padding, style: style.parent
} };
const getErrors = (datum, scale, axis) => {
/**
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
* and the first value is the positive error, the second is the negative error
* @param {Boolean} isArray(errorX)
* @return {String or Array}
*/
return data.reduce((childProps, datum, index) => {
const eventKey = datum.eventKey || index;
const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
const y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
const errorNames = { x: "errorX", y: "errorY" };
const errors = datum[errorNames[axis]];
if (errors === 0) {
return false;
}
const dataProps = {
x, y, scale, datum, data, index, groupComponent, borderWidth,
style: this.getDataStyles(datum, style.data),
errorX: this.getErrors(datum, scale, "x"),
errorY: this.getErrors(datum, scale, "y")
};
return isArray(errors) ?
[ errors[0] === 0 ? false : scale[axis](errors[0] + datum[`_${axis}`]),
errors[1] === 0 ? false : scale[axis](datum[`_${axis}`] - errors[1]) ] :
[ scale[axis](errors + datum[`_${axis}`]), scale[axis](datum[`_${axis}`] - errors) ];
};
childProps[eventKey] = {
data: dataProps
};
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = this.getLabelProps(dataProps, text, style);
}
const sortData = (dataset, sortKey, sortOrder = "ascending") => {
if (!sortKey) {
return dataset;
}
return childProps;
}, initialChildProps);
},
if (sortKey === "x" || sortKey === "y") {
sortKey = `_${sortKey}`;
}
getLabelProps(dataProps, text, style) {
const { x, index, scale, errorY } = dataProps;
const error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
const y = error || dataProps.y;
const labelStyle = style.labels || {};
return {
style: labelStyle,
y: y - (labelStyle.padding || 0),
x,
text,
index,
scale,
datum: dataProps.datum,
data: dataProps.data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
},
const sortedData = sortBy(dataset, sortKey);
getErrorData(props) {
if (props.data) {
if (Data.getLength(props.data) < 1) {
return [];
}
if (sortOrder === "descending") {
return sortedData.reverse();
}
return this.formatErrorData(props.data, props);
} else {
const generatedData = (props.errorX || props.errorY) && this.generateData(props);
return this.formatErrorData(generatedData, props);
}
},
return sortedData;
};
getErrors(datum, scale, axis) {
/**
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
* and the first value is the positive error, the second is the negative error
* @param {Boolean} isArray(errorX)
* @return {String or Array}
*/
const formatErrorData = (dataset, props) => {
if (!dataset || Data.getLength(dataset) < 1) {
return [];
}
const accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
errorX: Helpers.createAccessor(props.errorX !== undefined ? props.errorX : "errorX"),
errorY: Helpers.createAccessor(props.errorY !== undefined ? props.errorY : "errorY")
};
const errorNames = { x: "errorX", y: "errorY" };
const errors = datum[errorNames[axis]];
if (errors === 0) {
return false;
}
const replaceNegatives = (errors) => {
// check if the value is negative, if it is set to 0
const replaceNeg = (val) => !val || val < 0 ? 0 : val;
return isArray(errors) ? errors.map((err) => replaceNeg(err)) : replaceNeg(errors);
};
return isArray(errors) ?
[ errors[0] === 0 ? false : scale[axis](errors[0] + datum[`_${axis}`]),
errors[1] === 0 ? false : scale[axis](datum[`_${axis}`] - errors[1]) ] :
[ scale[axis](errors + datum[`_${axis}`]), scale[axis](datum[`_${axis}`] - errors) ];
},
const stringMap = {
x: Data.createStringMap(props, "x"),
y: Data.createStringMap(props, "y")
};
formatErrorData(dataset, props) {
if (!dataset || Data.getLength(dataset) < 1) {
return [];
}
const accessor = {
x: Helpers.createAccessor(props.x !== undefined ? props.x : "x"),
y: Helpers.createAccessor(props.y !== undefined ? props.y : "y"),
errorX: Helpers.createAccessor(props.errorX !== undefined ? props.errorX : "errorX"),
errorY: Helpers.createAccessor(props.errorY !== undefined ? props.errorY : "errorY")
};
const formattedData = dataset.reduce((dataArr, datum, index) => {
datum = Data.parseDatum(datum);
const replaceNegatives = (errors) => {
// check if the value is negative, if it is set to 0
const replaceNeg = (val) => !val || val < 0 ? 0 : val;
return isArray(errors) ? errors.map((err) => replaceNeg(err)) : replaceNeg(errors);
};
const evaluatedX = accessor.x(datum);
const evaluatedY = accessor.y(datum);
const _x = evaluatedX !== undefined ? evaluatedX : index;
const _y = evaluatedY !== undefined ? evaluatedY : datum;
const errorX = replaceNegatives(accessor.errorX(datum));
const errorY = replaceNegatives(accessor.errorY(datum));
const stringMap = {
x: Data.createStringMap(props, "x"),
y: Data.createStringMap(props, "y")
};
dataArr.push(
assign(
{},
datum,
{ _x, _y, errorX, errorY },
// map string data to numeric values, and add names
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {},
typeof _y === "string" ? { _y: stringMap.y[_y], y: _y } : {}
)
);
const formattedData = dataset.reduce((dataArr, datum, index) => {
datum = Data.parseDatum(datum);
return dataArr;
}, []);
const evaluatedX = accessor.x(datum);
const evaluatedY = accessor.y(datum);
const _x = evaluatedX !== undefined ? evaluatedX : index;
const _y = evaluatedY !== undefined ? evaluatedY : datum;
const errorX = replaceNegatives(accessor.errorX(datum));
const errorY = replaceNegatives(accessor.errorY(datum));
return sortData(formattedData, props.sortKey, props.sortOrder);
};
dataArr.push(
assign(
{},
datum,
{ _x, _y, errorX, errorY },
// map string data to numeric values, and add names
typeof _x === "string" ? { _x: stringMap.x[_x], x: _x } : {},
typeof _y === "string" ? { _y: stringMap.y[_y], y: _y } : {}
)
);
const getErrorData = (props) => {
if (props.data) {
if (Data.getLength(props.data) < 1) {
return [];
}
return dataArr;
}, []);
return formatErrorData(props.data, props);
} else {
const generatedData = (props.errorX || props.errorY) && Data.generateData(props);
return formatErrorData(generatedData, props);
}
};
return this.sortData(formattedData, props.sortKey, props.sortOrder);
},
sortData(dataset, sortKey, sortOrder = "ascending") {
if (!sortKey) {
return dataset;
const getDomainFromData = (props, axis, dataset) => {
const currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
let error;
if (currentAxis === "x") {
error = "errorX";
} else if (currentAxis === "y") {
error = "errorY";
}
const axisData = flatten(dataset).map((datum) => datum[`_${currentAxis}`]);
const errorData = flatten(flatten(dataset).map((datum) => {
let errorMax;
let errorMin;
if (isArray(datum[error])) {
errorMax = datum[error][0] + datum[`_${currentAxis}`];
errorMin = datum[`_${currentAxis}`] - datum[error][1];
} else {
errorMax = datum[error] + datum[`_${currentAxis}`];
errorMin = datum[`_${currentAxis}`] - datum[error];
}
return [errorMax, errorMin];
}));
if (sortKey === "x" || sortKey === "y") {
sortKey = `_${sortKey}`;
}
const allData = axisData.concat(errorData);
const min = Math.min(...allData);
const max = Math.max(...allData);
// TODO: is the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
return [min, max];
};
const sortedData = sortBy(dataset, sortKey);
const getDomain = (props, axis) => {
const propsDomain = Domain.getDomainFromProps(props, axis);
if (propsDomain) {
return Domain.padDomain(propsDomain, props, axis);
}
const categoryDomain = Domain.getDomainFromCategories(props, axis);
if (categoryDomain) {
return Domain.padDomain(categoryDomain, props, axis);
}
const dataset = getErrorData(props);
if (sortOrder === "descending") {
return sortedData.reverse();
}
if (dataset.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
return sortedData;
},
const domain = getDomainFromData(props, axis, dataset);
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
};
getDomain(props, axis) {
const propsDomain = Domain.getDomainFromProps(props, axis);
if (propsDomain) {
return Domain.padDomain(propsDomain, props, axis);
}
const categoryDomain = Domain.getDomainFromCategories(props, axis);
if (categoryDomain) {
return Domain.padDomain(categoryDomain, props, axis);
}
const dataset = this.getErrorData(props);
if (dataset.length < 1) {
return Scale.getBaseScale(props, axis).domain();
}
const getCalculatedValues = (props) => {
const defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ?
props.theme.errorbar.style : {};
const style = Helpers.getStyles(props.style, defaultStyles) || {};
const dataWithErrors = assign(Data.getData(props), getErrorData(props));
const data = Data.addEventKeys(props, dataWithErrors);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: getDomain(props, "x"),
y: getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain, data, scale, style, origin };
};
const domain = this.getDomainFromData(props, axis, dataset);
return Domain.cleanDomain(Domain.padDomain(domain, props, axis), props);
},
const getLabelProps = (dataProps, text, style) => {
const { x, index, scale, errorY } = dataProps;
const error = errorY && Array.isArray(errorY) ? errorY[0] : errorY;
const y = error || dataProps.y;
const labelStyle = style.labels || {};
return {
style: labelStyle,
y: y - (labelStyle.padding || 0),
x,
text,
index,
scale,
datum: dataProps.datum,
data: dataProps.data,
textAnchor: labelStyle.textAnchor,
verticalAnchor: labelStyle.verticalAnchor || "end",
angle: labelStyle.angle
};
};
getDomainFromData(props, axis, dataset) {
const currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
let error;
if (currentAxis === "x") {
error = "errorX";
} else if (currentAxis === "y") {
error = "errorY";
}
const axisData = flatten(dataset).map((datum) => datum[`_${currentAxis}`]);
const errorData = flatten(flatten(dataset).map((datum) => {
let errorMax;
let errorMin;
if (isArray(datum[error])) {
errorMax = datum[error][0] + datum[`_${currentAxis}`];
errorMin = datum[`_${currentAxis}`] - datum[error][1];
} else {
errorMax = datum[error] + datum[`_${currentAxis}`];
errorMin = datum[`_${currentAxis}`] - datum[error];
}
return [errorMax, errorMin];
}));
const getDataStyles = (datum, style) => {
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "y", "_x", "_y", "name", "errorX", "errorY", "eventKey", "label"
];
const stylesFromData = omit(datum, [...omitKeys, ...numKeys]);
return defaults({}, stylesFromData, style);
};
const allData = axisData.concat(errorData);
const min = Math.min(...allData);
const max = Math.max(...allData);
// TODO: is this the correct behavior, or should we just error. How do we
// handle charts with just one data point?
if (+min === +max) {
return Domain.getSinglePointDomain(max);
}
return [min, max];
},
const getBaseProps = (props, fallbackProps) => {
props = Helpers.modifyProps(props, fallbackProps, "errorbar");
const { data, style, scale, domain, origin } = getCalculatedValues(props, fallbackProps);
const { groupComponent, height, width, borderWidth, standalone, theme, polar, padding } = props;
const initialChildProps = { parent: {
domain, scale, data, height, width, standalone, theme, polar, origin,
padding, style: style.parent
} };
getCalculatedValues(props) {
const defaultStyles = props.theme && props.theme.errorbar && props.theme.errorbar.style ?
props.theme.errorbar.style : {};
const style = Helpers.getStyles(props.style, defaultStyles) || {};
const dataWithErrors = assign(Data.getData(props), this.getErrorData(props));
const data = Data.addEventKeys(props, dataWithErrors);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
return data.reduce((childProps, datum, index) => {
const eventKey = datum.eventKey || index;
const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
const y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
const dataProps = {
x, y, scale, datum, data, index, groupComponent, borderWidth,
style: getDataStyles(datum, style.data),
errorX: getErrors(datum, scale, "x"),
errorY: getErrors(datum, scale, "y")
};
const domain = {
x: this.getDomain(props, "x"),
y: this.getDomain(props, "y")
childProps[eventKey] = {
data: dataProps
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain, data, scale, style, origin };
},
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || props.events || props.sharedEvents) {
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
}
getDataStyles(datum, style) {
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "y", "_x", "_y", "name", "errorX", "errorY", "eventKey", "label"
];
const stylesFromData = omit(datum, [...omitKeys, ...numKeys]);
return defaults({}, stylesFromData, style);
}
return childProps;
}, initialChildProps);
};
export { getBaseProps, getDomain };

@@ -8,3 +8,3 @@ import PropTypes from "prop-types";

import { partialRight } from "lodash";
import ErrorBarHelpers from "./helper-methods";
import { getBaseProps, getDomain } from "./helper-methods";
import { BaseProps, DataProps } from "../../helpers/common-props";

@@ -67,6 +67,5 @@

static getDomain = ErrorBarHelpers.getDomain.bind(ErrorBarHelpers);
static getDomain = getDomain;
static getData = Data.getData.bind(Data);
static getBaseProps = partialRight(
ErrorBarHelpers.getBaseProps.bind(ErrorBarHelpers), fallbackProps);
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -73,0 +72,0 @@ "dataComponent", "labelComponent", "groupComponent", "containerComponent"

import { assign } from "lodash";
import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
export default {
getBaseProps(props, fallbackProps) {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "line");
props = assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
const {
data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = {
parent: {
style: style.parent, scale, data, height, width, domain, standalone, polar, origin, padding
},
all: { data:
{ polar, origin, scale, data, interpolation, groupComponent, theme, style: style.data }
}
};
return data.reduce((childProps, datum, index) => {
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
const eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
},
const getCalculatedValues = (props) => {
let data = Data.getData(props);
getCalculatedValues(props) {
let data = Data.getData(props);
if (data.length < 2) {
data = [];
}
if (data.length < 2) {
data = [];
}
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
const defaultStyles = props.theme && props.theme.line && props.theme.line.style ?
props.theme.line.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
const defaultStyles = props.theme && props.theme.line && props.theme.line.style ?
props.theme.line.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
return { domain, data, scale, style, origin };
};
return { domain, data, scale, style, origin };
}
const getBaseProps = (props, fallbackProps) => {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "line");
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = {
parent: {
style: style.parent, scale, data, height, width, domain, standalone, polar, origin, padding
},
all: { data:
{ polar, origin, scale, data, interpolation, groupComponent, theme, style: style.data }
}
};
return data.reduce((childProps, datum, index) => {
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
const eventKey = datum.eventKey || index;
childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
}
return childProps;
}, initialChildProps);
};
export { getBaseProps };
import { partialRight } from "lodash";
import PropTypes from "prop-types";
import React from "react";
import LineHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import {

@@ -61,4 +61,3 @@ PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents, VictoryContainer, VictoryTheme,

static getData = Data.getData.bind(Data);
static getBaseProps = partialRight(LineHelpers.getBaseProps.bind(LineHelpers),
fallbackProps);
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -65,0 +64,0 @@ "dataComponent", "labelComponent", "groupComponent", "containerComponent"

@@ -5,330 +5,336 @@ import { assign, uniqBy, defaults, defaultsDeep, isFunction } from "lodash";

export default {
getCalculatedValues(props) {
const defaultStyles = this.getStyleObject(props);
const style = this.getStyles(props, defaultStyles);
const padding = Helpers.getPadding(props);
const axis = this.getAxis(props);
const axisType = this.getAxisType(props);
const stringTicks = Helpers.stringTicks(props) ? props.tickValues : undefined;
const domain = this.getDomain(props, axis);
const range = this.getRange(props, axis);
const scale = this.getScale(props);
const initialTicks = Axis.getTicks(props, scale);
const ticks = axisType === "angular" ? this.filterTicks(initialTicks, scale) : initialTicks;
const tickFormat = Axis.getTickFormat(props, scale);
const radius = this.getRadius(props);
return {
axis, style, padding, stringTicks, axisType, scale, ticks, tickFormat, domain, range, radius
};
},
// exposed for use by VictoryChart
const getAxis = (props, flipped) => {
const typicalAxis = props.dependentAxis ? "y" : "x";
const invertedAxis = typicalAxis === "x" ? "y" : "x";
return flipped ? invertedAxis : typicalAxis;
};
evaluateProp(prop, data, index) {
return isFunction(prop) ? prop(data, index) : prop;
},
const getPosition = (r, angle, axis) => {
return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle);
};
evaluateStyle(style, data, index) {
if (!style || !Object.keys(style).some((value) => isFunction(style[value]))) {
return style;
}
return Object.keys(style).reduce((prev, curr) => {
prev[curr] = this.evaluateProp(style[curr], data, index);
return prev;
}, {});
},
const getAxisType = (props) => {
const typicalType = props.dependentAxis ? "radial" : "angular";
const invertedType = typicalType === "angular" ? "radial" : "angular";
return props.horizontal ? invertedType : typicalType;
};
// exposed for use by VictoryChart
getDomain(props, axis) {
const inherentAxis = this.getAxis(props);
if (axis && axis !== inherentAxis) {
return undefined;
}
let domain;
if (Array.isArray(props.domain)) {
domain = props.domain;
} else if (props.domain && props.domain[inherentAxis]) {
domain = props.domain[inherentAxis];
} else if (Array.isArray(props.tickValues) && props.tickValues.length > 1) {
domain = this.getDomainFromTickValues(props, axis);
}
const paddedDomain = Domain.padDomain(domain, props, inherentAxis);
return domain ? Domain.cleanDomain(paddedDomain, props, inherentAxis) : undefined;
},
const filterTicks = (ticks, scale) => {
const compareTicks = (t) => scale(t) % (2 * Math.PI);
return uniqBy(ticks, compareTicks);
};
getDomainFromTickValues(props, axis) {
const { tickValues, startAngle = 0, endAngle = 360 } = props;
if (Helpers.stringTicks(props)) {
return [1, tickValues.length];
} else {
const ticks = tickValues.map((value) => +value);
const domain = [Collection.getMinValue(ticks), Collection.getMaxValue(ticks)];
return axis === "x" && Math.abs(startAngle - endAngle) === 360 ?
Domain.getSymmetricDomain(domain, ticks) : domain;
}
},
const evaluateProp = (prop, data, index) => {
return isFunction(prop) ? prop(data, index) : prop;
};
getRadius(props) {
const { left, right, top, bottom } = Helpers.getPadding(props);
const { width, height } = props;
return Math.min(width - left - right, height - top - bottom) / 2;
},
const evaluateStyle = (style, data, index) => {
if (!style || !Object.keys(style).some((value) => isFunction(style[value]))) {
return style;
}
return Object.keys(style).reduce((prev, curr) => {
prev[curr] = evaluateProp(style[curr], data, index);
return prev;
}, {});
};
getRange(props, axis) {
// Return the range from props if one is given.
if (props.range && props.range[axis]) {
return props.range[axis];
} else if (props.range && Array.isArray(props.range)) {
return props.range;
}
const axisType = this.getAxisType(props);
if (axisType === "angular") {
const startAngle = Helpers.degreesToRadians(props.startAngle);
const endAngle = Helpers.degreesToRadians(props.endAngle);
return [startAngle, endAngle];
}
const radius = this.getRadius(props);
return [props.innerRadius || 0, radius];
},
const getEvaluatedStyles = (style, tick, index) => {
return {
tickStyle: evaluateStyle(style.ticks, tick, index),
labelStyle: evaluateStyle(style.tickLabels, tick, index),
gridStyle: evaluateStyle(style.grid, tick, index)
};
};
// exposed for use by VictoryChart
getAxis(props, flipped) {
const typicalAxis = props.dependentAxis ? "y" : "x";
const invertedAxis = typicalAxis === "x" ? "y" : "x";
return flipped ? invertedAxis : typicalAxis;
},
const getDomainFromTickValues = (props, axis) => {
const { tickValues, startAngle = 0, endAngle = 360 } = props;
if (Helpers.stringTicks(props)) {
return [1, tickValues.length];
} else {
const ticks = tickValues.map((value) => +value);
const domain = [Collection.getMinValue(ticks), Collection.getMaxValue(ticks)];
return axis === "x" && Math.abs(startAngle - endAngle) === 360 ?
Domain.getSymmetricDomain(domain, ticks) : domain;
}
};
getAxisType(props) {
const typicalType = props.dependentAxis ? "radial" : "angular";
const invertedType = typicalType === "angular" ? "radial" : "angular";
return props.horizontal ? invertedType : typicalType;
},
// exposed for use by VictoryChart
const getDomain = (props, axis) => {
const inherentAxis = getAxis(props);
if (axis && axis !== inherentAxis) {
return undefined;
}
let domain;
if (Array.isArray(props.domain)) {
domain = props.domain;
} else if (props.domain && props.domain[inherentAxis]) {
domain = props.domain[inherentAxis];
} else if (Array.isArray(props.tickValues) && props.tickValues.length > 1) {
domain = getDomainFromTickValues(props, axis);
}
const paddedDomain = Domain.padDomain(domain, props, inherentAxis);
return domain ? Domain.cleanDomain(paddedDomain, props, inherentAxis) : undefined;
};
// exposed for use by VictoryChart (necessary?)
getScale(props) {
const axis = this.getAxis(props);
const scale = Scale.getBaseScale(props, axis);
const domain = this.getDomain(props, axis) || scale.domain();
const range = this.getRange(props, axis);
scale.range(range);
scale.domain(domain);
return scale;
},
const getStyleObject = (props) => {
const { theme, dependentAxis } = props;
const generalAxisStyle = theme && theme.axis && theme.axis.style;
const axisType = dependentAxis ? "dependentAxis" : "independentAxis";
const specificAxisStyle = theme && theme[axisType] && theme[axisType].style;
getStyleObject(props) {
const { theme, dependentAxis } = props;
const generalAxisStyle = theme && theme.axis && theme.axis.style;
const axisType = dependentAxis ? "dependentAxis" : "independentAxis";
const specificAxisStyle = theme && theme[axisType] && theme[axisType].style;
return generalAxisStyle && specificAxisStyle
? defaultsDeep({},
specificAxisStyle,
generalAxisStyle
)
: specificAxisStyle || generalAxisStyle;
};
return generalAxisStyle && specificAxisStyle
? defaultsDeep({},
specificAxisStyle,
generalAxisStyle
)
: specificAxisStyle || generalAxisStyle;
},
const getRadius = (props) => {
const { left, right, top, bottom } = Helpers.getPadding(props);
const { width, height } = props;
return Math.min(width - left - right, height - top - bottom) / 2;
};
getStyles(props, styleObject) {
const style = props.style || {};
styleObject = styleObject || {};
const parentStyleProps = { height: "auto", width: "100%" };
return {
parent: defaults(parentStyleProps, style.parent, styleObject.parent),
axis: defaults({}, style.axis, styleObject.axis),
axisLabel: defaults({}, style.axisLabel, styleObject.axisLabel),
grid: defaults({}, style.grid, styleObject.grid),
ticks: defaults({}, style.ticks, styleObject.ticks),
tickLabels: defaults({}, style.tickLabels, styleObject.tickLabels)
};
},
const getRange = (props, axis) => {
// Return the range from props if one is given.
if (props.range && props.range[axis]) {
return props.range[axis];
} else if (props.range && Array.isArray(props.range)) {
return props.range;
}
const axisType = getAxisType(props);
if (axisType === "angular") {
const startAngle = Helpers.degreesToRadians(props.startAngle);
const endAngle = Helpers.degreesToRadians(props.endAngle);
return [startAngle, endAngle];
}
const radius = getRadius(props);
return [props.innerRadius || 0, radius];
};
getAxisAngle(props) {
const { axisAngle, startAngle, axisValue, dependentAxis, scale } = props;
const otherAxis = this.getAxis(props) === "y" ? "x" : "y";
if (axisValue === undefined || !dependentAxis || scale[otherAxis] === undefined) {
return axisAngle || startAngle;
}
return Helpers.radiansToDegrees(scale.x(axisValue));
},
// exposed for use by VictoryChart (necessary?)
const getScale = (props) => {
const axis = getAxis(props);
const scale = Scale.getBaseScale(props, axis);
const domain = getDomain(props, axis) || scale.domain();
const range = getRange(props, axis);
scale.range(range);
scale.domain(domain);
return scale;
};
getTickProps(props, calculatedValues, tick, index) { //eslint-disable-line max-params
const { axisType, radius, scale, style, stringTicks } = calculatedValues;
const originalTick = stringTicks ? stringTicks[index] : tick;
const { tickStyle } = this.getEvaluatedStyles(style, originalTick, index);
const tickPadding = tickStyle.padding || 0;
const angularPadding = tickPadding; // TODO: do some geometry
const axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
return axisType === "angular" ?
{
index, datum: tick, style: tickStyle,
x1: radius * Math.cos(scale(tick)),
y1: -radius * Math.sin(scale(tick)),
x2: (radius + tickPadding) * Math.cos(scale(tick)),
y2: -(radius + tickPadding) * Math.sin(scale(tick))
} : {
style, index, datum: tick,
x1: (scale(tick) / 2) * Math.cos(axisAngle - angularPadding),
x2: (scale(tick) / 2) * Math.cos(axisAngle + angularPadding),
y1: -(scale(tick) / 2) * Math.sin(axisAngle - angularPadding),
y2: -(scale(tick) / 2) * Math.sin(axisAngle + angularPadding)
};
},
const getStyles = (props, styleObject) => {
const style = props.style || {};
styleObject = styleObject || {};
const parentStyleProps = { height: "auto", width: "100%" };
return {
parent: defaults(parentStyleProps, style.parent, styleObject.parent),
axis: defaults({}, style.axis, styleObject.axis),
axisLabel: defaults({}, style.axisLabel, styleObject.axisLabel),
grid: defaults({}, style.grid, styleObject.grid),
ticks: defaults({}, style.ticks, styleObject.ticks),
tickLabels: defaults({}, style.tickLabels, styleObject.tickLabels)
};
};
getTickLabelProps(props, calculatedValues, tick, index) { //eslint-disable-line max-params
const { axisType, radius, tickFormat, style, scale, ticks, stringTicks } = calculatedValues;
const originalTick = stringTicks ? stringTicks[index] : tick;
const { labelStyle } = this.getEvaluatedStyles(style, originalTick, index);
const { tickLabelComponent } = props;
const labelPlacement = tickLabelComponent.props && tickLabelComponent.props.labelPlacement ?
tickLabelComponent.props.labelPlacement : props.labelPlacement;
const tickPadding = labelStyle.padding || 0;
const angularPadding = 0; // TODO: do some geometry
const axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
const labelAngle = axisType === "angular" ?
Helpers.radiansToDegrees(scale(tick)) : axisAngle + angularPadding;
const textAngle = labelStyle.angle ||
LabelHelpers.getPolarAngle(assign({}, props, { labelPlacement }), labelAngle);
const labelRadius = axisType === "angular" ? radius + tickPadding : scale(tick);
const textAnchor = labelStyle.textAnchor ||
LabelHelpers.getPolarTextAnchor(assign({}, props, { labelPlacement }), labelAngle);
return {
index, datum: tick, style: labelStyle,
angle: textAngle,
textAnchor,
text: tickFormat(tick, index, ticks),
x: labelRadius * Math.cos(Helpers.degreesToRadians(labelAngle)),
y: -labelRadius * Math.sin(Helpers.degreesToRadians(labelAngle))
};
},
const getAxisAngle = (props) => {
const { axisAngle, startAngle, axisValue, dependentAxis, scale } = props;
const otherAxis = getAxis(props) === "y" ? "x" : "y";
if (axisValue === undefined || !dependentAxis || scale[otherAxis] === undefined) {
return axisAngle || startAngle;
}
return Helpers.radiansToDegrees(scale.x(axisValue));
};
getGridProps(props, calculatedValues, tick, index) { //eslint-disable-line max-params
const { axisType, radius, style, scale, stringTicks } = calculatedValues;
const { startAngle, endAngle, innerRadius = 0 } = props;
const originalTick = stringTicks ? stringTicks[index] : tick;
const { gridStyle } = this.getEvaluatedStyles(style, originalTick, index);
const angle = scale(tick);
return axisType === "angular" ?
{
index, datum: tick, style: gridStyle,
x1: this.getPosition(radius, angle, "x"),
y1: this.getPosition(radius, angle, "y"),
x2: this.getPosition(innerRadius, angle, "x"),
y2: this.getPosition(innerRadius, angle, "y")
} : {
style: gridStyle, index, datum: tick,
cx: 0, cy: 0, r: scale(tick), startAngle, endAngle
};
},
const getTickProps = (props, calculatedValues, tick, index) => { //eslint-disable-line max-params
const { axisType, radius, scale, style, stringTicks } = calculatedValues;
const originalTick = stringTicks ? stringTicks[index] : tick;
const { tickStyle } = getEvaluatedStyles(style, originalTick, index);
const tickPadding = tickStyle.padding || 0;
const angularPadding = tickPadding; // TODO: do some geometry
const axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
return axisType === "angular" ?
{
index, datum: tick, style: tickStyle,
x1: radius * Math.cos(scale(tick)),
y1: -radius * Math.sin(scale(tick)),
x2: (radius + tickPadding) * Math.cos(scale(tick)),
y2: -(radius + tickPadding) * Math.sin(scale(tick))
} : {
style, index, datum: tick,
x1: (scale(tick) / 2) * Math.cos(axisAngle - angularPadding),
x2: (scale(tick) / 2) * Math.cos(axisAngle + angularPadding),
y1: -(scale(tick) / 2) * Math.sin(axisAngle - angularPadding),
y2: -(scale(tick) / 2) * Math.sin(axisAngle + angularPadding)
};
};
getAxisLabelProps(props, calculatedValues) {
const { axisType, radius, style, scale } = calculatedValues;
const { axisLabelComponent } = props;
if (axisType !== "radial") {
return {};
}
const labelPlacement = axisLabelComponent.props && axisLabelComponent.props.labelPlacement ?
axisLabelComponent.props.labelPlacement : props.labelPlacement;
const labelStyle = style && style.axisLabel || {};
const axisAngle = axisType === "radial" ? this.getAxisAngle(props, scale) : undefined;
const textAngle = labelStyle.angle ||
LabelHelpers.getPolarAngle(assign({}, props, { labelPlacement }), axisAngle);
const labelRadius = radius + (labelStyle.padding || 0);
const textAnchor = labelStyle.textAnchor ||
LabelHelpers.getTextPolarAnchor(assign({}, props, { labelPlacement }), axisAngle);
const verticalAnchor = labelStyle.verticalAnchor ||
LabelHelpers.getPolarVerticalAnchor(assign({}, props, { labelPlacement }), axisAngle);
return {
style: labelStyle,
angle: textAngle,
textAnchor,
verticalAnchor,
text: props.label,
x: this.getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "x"),
y: this.getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "y")
};
},
//eslint-disable-next-line max-params
const getTickLabelProps = (props, calculatedValues, tick, index) => {
const { axisType, radius, tickFormat, style, scale, ticks, stringTicks } = calculatedValues;
const originalTick = stringTicks ? stringTicks[index] : tick;
const { labelStyle } = getEvaluatedStyles(style, originalTick, index);
const { tickLabelComponent } = props;
const labelPlacement = tickLabelComponent.props && tickLabelComponent.props.labelPlacement ?
tickLabelComponent.props.labelPlacement : props.labelPlacement;
const tickPadding = labelStyle.padding || 0;
const angularPadding = 0; // TODO: do some geometry
const axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
const labelAngle = axisType === "angular" ?
Helpers.radiansToDegrees(scale(tick)) : axisAngle + angularPadding;
const textAngle = labelStyle.angle ||
LabelHelpers.getPolarAngle(assign({}, props, { labelPlacement }), labelAngle);
const labelRadius = axisType === "angular" ? radius + tickPadding : scale(tick);
const textAnchor = labelStyle.textAnchor ||
LabelHelpers.getPolarTextAnchor(assign({}, props, { labelPlacement }), labelAngle);
return {
index, datum: tick, style: labelStyle,
angle: textAngle,
textAnchor,
text: tickFormat(tick, index, ticks),
x: labelRadius * Math.cos(Helpers.degreesToRadians(labelAngle)),
y: -labelRadius * Math.sin(Helpers.degreesToRadians(labelAngle))
};
};
getPosition(r, angle, axis) {
return axis === "x" ? r * Math.cos(angle) : -r * Math.sin(angle);
},
const getGridProps = (props, calculatedValues, tick, index) => { //eslint-disable-line max-params
const { axisType, radius, style, scale, stringTicks } = calculatedValues;
const { startAngle, endAngle, innerRadius = 0 } = props;
const originalTick = stringTicks ? stringTicks[index] : tick;
const { gridStyle } = getEvaluatedStyles(style, originalTick, index);
const angle = scale(tick);
return axisType === "angular" ?
{
index, datum: tick, style: gridStyle,
x1: getPosition(radius, angle, "x"),
y1: getPosition(radius, angle, "y"),
x2: getPosition(innerRadius, angle, "x"),
y2: getPosition(innerRadius, angle, "y")
} : {
style: gridStyle, index, datum: tick,
cx: 0, cy: 0, r: scale(tick), startAngle, endAngle
};
};
getAxisProps(modifiedProps, calculatedValues) {
const { style, axisType, radius, scale } = calculatedValues;
const { startAngle, endAngle, innerRadius = 0 } = modifiedProps;
const axisAngle = axisType === "radial" ?
Helpers.degreesToRadians(this.getAxisAngle(modifiedProps, scale)) : undefined;
return axisType === "radial" ?
{
style: style.axis,
x1: this.getPosition(innerRadius, axisAngle, "x"),
x2: this.getPosition(radius, axisAngle, "x"),
y1: this.getPosition(innerRadius, axisAngle, "y"),
y2: this.getPosition(radius, axisAngle, "y")
} : {
style: style.axis,
cx: 0, cy: 0, r: radius, startAngle, endAngle
};
},
const getAxisLabelProps = (props, calculatedValues) => {
const { axisType, radius, style, scale } = calculatedValues;
const { axisLabelComponent } = props;
if (axisType !== "radial") {
return {};
}
const labelPlacement = axisLabelComponent.props && axisLabelComponent.props.labelPlacement ?
axisLabelComponent.props.labelPlacement : props.labelPlacement;
const labelStyle = style && style.axisLabel || {};
const axisAngle = axisType === "radial" ? getAxisAngle(props, scale) : undefined;
const textAngle = labelStyle.angle ||
LabelHelpers.getPolarAngle(assign({}, props, { labelPlacement }), axisAngle);
const labelRadius = radius + (labelStyle.padding || 0);
const textAnchor = labelStyle.textAnchor ||
LabelHelpers.getTextPolarAnchor(assign({}, props, { labelPlacement }), axisAngle);
const verticalAnchor = labelStyle.verticalAnchor ||
LabelHelpers.getPolarVerticalAnchor(assign({}, props, { labelPlacement }), axisAngle);
return {
style: labelStyle,
angle: textAngle,
textAnchor,
verticalAnchor,
text: props.label,
x: getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "x"),
y: getPosition(labelRadius, Helpers.degreesToRadians(axisAngle), "y")
};
};
getEvaluatedStyles(style, tick, index) {
return {
tickStyle: this.evaluateStyle(style.ticks, tick, index),
labelStyle: this.evaluateStyle(style.tickLabels, tick, index),
gridStyle: this.evaluateStyle(style.grid, tick, index)
};
},
const getAxisProps = (modifiedProps, calculatedValues) => {
const { style, axisType, radius, scale } = calculatedValues;
const { startAngle, endAngle, innerRadius = 0 } = modifiedProps;
const axisAngle = axisType === "radial" ?
Helpers.degreesToRadians(getAxisAngle(modifiedProps, scale)) : undefined;
return axisType === "radial" ?
{
style: style.axis,
x1: getPosition(innerRadius, axisAngle, "x"),
x2: getPosition(radius, axisAngle, "x"),
y1: getPosition(innerRadius, axisAngle, "y"),
y2: getPosition(radius, axisAngle, "y")
} : {
style: style.axis,
cx: 0, cy: 0, r: radius, startAngle, endAngle
};
};
getRole(props) {
if (props.dependentAxis) {
return props.theme && props.theme.dependentAxis
? "dependentAxis"
: "axis";
}
return props.theme && props.theme.independentAxis
? "independentAxis"
const getRole = (props) => {
if (props.dependentAxis) {
return props.theme && props.theme.dependentAxis
? "dependentAxis"
: "axis";
},
}
getShallowMergedThemeProps(props, role) {
const axisTheme = props.theme.axis || {};
return defaults({}, props.theme[role], axisTheme);
},
return props.theme && props.theme.independentAxis
? "independentAxis"
: "axis";
};
modifyProps(props, fallbackProps, role) {
if (role !== "axis") {
props.theme[role] = this.getShallowMergedThemeProps(props, role);
}
return Helpers.modifyProps(props, fallbackProps, role);
},
const getShallowMergedThemeProps = (props, role) => {
const axisTheme = props.theme.axis || {};
return defaults({}, props.theme[role], axisTheme);
};
getBaseProps(props, fallbackProps) {
const role = this.getRole(props);
props = this.modifyProps(props, fallbackProps, role);
const calculatedValues = this.getCalculatedValues(props);
const { style, scale, ticks, domain } = calculatedValues;
const { width, height, standalone, theme } = props;
const axisProps = this.getAxisProps(props, calculatedValues);
const axisLabelProps = this.getAxisLabelProps(props, calculatedValues);
const initialChildProps = { parent:
{ style: style.parent, ticks, scale, width, height, domain, standalone, theme }
};
const modifyProps = (props, fallbackProps, role) => {
if (role !== "axis") {
props.theme[role] = getShallowMergedThemeProps(props, role);
}
return Helpers.modifyProps(props, fallbackProps, role);
};
return ticks.reduce((childProps, tick, index) => {
childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
ticks: this.getTickProps(props, calculatedValues, tick, index),
tickLabels: this.getTickLabelProps(props, calculatedValues, tick, index),
grid: this.getGridProps(props, calculatedValues, tick, index)
};
const getCalculatedValues = (props) => {
const defaultStyles = getStyleObject(props);
const style = getStyles(props, defaultStyles);
const padding = Helpers.getPadding(props);
const axis = getAxis(props);
const axisType = getAxisType(props);
const stringTicks = Helpers.stringTicks(props) ? props.tickValues : undefined;
const domain = getDomain(props, axis);
const range = getRange(props, axis);
const scale = getScale(props);
const initialTicks = Axis.getTicks(props, scale);
const ticks = axisType === "angular" ? filterTicks(initialTicks, scale) : initialTicks;
const tickFormat = Axis.getTickFormat(props, scale);
const radius = getRadius(props);
return {
axis, style, padding, stringTicks, axisType, scale, ticks, tickFormat, domain, range, radius
};
};
return childProps;
}, initialChildProps);
},
const getBaseProps = (props, fallbackProps) => {
const role = getRole(props);
props = modifyProps(props, fallbackProps, role);
const calculatedValues = getCalculatedValues(props);
const { style, scale, ticks, domain } = calculatedValues;
const { width, height, standalone, theme } = props;
const axisProps = getAxisProps(props, calculatedValues);
const axisLabelProps = getAxisLabelProps(props, calculatedValues);
const initialChildProps = { parent:
{ style: style.parent, ticks, scale, width, height, domain, standalone, theme }
};
filterTicks(ticks, scale) {
const compareTicks = (t) => scale(t) % (2 * Math.PI);
return uniqBy(ticks, compareTicks);
}
return ticks.reduce((childProps, tick, index) => {
childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
ticks: getTickProps(props, calculatedValues, tick, index),
tickLabels: getTickLabelProps(props, calculatedValues, tick, index),
grid: getGridProps(props, calculatedValues, tick, index)
};
return childProps;
}, initialChildProps);
};
export { getDomain,
getAxis,
getScale,
getStyles,
getBaseProps
};

@@ -8,3 +8,3 @@ import React from "react";

} from "victory-core";
import AxisHelpers from "./helper-methods";
import { getDomain, getAxis, getScale, getStyles, getBaseProps } from "./helper-methods";
import { BaseProps } from "../../helpers/common-props";

@@ -109,7 +109,7 @@

static getDomain = AxisHelpers.getDomain.bind(AxisHelpers);
static getAxis = AxisHelpers.getAxis.bind(AxisHelpers);
static getScale = AxisHelpers.getScale.bind(AxisHelpers);
static getStyles = partialRight(AxisHelpers.getStyles.bind(AxisHelpers), fallbackProps.style);
static getBaseProps = partialRight(AxisHelpers.getBaseProps.bind(AxisHelpers), fallbackProps);
static getDomain = getDomain;
static getAxis = getAxis;
static getScale = getScale;
static getStyles = partialRight(getStyles, fallbackProps.style);
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -116,0 +116,0 @@ "axisComponent", "circularAxisComponent", "groupComponent", "containerComponent",

@@ -5,80 +5,81 @@ import { assign, keys, omit, defaults, without, isNaN } from "lodash";

export default {
getBaseProps(props, fallbackProps) {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "scatter");
props = assign({}, modifiedProps, this.getCalculatedValues(modifiedProps));
const {
data, domain, events, height, origin, padding, polar, polygons,
scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = { parent: {
style: style.parent, scale, domain, data, standalone, height, width, theme,
origin, polar, padding
} };
const getVoronoi = (props, range, scale) => {
const minRange = [Math.min(...range.x), Math.min(...range.y)];
const maxRange = [Math.max(...range.x), Math.max(...range.y)];
const angleAccessor = (d) => {
const x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
return -1 * x + Math.PI / 2;
};
const xAccessor = (d) => scale.x(d._x1 !== undefined ? d._x1 : d._x);
return d3Voronoi()
.x((d) => props.polar ? angleAccessor(d) : xAccessor(d))
.y((d) => scale.y(d._y1 !== undefined ? d._y1 : d._y))
.extent([minRange, maxRange]);
};
return data.reduce((childProps, datum, index) => {
const polygon = without(polygons[index], "data");
const eventKey = datum.eventKey;
const { x, y } = Helpers.scalePoint(props, datum);
const dataProps = {
x, y, datum, data, index, scale, polygon, origin,
size: props.size,
style: this.getDataStyles(datum, style.data)
};
const getDataStyles = (datum, style) => {
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "y", "_x", "_y", "eventKey", "label"
];
const stylesFromData = omit(datum, [...omitKeys, ...numKeys]);
return defaults({}, stylesFromData, style);
};
childProps[eventKey] = { data: dataProps };
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
},
const getCalculatedValues = (props) => {
const defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ?
props.theme.voronoi.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const data = Data.getData(props);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const voronoi = getVoronoi(props, range, scale);
const polygons = voronoi.polygons(data);
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain, data, scale, style, polygons, origin };
};
getCalculatedValues(props) {
const defaultStyles = props.theme && props.theme.voronoi && props.theme.voronoi.style ?
props.theme.voronoi.style : {};
const style = Helpers.getStyles(props.style, defaultStyles);
const data = Data.getData(props);
const range = {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const domain = {
x: Domain.getDomain(props, "x"),
y: Domain.getDomain(props, "y")
};
const scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
};
const voronoi = this.getVoronoi(props, range, scale);
const polygons = voronoi.polygons(data);
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
return { domain, data, scale, style, polygons, origin };
},
const getBaseProps = (props, fallbackProps) => {
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "scatter");
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
const {
data, domain, events, height, origin, padding, polar, polygons,
scale, sharedEvents, standalone, style, theme, width
} = props;
const initialChildProps = { parent: {
style: style.parent, scale, domain, data, standalone, height, width, theme,
origin, polar, padding
} };
getVoronoi(props, range, scale) {
const minRange = [Math.min(...range.x), Math.min(...range.y)];
const maxRange = [Math.max(...range.x), Math.max(...range.y)];
const angleAccessor = (d) => {
const x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
return -1 * x + Math.PI / 2;
return data.reduce((childProps, datum, index) => {
const polygon = without(polygons[index], "data");
const eventKey = datum.eventKey;
const { x, y } = Helpers.scalePoint(props, datum);
const dataProps = {
x, y, datum, data, index, scale, polygon, origin,
size: props.size,
style: getDataStyles(datum, style.data)
};
const xAccessor = (d) => scale.x(d._x1 !== undefined ? d._x1 : d._x);
return d3Voronoi()
.x((d) => props.polar ? angleAccessor(d) : xAccessor(d))
.y((d) => scale.y(d._y1 !== undefined ? d._y1 : d._y))
.extent([minRange, maxRange]);
},
getDataStyles(datum, style) {
const numKeys = keys(datum).filter((k) => isNaN(k));
const omitKeys = [
"x", "y", "_x", "_y", "eventKey", "label"
];
const stylesFromData = omit(datum, [...omitKeys, ...numKeys]);
return defaults({}, stylesFromData, style);
}
childProps[eventKey] = { data: dataProps };
const text = LabelHelpers.getText(props, datum, index);
if (text !== undefined && text !== null || events || sharedEvents) {
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
}
return childProps;
}, initialChildProps);
};
export { getBaseProps };

@@ -7,3 +7,3 @@ import React from "react";

} from "victory-core";
import VoronoiHelpers from "./helper-methods";
import { getBaseProps } from "./helper-methods";
import { BaseProps, DataProps } from "../../helpers/common-props";

@@ -46,4 +46,3 @@

static getData = Data.getData.bind(Data);
static getBaseProps = partialRight(
VoronoiHelpers.getBaseProps.bind(VoronoiHelpers), fallbackProps);
static getBaseProps = partialRight(getBaseProps, fallbackProps);
static expectedComponents = [

@@ -50,0 +49,0 @@ "dataComponent", "labelComponent", "groupComponent", "containerComponent"

@@ -223,14 +223,21 @@ import { assign, defaults, flatten, isFunction, keys, partialRight, uniq,

const xArr = sortBy(xKeys);
return datasets.map((dataset) => {
let indexOffset = 0;
const isDate = dataset[0] && dataset[0]._x instanceof Date;
const filledInData = xArr.map((x, index) => {
x = +x;
const datum = dataset[index - indexOffset];
const isDate = datum._x instanceof Date;
const x1 = isDate ? datum._x.getTime() : datum._x;
x = +x;
if (x1 === x) {
return datum;
if (datum) {
const x1 = isDate ? datum._x.getTime() : datum._x;
if (x1 === x) {
return datum;
} else {
indexOffset++;
const y = fillInMissingData ? 0 : null;
x = isDate ? new Date(x) : x;
return { x, y, _x: x, _y: y };
}
} else {
indexOffset++;
const y = fillInMissingData ? 0 : null;

@@ -241,2 +248,3 @@ x = isDate ? new Date(x) : x;

});
return filledInData;

@@ -243,0 +251,0 @@ });

@@ -7,2 +7,3 @@ export { default as VictoryChart } from "./components/victory-chart/victory-chart";

export { default as VictoryBar } from "./components/victory-bar/victory-bar";
export { default as VictoryBoxPlot } from "./components/victory-boxplot/victory-boxplot";
export { default as VictoryScatter } from "./components/victory-scatter/victory-scatter";

@@ -9,0 +10,0 @@ export { default as VictoryGroup } from "./components/victory-group/victory-group";

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc