victory-bar
Advanced tools
Comparing version 35.8.1 to 35.9.0
@@ -94,2 +94,7 @@ import _isNil from "lodash/isNil"; | ||
var props = arguments.length > 1 ? arguments[1] : undefined; | ||
if (props.disableInlineStyles) { | ||
return {}; | ||
} | ||
var stroke = style.fill || "black"; | ||
@@ -96,0 +101,0 @@ var baseStyle = { |
@@ -34,3 +34,3 @@ import _isNil from "lodash/isNil"; | ||
var defaultStyles = Helpers.getDefaultStyles(props, "bar"); | ||
var style = Helpers.getStyles(props.style, defaultStyles); | ||
var style = !props.disableInlineStyles ? Helpers.getStyles(props.style, defaultStyles) : {}; | ||
var range = props.range || { | ||
@@ -68,2 +68,3 @@ x: Helpers.getRange(props, "x"), | ||
data = _props.data, | ||
disableInlineStyles = _props.disableInlineStyles, | ||
domain = _props.domain, | ||
@@ -119,2 +120,3 @@ events = _props.events, | ||
datum: datum, | ||
disableInlineStyles: disableInlineStyles, | ||
getPath: getPath, | ||
@@ -121,0 +123,0 @@ horizontal: horizontal, |
@@ -33,3 +33,6 @@ import * as React from "react"; | ||
}; | ||
events?: EventPropTypeInterface<VictoryBarTTargetType, number | string | number[] | string[]>[]; | ||
events?: EventPropTypeInterface< | ||
VictoryBarTTargetType, | ||
number | string | number[] | string[] | ||
>[]; | ||
eventKey?: StringOrNumberOrCallback; | ||
@@ -36,0 +39,0 @@ horizontal?: boolean; |
@@ -291,5 +291,5 @@ 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; } | ||
var topPoints = getHalfPoints("top"); | ||
var bottomPoints = getHalfPoints("bottom"); // eslint-disable-next-line no-magic-numbers | ||
return [bottomPoints[1], bottomPoints[0]].concat(_toConsumableArray(topPoints), [bottomPoints[3], bottomPoints[2]]); | ||
var bottomPoints = getHalfPoints("bottom"); | ||
return [bottomPoints[1], bottomPoints[0]].concat(_toConsumableArray(topPoints), [// eslint-disable-next-line no-magic-numbers | ||
bottomPoints[3], bottomPoints[2]]); | ||
}; // eslint-disable-next-line max-params | ||
@@ -296,0 +296,0 @@ |
@@ -108,2 +108,7 @@ "use strict"; | ||
var props = arguments.length > 1 ? arguments[1] : undefined; | ||
if (props.disableInlineStyles) { | ||
return {}; | ||
} | ||
var stroke = style.fill || "black"; | ||
@@ -110,0 +115,0 @@ var baseStyle = { |
@@ -51,4 +51,3 @@ "use strict"; | ||
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles); | ||
var style = !props.disableInlineStyles ? _victoryCore.Helpers.getStyles(props.style, defaultStyles) : {}; | ||
var range = props.range || { | ||
@@ -89,2 +88,3 @@ x: _victoryCore.Helpers.getRange(props, "x"), | ||
data = _props.data, | ||
disableInlineStyles = _props.disableInlineStyles, | ||
domain = _props.domain, | ||
@@ -140,2 +140,3 @@ events = _props.events, | ||
datum: datum, | ||
disableInlineStyles: disableInlineStyles, | ||
getPath: getPath, | ||
@@ -142,0 +143,0 @@ horizontal: horizontal, |
@@ -33,3 +33,6 @@ import * as React from "react"; | ||
}; | ||
events?: EventPropTypeInterface<VictoryBarTTargetType, number | string | number[] | string[]>[]; | ||
events?: EventPropTypeInterface< | ||
VictoryBarTTargetType, | ||
number | string | number[] | string[] | ||
>[]; | ||
eventKey?: StringOrNumberOrCallback; | ||
@@ -36,0 +39,0 @@ horizontal?: boolean; |
@@ -303,5 +303,5 @@ "use strict"; | ||
var topPoints = getHalfPoints("top"); | ||
var bottomPoints = getHalfPoints("bottom"); // eslint-disable-next-line no-magic-numbers | ||
return [bottomPoints[1], bottomPoints[0]].concat(_toConsumableArray(topPoints), [bottomPoints[3], bottomPoints[2]]); | ||
var bottomPoints = getHalfPoints("bottom"); | ||
return [bottomPoints[1], bottomPoints[0]].concat(_toConsumableArray(topPoints), [// eslint-disable-next-line no-magic-numbers | ||
bottomPoints[3], bottomPoints[2]]); | ||
}; // eslint-disable-next-line max-params | ||
@@ -308,0 +308,0 @@ |
{ | ||
"name": "victory-bar", | ||
"version": "35.8.1", | ||
"version": "35.9.0", | ||
"description": "Bar Component for Victory", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"prop-types": "^15.5.8", | ||
"victory-core": "^35.8.1" | ||
"victory-core": "^35.9.0" | ||
}, | ||
@@ -28,0 +28,0 @@ "scripts": { |
@@ -39,3 +39,4 @@ import React from "react"; | ||
const barRatio = props.barRatio || 0.5; | ||
const defaultWidth = barRatio * (data.length < 2 ? defaultBarWidth : extent / bars); | ||
const defaultWidth = | ||
barRatio * (data.length < 2 ? defaultBarWidth : extent / bars); | ||
return Math.max(1, defaultWidth); | ||
@@ -45,8 +46,19 @@ }; | ||
const getCornerRadiusFromObject = (cornerRadius, props) => { | ||
const realCornerRadius = { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 0 }; | ||
const realCornerRadius = { | ||
topLeft: 0, | ||
topRight: 0, | ||
bottomLeft: 0, | ||
bottomRight: 0 | ||
}; | ||
const updateCornerRadius = (corner, fallback) => { | ||
if (!isNil(cornerRadius[corner])) { | ||
realCornerRadius[corner] = Helpers.evaluateProp(cornerRadius[corner], props); | ||
realCornerRadius[corner] = Helpers.evaluateProp( | ||
cornerRadius[corner], | ||
props | ||
); | ||
} else if (!isNil(cornerRadius[fallback])) { | ||
realCornerRadius[corner] = Helpers.evaluateProp(cornerRadius[fallback], props); | ||
realCornerRadius[corner] = Helpers.evaluateProp( | ||
cornerRadius[fallback], | ||
props | ||
); | ||
} | ||
@@ -62,3 +74,8 @@ }; | ||
const getCornerRadius = (cornerRadius, props) => { | ||
const realCornerRadius = { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 0 }; | ||
const realCornerRadius = { | ||
topLeft: 0, | ||
topRight: 0, | ||
bottomLeft: 0, | ||
bottomRight: 0 | ||
}; | ||
if (!cornerRadius) { | ||
@@ -77,2 +94,5 @@ return realCornerRadius; | ||
const getStyle = (style = {}, props) => { | ||
if (props.disableInlineStyles) { | ||
return {}; | ||
} | ||
const stroke = style.fill || "black"; | ||
@@ -98,3 +118,6 @@ const baseStyle = { fill: "black", stroke }; | ||
const barWidth = getBarWidth(props.barWidth, assign({}, props, { style })); | ||
const cornerRadius = getCornerRadius(props.cornerRadius, assign({}, props, { style, barWidth })); | ||
const cornerRadius = getCornerRadius( | ||
props.cornerRadius, | ||
assign({}, props, { style, barWidth }) | ||
); | ||
@@ -106,3 +129,11 @@ const ariaLabel = Helpers.evaluateProp(props.ariaLabel, props); | ||
return assign({}, props, { ariaLabel, style, barWidth, cornerRadius, desc, id, tabIndex }); | ||
return assign({}, props, { | ||
ariaLabel, | ||
style, | ||
barWidth, | ||
cornerRadius, | ||
desc, | ||
id, | ||
tabIndex | ||
}); | ||
}; | ||
@@ -117,3 +148,4 @@ | ||
: getBarPath(props, barWidth, cornerRadius); | ||
const defaultTransform = polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined; | ||
const defaultTransform = | ||
polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined; | ||
return React.cloneElement(props.pathComponent, { | ||
@@ -120,0 +152,0 @@ ...props.events, |
@@ -99,7 +99,11 @@ /** | ||
solveX(y) { | ||
const sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2)); | ||
const sqrt = Math.sqrt( | ||
Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2) | ||
); | ||
return [this.center.x - sqrt, this.center.x + sqrt]; | ||
}, | ||
solveY(x) { | ||
const sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2)); | ||
const sqrt = Math.sqrt( | ||
Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2) | ||
); | ||
return [this.center.y - sqrt, this.center.y + sqrt]; | ||
@@ -106,0 +110,0 @@ } |
import { assign, isNil } from "lodash"; | ||
import { Helpers, LabelHelpers, Data, Domain, Scale, Collection } from "victory-core"; | ||
import { | ||
Helpers, | ||
LabelHelpers, | ||
Data, | ||
Domain, | ||
Scale, | ||
Collection | ||
} from "victory-core"; | ||
@@ -7,3 +14,5 @@ const getBarPosition = (props, datum) => { | ||
const defaultZero = | ||
Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0; | ||
Scale.getType(props.scale[axis]) === "log" | ||
? 1 / Number.MAX_SAFE_INTEGER | ||
: 0; | ||
let defaultMin = defaultZero; | ||
@@ -19,3 +28,5 @@ const minY = Collection.getMinValue(props.domain[axis]); | ||
return datum[`_${axis}`] instanceof Date ? new Date(defaultMin) : defaultMin; | ||
return datum[`_${axis}`] instanceof Date | ||
? new Date(defaultMin) | ||
: defaultMin; | ||
}; | ||
@@ -30,3 +41,5 @@ const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y"); | ||
const defaultStyles = Helpers.getDefaultStyles(props, "bar"); | ||
const style = Helpers.getStyles(props.style, defaultStyles); | ||
const style = !props.disableInlineStyles | ||
? Helpers.getStyles(props.style, defaultStyles) | ||
: {}; | ||
const range = props.range || { | ||
@@ -48,3 +61,5 @@ x: Helpers.getRange(props, "x"), | ||
}; | ||
const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined; | ||
const origin = polar | ||
? props.origin || Helpers.getPolarOrigin(props) | ||
: undefined; | ||
@@ -65,2 +80,3 @@ let data = Data.getData(props); | ||
data, | ||
disableInlineStyles, | ||
domain, | ||
@@ -113,2 +129,3 @@ events, | ||
datum, | ||
disableInlineStyles, | ||
getPath, | ||
@@ -134,3 +151,6 @@ horizontal, | ||
const text = LabelHelpers.getText(props, datum, index); | ||
if ((text !== undefined && text !== null) || (labels && (events || sharedEvents))) { | ||
if ( | ||
(text !== undefined && text !== null) || | ||
(labels && (events || sharedEvents)) | ||
) { | ||
childProps[eventKey].labels = LabelHelpers.getProps(props, index); | ||
@@ -137,0 +157,0 @@ } |
@@ -33,3 +33,6 @@ import * as React from "react"; | ||
}; | ||
events?: EventPropTypeInterface<VictoryBarTTargetType, number | string | number[] | string[]>[]; | ||
events?: EventPropTypeInterface< | ||
VictoryBarTTargetType, | ||
number | string | number[] | string[] | ||
>[]; | ||
eventKey?: StringOrNumberOrCallback; | ||
@@ -36,0 +39,0 @@ horizontal?: boolean; |
@@ -56,3 +56,5 @@ import * as d3Shape from "d3-shape"; | ||
const previousAngle = | ||
index === 0 ? getAngle(props, data.length - 1) - Math.PI * 2 : getAngle(props, index - 1); | ||
index === 0 | ||
? getAngle(props, data.length - 1) - Math.PI * 2 | ||
: getAngle(props, index - 1); | ||
if (index === 0 && angularRange < 2 * Math.PI) { | ||
@@ -72,5 +74,9 @@ return scale.x.range()[0]; | ||
const lastAngle = | ||
scale.x.range()[1] === 2 * Math.PI ? getAngle(props, 0) + Math.PI * 2 : scale.x.range()[1]; | ||
scale.x.range()[1] === 2 * Math.PI | ||
? getAngle(props, 0) + Math.PI * 2 | ||
: scale.x.range()[1]; | ||
const nextAngle = | ||
index === data.length - 1 ? getAngle(props, 0) + Math.PI * 2 : getAngle(props, index + 1); | ||
index === data.length - 1 | ||
? getAngle(props, 0) + Math.PI * 2 | ||
: getAngle(props, index + 1); | ||
if (index === data.length - 1 && angularRange < 2 * Math.PI) { | ||
@@ -125,5 +131,11 @@ return lastAngle; | ||
if (hasIntersection) { | ||
const topCenter = point(x + signL * cr[`top${side}`], y1 + sign * cr[`top${side}`]); | ||
const topCenter = point( | ||
x + signL * cr[`top${side}`], | ||
y1 + sign * cr[`top${side}`] | ||
); | ||
const topCircle = circle(topCenter, cr[`top${side}`]); | ||
const bottomCenter = point(x + signL * cr[`bottom${side}`], y0 - sign * cr[`bottom${side}`]); | ||
const bottomCenter = point( | ||
x + signL * cr[`bottom${side}`], | ||
y0 - sign * cr[`bottom${side}`] | ||
); | ||
const bottomCircle = circle(bottomCenter, cr[`bottom${side}`]); | ||
@@ -137,3 +149,4 @@ const circleIntersection = topCircle.intersection(bottomCircle); | ||
} else { | ||
const hasBottomLineTopArcIntersection = cr[`top${side}`] > cr[`bottom${side}`]; | ||
const hasBottomLineTopArcIntersection = | ||
cr[`top${side}`] > cr[`bottom${side}`]; | ||
if (hasBottomLineTopArcIntersection) { | ||
@@ -175,5 +188,11 @@ const newX = topCircle.solveX(y0)[isLeft ? 0 : 1]; | ||
if (hasIntersection) { | ||
const leftCenter = point(x0 + cr[`${side}Left`], y - signL * cr[`${side}Left`]); | ||
const leftCenter = point( | ||
x0 + cr[`${side}Left`], | ||
y - signL * cr[`${side}Left`] | ||
); | ||
const leftCircle = circle(leftCenter, cr[`${side}Left`]); | ||
const rightCenter = point(x1 - cr[`${side}Right`], y - signL * cr[`${side}Right`]); | ||
const rightCenter = point( | ||
x1 - cr[`${side}Right`], | ||
y - signL * cr[`${side}Right`] | ||
); | ||
const rightCircle = circle(rightCenter, cr[`${side}Right`]); | ||
@@ -187,3 +206,4 @@ const circleIntersection = leftCircle.intersection(rightCircle); | ||
} else { | ||
const hasLeftLineRightArcIntersection = cr[`${side}Right`] > cr[`${side}Left`]; | ||
const hasLeftLineRightArcIntersection = | ||
cr[`${side}Right`] > cr[`${side}Left`]; | ||
if (hasLeftLineRightArcIntersection) { | ||
@@ -206,4 +226,10 @@ const newY = rightCircle.solveY(x0)[isTop ? 0 : 1]; | ||
const bottomPoints = getHalfPoints("bottom"); | ||
// eslint-disable-next-line no-magic-numbers | ||
return [bottomPoints[1], bottomPoints[0], ...topPoints, bottomPoints[3], bottomPoints[2]]; | ||
return [ | ||
bottomPoints[1], | ||
bottomPoints[0], | ||
...topPoints, | ||
// eslint-disable-next-line no-magic-numbers | ||
bottomPoints[3], | ||
bottomPoints[2] | ||
]; | ||
}; | ||
@@ -274,3 +300,10 @@ | ||
const leftMiddle = leftMoves.indexOf("L"); | ||
return { rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle }; | ||
return { | ||
rightMoves, | ||
rightCoords, | ||
rightMiddle, | ||
leftMoves, | ||
leftCoords, | ||
leftMiddle | ||
}; | ||
}; | ||
@@ -282,5 +315,10 @@ | ||
const arcLength = r2 * Math.abs(end - start); | ||
const { rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle } = getPathData( | ||
"top" | ||
); | ||
const { | ||
rightMoves, | ||
rightCoords, | ||
rightMiddle, | ||
leftMoves, | ||
leftCoords, | ||
leftMiddle | ||
} = getPathData("top"); | ||
let moves; | ||
@@ -297,3 +335,5 @@ let coords; | ||
if (topRight > topLeft) { | ||
const defaultOffset = isShort(rightMiddle) ? leftMiddle : leftMiddle - 2; | ||
const defaultOffset = isShort(rightMiddle) | ||
? leftMiddle | ||
: leftMiddle - 2; | ||
leftOffset = isShort(leftMiddle) ? leftMiddle - 1 : defaultOffset; | ||
@@ -304,4 +344,10 @@ } else { | ||
} | ||
moves = [...rightMoves.slice(0, rightOffset), ...leftMoves.slice(leftOffset)]; | ||
coords = [...rightCoords.slice(0, rightOffset), ...leftCoords.slice(leftOffset)]; | ||
moves = [ | ||
...rightMoves.slice(0, rightOffset), | ||
...leftMoves.slice(leftOffset) | ||
]; | ||
coords = [ | ||
...rightCoords.slice(0, rightOffset), | ||
...leftCoords.slice(leftOffset) | ||
]; | ||
} | ||
@@ -312,3 +358,6 @@ | ||
const subCoords = coords.slice(0, middle); | ||
return subMoves.map((m, i) => ({ command: m, coords: subCoords[i].split(",") })); | ||
return subMoves.map((m, i) => ({ | ||
command: m, | ||
coords: subCoords[i].split(",") | ||
})); | ||
}; | ||
@@ -320,8 +369,16 @@ | ||
const arcLength = r1 * Math.abs(end - start); | ||
const { rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle } = getPathData( | ||
"bottom" | ||
); | ||
const { | ||
rightMoves, | ||
rightCoords, | ||
rightMiddle, | ||
leftMoves, | ||
leftCoords, | ||
leftMiddle | ||
} = getPathData("bottom"); | ||
let moves; | ||
let coords; | ||
if (bottomRight === bottomLeft || arcLength < 2 * bottomRight + 2 * bottomLeft) { | ||
if ( | ||
bottomRight === bottomLeft || | ||
arcLength < 2 * bottomRight + 2 * bottomLeft | ||
) { | ||
moves = bottomRight > bottomLeft ? rightMoves : leftMoves; | ||
@@ -339,4 +396,10 @@ coords = bottomRight > bottomLeft ? rightCoords : leftCoords; | ||
moves = [...leftMoves.slice(0, leftMiddle + 2), ...rightMoves.slice(rightOffset)]; | ||
coords = [...leftCoords.slice(0, leftMiddle + 2), ...rightCoords.slice(rightOffset)]; | ||
moves = [ | ||
...leftMoves.slice(0, leftMiddle + 2), | ||
...rightMoves.slice(rightOffset) | ||
]; | ||
coords = [ | ||
...leftCoords.slice(0, leftMiddle + 2), | ||
...rightCoords.slice(rightOffset) | ||
]; | ||
} | ||
@@ -346,3 +409,6 @@ const middle = moves.indexOf("L"); | ||
const subCoords = coords.slice(middle, -1); | ||
return subMoves.map((m, i) => ({ command: m, coords: subCoords[i].split(",") })); | ||
return subMoves.map((m, i) => ({ | ||
command: m, | ||
coords: subCoords[i].split(",") | ||
})); | ||
}; | ||
@@ -349,0 +415,0 @@ |
@@ -30,3 +30,10 @@ import PropTypes from "prop-types"; | ||
class VictoryBar extends React.Component { | ||
static animationWhitelist = ["data", "domain", "height", "padding", "style", "width"]; | ||
static animationWhitelist = [ | ||
"data", | ||
"domain", | ||
"height", | ||
"padding", | ||
"style", | ||
"width" | ||
]; | ||
@@ -112,3 +119,5 @@ static displayName = "VictoryBar"; | ||
const children = this.renderData(props); | ||
return props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return props.standalone | ||
? this.renderContainer(props.containerComponent, children) | ||
: children; | ||
} | ||
@@ -115,0 +124,0 @@ } |
119435
3255
Updatedvictory-core@^35.9.0