victory-candlestick
Advanced tools
Comparing version 30.1.0 to 30.2.0
@@ -0,1 +1,2 @@ | ||
import _isFunction from "lodash/isFunction"; | ||
import _defaults from "lodash/defaults"; | ||
@@ -20,3 +21,3 @@ import _assign from "lodash/assign"; | ||
/*eslint no-magic-numbers: ["error", { "ignore": [0.5, 2] }]*/ | ||
/*eslint no-magic-numbers: ["error", { "ignore": [0, 0.5, 1, 2] }]*/ | ||
import React from "react"; | ||
@@ -38,2 +39,25 @@ import PropTypes from "prop-types"; | ||
_createClass(Candle, [{ | ||
key: "getCandleWidth", | ||
value: function getCandleWidth(props, style) { | ||
var active = props.active, | ||
datum = props.datum, | ||
data = props.data, | ||
candleWidth = props.candleWidth, | ||
scale = props.scale, | ||
defaultCandleWidth = props.defaultCandleWidth; | ||
if (candleWidth) { | ||
return _isFunction(candleWidth) ? Helpers.evaluateProp(candleWidth, datum, active) : candleWidth; | ||
} else if (style.width) { | ||
return style.width; | ||
} | ||
var range = scale.x.range(); | ||
var extent = Math.abs(range[1] - range[0]); | ||
var candles = data.length + 2; | ||
var candleRatio = props.candleRatio || 0.5; | ||
var defaultWidth = candleRatio * (data.length < 2 ? defaultCandleWidth : extent / candles); | ||
return Math.max(1, defaultWidth); | ||
} | ||
}, { | ||
key: "render", | ||
@@ -47,9 +71,8 @@ value: function render() { | ||
close = _props.close, | ||
data = _props.data, | ||
datum = _props.datum, | ||
active = _props.active, | ||
width = _props.width, | ||
candleHeight = _props.candleHeight, | ||
events = _props.events, | ||
groupComponent = _props.groupComponent, | ||
clipPath = _props.clipPath, | ||
id = _props.id, | ||
rectComponent = _props.rectComponent, | ||
@@ -61,5 +84,3 @@ lineComponent = _props.lineComponent, | ||
wickStrokeWidth = _props.wickStrokeWidth, | ||
transform = _props.transform, | ||
clipPath = _props.clipPath, | ||
id = _props.id; | ||
transform = _props.transform; | ||
var style = Helpers.evaluateStyle(_assign({ | ||
@@ -73,4 +94,4 @@ stroke: "black" | ||
var padding = this.props.padding.left || this.props.padding; | ||
var candleWidth = style.width || 0.5 * (width - 2 * padding) / data.length; | ||
var candleWidth = this.getCandleWidth(this.props, style); | ||
var candleHeight = Math.abs(close - open); | ||
var candleX = x - candleWidth / 2; | ||
@@ -125,5 +146,7 @@ var sharedProps = { | ||
value: _objectSpread({}, CommonProps.primitiveProps, { | ||
candleHeight: PropTypes.number, | ||
candleRatio: PropTypes.number, | ||
candleWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]), | ||
close: PropTypes.number, | ||
datum: PropTypes.object, | ||
defaultCandleWidth: PropTypes.number, | ||
groupComponent: PropTypes.element, | ||
@@ -134,3 +157,2 @@ high: PropTypes.number, | ||
open: PropTypes.number, | ||
padding: PropTypes.oneOfType([PropTypes.number, PropTypes.object]), | ||
rectComponent: PropTypes.element, | ||
@@ -147,2 +169,3 @@ wickStrokeWidth: PropTypes.number, | ||
value: { | ||
defaultCandleWidth: 8, | ||
groupComponent: React.createElement("g", null), | ||
@@ -149,0 +172,0 @@ lineComponent: React.createElement(Line, null), |
@@ -129,2 +129,4 @@ import _assign from "lodash/assign"; | ||
name = _props.name, | ||
candleWidth = _props.candleWidth, | ||
candleRatio = _props.candleRatio, | ||
theme = _props.theme, | ||
@@ -159,3 +161,2 @@ polar = _props.polar, | ||
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); | ||
@@ -166,3 +167,4 @@ var dataProps = { | ||
low: low, | ||
candleHeight: candleHeight, | ||
candleWidth: candleWidth, | ||
candleRatio: candleRatio, | ||
scale: scale, | ||
@@ -174,3 +176,2 @@ data: data, | ||
style: dataStyle, | ||
padding: padding, | ||
width: width, | ||
@@ -177,0 +178,0 @@ polar: polar, |
@@ -148,2 +148,4 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
}), | ||
candleRatio: PropTypes.number, | ||
candleWidth: PropTypes.oneOfType([PropTypes.func, PropTypes.number]), | ||
close: PropTypes.oneOfType([PropTypes.func, CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), | ||
@@ -150,0 +152,0 @@ high: PropTypes.oneOfType([PropTypes.func, CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction")); | ||
var _defaults2 = _interopRequireDefault(require("lodash/defaults")); | ||
@@ -49,2 +51,25 @@ | ||
_createClass(Candle, [{ | ||
key: "getCandleWidth", | ||
value: function getCandleWidth(props, style) { | ||
var active = props.active, | ||
datum = props.datum, | ||
data = props.data, | ||
candleWidth = props.candleWidth, | ||
scale = props.scale, | ||
defaultCandleWidth = props.defaultCandleWidth; | ||
if (candleWidth) { | ||
return (0, _isFunction2.default)(candleWidth) ? _victoryCore.Helpers.evaluateProp(candleWidth, datum, active) : candleWidth; | ||
} else if (style.width) { | ||
return style.width; | ||
} | ||
var range = scale.x.range(); | ||
var extent = Math.abs(range[1] - range[0]); | ||
var candles = data.length + 2; | ||
var candleRatio = props.candleRatio || 0.5; | ||
var defaultWidth = candleRatio * (data.length < 2 ? defaultCandleWidth : extent / candles); | ||
return Math.max(1, defaultWidth); | ||
} | ||
}, { | ||
key: "render", | ||
@@ -58,9 +83,8 @@ value: function render() { | ||
close = _props.close, | ||
data = _props.data, | ||
datum = _props.datum, | ||
active = _props.active, | ||
width = _props.width, | ||
candleHeight = _props.candleHeight, | ||
events = _props.events, | ||
groupComponent = _props.groupComponent, | ||
clipPath = _props.clipPath, | ||
id = _props.id, | ||
rectComponent = _props.rectComponent, | ||
@@ -72,5 +96,3 @@ lineComponent = _props.lineComponent, | ||
wickStrokeWidth = _props.wickStrokeWidth, | ||
transform = _props.transform, | ||
clipPath = _props.clipPath, | ||
id = _props.id; | ||
transform = _props.transform; | ||
@@ -84,4 +106,4 @@ var style = _victoryCore.Helpers.evaluateStyle((0, _assign2.default)({ | ||
}, style); | ||
var padding = this.props.padding.left || this.props.padding; | ||
var candleWidth = style.width || 0.5 * (width - 2 * padding) / data.length; | ||
var candleWidth = this.getCandleWidth(this.props, style); | ||
var candleHeight = Math.abs(close - open); | ||
var candleX = x - candleWidth / 2; | ||
@@ -133,5 +155,7 @@ var sharedProps = { | ||
value: _objectSpread({}, _victoryCore.CommonProps.primitiveProps, { | ||
candleHeight: _propTypes.default.number, | ||
candleRatio: _propTypes.default.number, | ||
candleWidth: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.func]), | ||
close: _propTypes.default.number, | ||
datum: _propTypes.default.object, | ||
defaultCandleWidth: _propTypes.default.number, | ||
groupComponent: _propTypes.default.element, | ||
@@ -142,3 +166,2 @@ high: _propTypes.default.number, | ||
open: _propTypes.default.number, | ||
padding: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.object]), | ||
rectComponent: _propTypes.default.element, | ||
@@ -155,2 +178,3 @@ wickStrokeWidth: _propTypes.default.number, | ||
value: { | ||
defaultCandleWidth: 8, | ||
groupComponent: _react.default.createElement("g", null), | ||
@@ -157,0 +181,0 @@ lineComponent: _react.default.createElement(_victoryCore.Line, null), |
@@ -147,2 +147,4 @@ "use strict"; | ||
name = _props.name, | ||
candleWidth = _props.candleWidth, | ||
candleRatio = _props.candleRatio, | ||
theme = _props.theme, | ||
@@ -177,3 +179,2 @@ polar = _props.polar, | ||
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); | ||
@@ -184,3 +185,4 @@ var dataProps = { | ||
low: low, | ||
candleHeight: candleHeight, | ||
candleWidth: candleWidth, | ||
candleRatio: candleRatio, | ||
scale: scale, | ||
@@ -192,3 +194,2 @@ data: data, | ||
style: dataStyle, | ||
padding: padding, | ||
width: width, | ||
@@ -195,0 +196,0 @@ polar: polar, |
@@ -162,2 +162,4 @@ "use strict"; | ||
}), | ||
candleRatio: _propTypes.default.number, | ||
candleWidth: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.number]), | ||
close: _propTypes.default.oneOfType([_propTypes.default.func, _victoryCore.PropTypes.allOfType([_victoryCore.PropTypes.integer, _victoryCore.PropTypes.nonNegative]), _propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]), | ||
@@ -164,0 +166,0 @@ high: _propTypes.default.oneOfType([_propTypes.default.func, _victoryCore.PropTypes.allOfType([_victoryCore.PropTypes.integer, _victoryCore.PropTypes.nonNegative]), _propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]), |
{ | ||
"name": "victory-candlestick", | ||
"version": "30.1.0", | ||
"version": "30.2.0", | ||
"description": "Candlestick Component for Victory", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"prop-types": "^15.5.8", | ||
"victory-core": "^30.1.0" | ||
"victory-core": "^30.2.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "scripts": { |
@@ -1,6 +0,6 @@ | ||
/*eslint no-magic-numbers: ["error", { "ignore": [0.5, 2] }]*/ | ||
/*eslint no-magic-numbers: ["error", { "ignore": [0, 0.5, 1, 2] }]*/ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Helpers, CommonProps, Rect, Line } from "victory-core"; | ||
import { assign, defaults } from "lodash"; | ||
import { assign, defaults, isFunction } from "lodash"; | ||
@@ -10,5 +10,10 @@ export default class Candle extends React.Component { | ||
...CommonProps.primitiveProps, | ||
candleHeight: PropTypes.number, | ||
candleRatio: PropTypes.number, | ||
candleWidth: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.func | ||
]), | ||
close: PropTypes.number, | ||
datum: PropTypes.object, | ||
defaultCandleWidth: PropTypes.number, | ||
groupComponent: PropTypes.element, | ||
@@ -19,6 +24,2 @@ high: PropTypes.number, | ||
open: PropTypes.number, | ||
padding: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.object | ||
]), | ||
rectComponent: PropTypes.element, | ||
@@ -31,2 +32,3 @@ wickStrokeWidth: PropTypes.number, | ||
static defaultProps = { | ||
defaultCandleWidth: 8, | ||
groupComponent: <g/>, | ||
@@ -37,7 +39,22 @@ lineComponent: <Line/>, | ||
getCandleWidth(props, style) { | ||
const { active, datum, data, candleWidth, scale, defaultCandleWidth } = props; | ||
if (candleWidth) { | ||
return isFunction(candleWidth) ? | ||
Helpers.evaluateProp(candleWidth, datum, active) : candleWidth; | ||
} else if (style.width) { | ||
return style.width; | ||
} | ||
const range = scale.x.range(); | ||
const extent = Math.abs(range[1] - range[0]); | ||
const candles = data.length + 2; | ||
const candleRatio = props.candleRatio || 0.5; | ||
const defaultWidth = candleRatio * (data.length < 2 ? defaultCandleWidth : extent / candles); | ||
return Math.max(1, defaultWidth); | ||
} | ||
render() { | ||
const { | ||
x, high, low, open, close, data, datum, active, width, candleHeight, events, groupComponent, | ||
rectComponent, lineComponent, role, shapeRendering, className, wickStrokeWidth, transform, | ||
clipPath, id | ||
x, high, low, open, close, datum, active, events, groupComponent, clipPath, id, | ||
rectComponent, lineComponent, role, shapeRendering, className, wickStrokeWidth, transform | ||
} = this.props; | ||
@@ -48,4 +65,4 @@ const style = Helpers.evaluateStyle( | ||
const wickStyle = defaults({ strokeWidth: wickStrokeWidth }, style); | ||
const padding = this.props.padding.left || this.props.padding; | ||
const candleWidth = style.width || 0.5 * (width - 2 * padding) / data.length; | ||
const candleWidth = this.getCandleWidth(this.props, style); | ||
const candleHeight = Math.abs(close - open); | ||
const candleX = x - candleWidth / 2; | ||
@@ -52,0 +69,0 @@ const sharedProps = { role, shapeRendering, className, events, transform, clipPath }; |
@@ -61,3 +61,2 @@ import { assign } from "lodash"; | ||
const isTransparent = (attr) => { | ||
@@ -100,3 +99,3 @@ return attr === "none" || attr === "transparent"; | ||
const { | ||
groupComponent, width, height, padding, standalone, name, | ||
groupComponent, width, height, padding, standalone, name, candleWidth, candleRatio, | ||
theme, polar, wickStrokeWidth, labels, events, sharedEvents | ||
@@ -116,7 +115,6 @@ } = props; | ||
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 | ||
x, high, low, candleWidth, candleRatio, scale, data, datum, groupComponent, index, | ||
style: dataStyle, width, polar, origin, wickStrokeWidth, open, close | ||
}; | ||
@@ -123,0 +121,0 @@ |
@@ -46,2 +46,7 @@ import PropTypes from "prop-types"; | ||
candleColors: PropTypes.shape({ positive: PropTypes.string, negative: PropTypes.string }), | ||
candleRatio: PropTypes.number, | ||
candleWidth: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.number | ||
]), | ||
close: PropTypes.oneOfType([ | ||
@@ -48,0 +53,0 @@ PropTypes.func, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1196791
21668
Updatedvictory-core@^30.2.0