victory-histogram
Advanced tools
Comparing version 36.9.2 to 37.0.0
# victory-histogram | ||
## 37.0.0 | ||
### Major Changes | ||
- Upgrade babel dependencies and build target to modern browsers ([#2804](https://github.com/FormidableLabs/victory/pull/2804)) | ||
## 36.9.2 | ||
@@ -4,0 +10,0 @@ |
@@ -1,19 +0,1 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core"; | ||
@@ -24,7 +6,6 @@ import { getBarPosition } from "victory-bar"; | ||
import * as d3Scale from "victory-vendor/d3-scale"; | ||
var cacheLastValue = function (func) { | ||
var called = false; | ||
var lastArgs; | ||
var lastReturnVal; | ||
const cacheLastValue = func => { | ||
let called = false; | ||
let lastArgs; | ||
let lastReturnVal; | ||
return function () { | ||
@@ -34,8 +15,6 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
if (called && isEqual(lastArgs, args)) { | ||
return lastReturnVal; | ||
} | ||
var value = func.apply(void 0, args); | ||
const value = func(...args); | ||
called = true; | ||
@@ -47,26 +26,23 @@ lastReturnVal = value; | ||
}; | ||
var dataOrBinsContainDates = function (_ref) { | ||
var data = _ref.data, | ||
bins = _ref.bins, | ||
x = _ref.x; | ||
var xAccessor = Helpers.createAccessor(x || "x"); | ||
var dataIsDates = (data === null || data === void 0 ? void 0 : data.some(function (datum) { | ||
return xAccessor(datum) instanceof Date; | ||
})) || false; | ||
var binsHasDates = Array.isArray(bins) && bins.some(function (bin) { | ||
return bin instanceof Date; | ||
}); | ||
const dataOrBinsContainDates = _ref => { | ||
let { | ||
data, | ||
bins, | ||
x | ||
} = _ref; | ||
const xAccessor = Helpers.createAccessor(x || "x"); | ||
const dataIsDates = data?.some(datum => xAccessor(datum) instanceof Date) || false; | ||
const binsHasDates = Array.isArray(bins) && bins.some(bin => bin instanceof Date); | ||
return dataIsDates || binsHasDates; | ||
}; | ||
var getBinningFunc = function (_ref2) { | ||
var data = _ref2.data, | ||
x = _ref2.x, | ||
bins = _ref2.bins, | ||
dataOrBinsContainsDates = _ref2.dataOrBinsContainsDates; | ||
var xAccessor = Helpers.createAccessor(x || "x"); | ||
var bin = d3Array.bin().value(xAccessor); | ||
var niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice(); | ||
const getBinningFunc = _ref2 => { | ||
let { | ||
data, | ||
x, | ||
bins, | ||
dataOrBinsContainsDates | ||
} = _ref2; | ||
const xAccessor = Helpers.createAccessor(x || "x"); | ||
const bin = d3Array.bin().value(xAccessor); | ||
const niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice(); | ||
if (Array.isArray(bins)) { | ||
@@ -77,3 +53,2 @@ bin.domain([bins[0], bins[bins.length - 1]]); | ||
} | ||
if (Number.isInteger(bins)) { | ||
@@ -84,3 +59,2 @@ bin.domain(niceScale.domain()); | ||
} | ||
if (dataOrBinsContainsDates) { | ||
@@ -91,50 +65,45 @@ bin.domain(niceScale.domain()); | ||
} | ||
bin.domain(niceScale.domain()); | ||
return bin; | ||
}; | ||
export var getFormattedData = cacheLastValue(function (_ref3) { | ||
var _ref3$data = _ref3.data, | ||
data = _ref3$data === void 0 ? [] : _ref3$data, | ||
x = _ref3.x, | ||
bins = _ref3.bins; | ||
export const getFormattedData = cacheLastValue(_ref3 => { | ||
let { | ||
data = [], | ||
x, | ||
bins | ||
} = _ref3; | ||
if ((!data || !data.length) && !Array.isArray(bins)) { | ||
return []; | ||
} | ||
var dataOrBinsContainsDates = dataOrBinsContainDates({ | ||
data: data, | ||
bins: bins, | ||
x: x | ||
const dataOrBinsContainsDates = dataOrBinsContainDates({ | ||
data, | ||
bins, | ||
x | ||
}); | ||
var binFunc = getBinningFunc({ | ||
data: data, | ||
x: x, | ||
bins: bins, | ||
dataOrBinsContainsDates: dataOrBinsContainsDates | ||
const binFunc = getBinningFunc({ | ||
data, | ||
x, | ||
bins, | ||
dataOrBinsContainsDates | ||
}); | ||
var foo = binFunc(data); | ||
var binnedData = _toConsumableArray(foo).filter(function (_ref4) { | ||
var x0 = _ref4.x0, | ||
x1 = _ref4.x1; | ||
const foo = binFunc(data); | ||
const binnedData = [...foo].filter(_ref4 => { | ||
let { | ||
x0, | ||
x1 | ||
} = _ref4; | ||
if (x0 instanceof Date && x1 instanceof Date) { | ||
return new Date(x0).getTime() !== new Date(x1).getTime(); | ||
} | ||
return x0 !== x1; | ||
}); | ||
var formattedData = binnedData.map(function (bin) { | ||
var x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0; | ||
var x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0; | ||
const formattedData = binnedData.map(bin => { | ||
const x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0; | ||
const x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0; | ||
return { | ||
x0: x0, | ||
x1: x1, | ||
x0, | ||
x1, | ||
x: dataOrBinsContainsDates ? new Date((x0.getTime() + x1.getTime()) / 2) : (x0 + x1) / 2, | ||
y: bin.length, | ||
binnedData: _toConsumableArray(bin) | ||
binnedData: [...bin] | ||
}; | ||
@@ -144,33 +113,35 @@ }); | ||
}); | ||
export var getData = function (props) { | ||
var bins = props.bins, | ||
data = props.data, | ||
x = props.x; | ||
var dataIsPreformatted = data === null || data === void 0 ? void 0 : data.some(function (_ref5) { | ||
var _y = _ref5._y; | ||
export const getData = props => { | ||
const { | ||
bins, | ||
data, | ||
x | ||
} = props; | ||
const dataIsPreformatted = data?.some(_ref5 => { | ||
let { | ||
_y | ||
} = _ref5; | ||
return !Helpers.isNil(_y); | ||
}); | ||
var formattedData = dataIsPreformatted ? data : getFormattedData({ | ||
data: data, | ||
x: x, | ||
bins: bins | ||
const formattedData = dataIsPreformatted ? data : getFormattedData({ | ||
data, | ||
x, | ||
bins | ||
}); | ||
return Data.getData(_objectSpread(_objectSpread({}, props), {}, { | ||
return Data.getData({ | ||
...props, | ||
data: formattedData, | ||
x: "x" | ||
})); | ||
}); | ||
}; | ||
export var getDomain = function (props, axis) { | ||
var _props$data; | ||
var data = getData(props); | ||
export const getDomain = (props, axis) => { | ||
const data = getData(props); | ||
if (!data.length) { | ||
return [0, 1]; | ||
} | ||
if (axis === "x") { | ||
var firstBin = data[0]; | ||
var lastBin = data[data.length - 1]; | ||
return Domain.getDomainWithZero(_objectSpread(_objectSpread({}, props), {}, { | ||
const firstBin = data[0]; | ||
const lastBin = data[data.length - 1]; | ||
return Domain.getDomainWithZero({ | ||
...props, | ||
data: [{ | ||
@@ -182,24 +153,23 @@ x: firstBin.x0 | ||
x: "x" | ||
}), "x"); | ||
}, "x"); | ||
} | ||
return (_props$data = props.data) !== null && _props$data !== void 0 && _props$data.length ? Domain.getDomainWithZero(_objectSpread(_objectSpread({}, props), {}, { | ||
data: data | ||
}), "y") : [0, 1]; | ||
return props.data?.length ? Domain.getDomainWithZero({ | ||
...props, | ||
data | ||
}, "y") : [0, 1]; | ||
}; | ||
var getCalculatedValues = function (props) { | ||
var defaultStyles = Helpers.getDefaultStyles(props, "histogram"); | ||
var style = Helpers.getStyles(props.style, defaultStyles); | ||
var range = props.range || { | ||
const getCalculatedValues = props => { | ||
const defaultStyles = Helpers.getDefaultStyles(props, "histogram"); | ||
const style = Helpers.getStyles(props.style, defaultStyles); | ||
const range = props.range || { | ||
x: Helpers.getRange(props, "x"), | ||
y: Helpers.getRange(props, "y") | ||
}; | ||
var domain = { | ||
const domain = { | ||
x: getDomain(props, "x"), | ||
y: getDomain(props, "y") | ||
}; | ||
var data = getData(props); | ||
let data = getData(props); | ||
data = Data.formatDataFromDomain(data, domain, 0); | ||
var scale = { | ||
const scale = { | ||
x: Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x), | ||
@@ -209,88 +179,84 @@ y: Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y) | ||
return { | ||
style: style, | ||
data: data, | ||
scale: scale, | ||
domain: domain | ||
style, | ||
data, | ||
scale, | ||
domain | ||
}; | ||
}; | ||
export var getBaseProps = function (initialProps, fallbackProps) { | ||
var modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "histogram"); | ||
var props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps)); | ||
var binSpacing = props.binSpacing, | ||
cornerRadius = props.cornerRadius, | ||
data = props.data, | ||
domain = props.domain, | ||
events = props.events, | ||
height = props.height, | ||
horizontal = props.horizontal, | ||
padding = props.padding, | ||
scale = props.scale, | ||
sharedEvents = props.sharedEvents, | ||
standalone = props.standalone, | ||
style = props.style, | ||
theme = props.theme, | ||
width = props.width, | ||
labels = props.labels, | ||
name = props.name, | ||
getPath = props.getPath, | ||
disableInlineStyles = props.disableInlineStyles; | ||
var initialChildProps = { | ||
export const getBaseProps = (initialProps, fallbackProps) => { | ||
const modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "histogram"); | ||
const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps)); | ||
const { | ||
binSpacing, | ||
cornerRadius, | ||
data, | ||
domain, | ||
events, | ||
height, | ||
horizontal, | ||
padding, | ||
scale, | ||
sharedEvents, | ||
standalone, | ||
style, | ||
theme, | ||
width, | ||
labels, | ||
name, | ||
getPath, | ||
disableInlineStyles | ||
} = props; | ||
const initialChildProps = { | ||
parent: { | ||
horizontal: horizontal, | ||
domain: domain, | ||
scale: scale, | ||
width: width, | ||
height: height, | ||
data: data, | ||
standalone: standalone, | ||
name: name, | ||
theme: theme, | ||
padding: padding, | ||
horizontal, | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
data, | ||
standalone, | ||
name, | ||
theme, | ||
padding, | ||
style: style.parent | ||
} | ||
}; | ||
var getDistance = function (datum) { | ||
var current = scale.x(datum.x0); | ||
var next = scale.x(datum.x1); | ||
const getDistance = datum => { | ||
const current = scale.x(datum.x0); | ||
const next = scale.x(datum.x1); | ||
return Math.abs(next - current); | ||
}; | ||
var getBarWidth = function (datum) { | ||
const getBarWidth = datum => { | ||
if (binSpacing) { | ||
return getDistance(datum) - binSpacing; | ||
} | ||
return getDistance(datum); | ||
}; | ||
return data.reduce(function (childProps, datum, index) { | ||
var eventKey = !Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
var _getBarPosition = getBarPosition(props, datum), | ||
x = _getBarPosition.x, | ||
y = _getBarPosition.y, | ||
y0 = _getBarPosition.y0, | ||
x0 = _getBarPosition.x0; | ||
var barWidth = getBarWidth(datum); | ||
var dataProps = { | ||
return data.reduce((childProps, datum, index) => { | ||
const eventKey = !Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
const { | ||
x, | ||
y, | ||
y0, | ||
x0 | ||
} = getBarPosition(props, datum); | ||
const barWidth = getBarWidth(datum); | ||
const dataProps = { | ||
alignment: "middle", | ||
barWidth: barWidth, | ||
cornerRadius: cornerRadius, | ||
data: data, | ||
datum: datum, | ||
horizontal: horizontal, | ||
index: index, | ||
scale: scale, | ||
barWidth, | ||
cornerRadius, | ||
data, | ||
datum, | ||
horizontal, | ||
index, | ||
scale, | ||
style: disableInlineStyles ? {} : style.data, | ||
width: width, | ||
height: height, | ||
x: x, | ||
y: y, | ||
y0: y0, | ||
x0: x0, | ||
getPath: getPath, | ||
disableInlineStyles: disableInlineStyles | ||
width, | ||
height, | ||
x, | ||
y, | ||
y0, | ||
x0, | ||
getPath, | ||
disableInlineStyles | ||
}; | ||
@@ -300,10 +266,8 @@ childProps[eventKey] = { | ||
}; | ||
var text = LabelHelpers.getText(props, datum, index); | ||
const text = LabelHelpers.getText(props, datum, index); | ||
if (text !== undefined && text !== null || labels && (events || sharedEvents)) { | ||
childProps[eventKey].labels = LabelHelpers.getProps(props, index); | ||
} | ||
return childProps; | ||
}, initialChildProps); | ||
}; |
@@ -1,21 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
import React from "react"; | ||
@@ -25,3 +5,3 @@ import { Bar } from "victory-bar"; | ||
import { getBaseProps, getData, getDomain, getFormattedData } from "./helper-methods"; | ||
var fallbackProps = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -31,4 +11,6 @@ height: 300, | ||
}; | ||
var defaultData = []; // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
const defaultData = []; | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
/** | ||
@@ -38,109 +20,78 @@ * Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes | ||
*/ | ||
var VictoryHistogramBase = /*#__PURE__*/function (_React$Component) { | ||
_inherits(VictoryHistogramBase, _React$Component); | ||
var _super = _createSuper(VictoryHistogramBase); | ||
function VictoryHistogramBase() { | ||
_classCallCheck(this, VictoryHistogramBase); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(VictoryHistogramBase, [{ | ||
key: "shouldAnimate", | ||
value: // Overridden in native versions | ||
function shouldAnimate() { | ||
return !!this.props.animate; | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var animationWhitelist = VictoryHistogramBase.animationWhitelist, | ||
role = VictoryHistogramBase.role; | ||
var props = Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
} | ||
var children = this.renderData(props); | ||
var component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return UserProps.withSafeUserProps(component, props); | ||
} | ||
}]); | ||
return VictoryHistogramBase; | ||
}(React.Component); | ||
VictoryHistogramBase.animationWhitelist = ["data", "domain", "height", "padding", "style", "width"]; | ||
VictoryHistogramBase.displayName = "VictoryHistogram"; | ||
VictoryHistogramBase.role = "histogram"; | ||
VictoryHistogramBase.defaultTransitions = { | ||
onLoad: { | ||
duration: 2000, | ||
before: function () { | ||
return { | ||
class VictoryHistogramBase extends React.Component { | ||
static animationWhitelist = ["data", "domain", "height", "padding", "style", "width"]; | ||
static displayName = "VictoryHistogram"; | ||
static role = "histogram"; | ||
static defaultTransitions = { | ||
onLoad: { | ||
duration: 2000, | ||
before: () => ({ | ||
_y: 0, | ||
_y1: 0, | ||
_y0: 0 | ||
}; | ||
}, | ||
after: function (datum) { | ||
return { | ||
}), | ||
after: datum => ({ | ||
_y: datum._y, | ||
_y1: datum._y1, | ||
_y0: datum._y0 | ||
}; | ||
} | ||
}, | ||
onExit: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
}) | ||
}, | ||
onExit: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
yOffset: 0 | ||
}; | ||
} | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
}) | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
_y1: 0, | ||
_y0: 0 | ||
}; | ||
}, | ||
after: function (datum) { | ||
return { | ||
}), | ||
after: datum => ({ | ||
_y: datum._y, | ||
_y1: datum._y1, | ||
_y0: datum._y0 | ||
}; | ||
}) | ||
} | ||
}; | ||
static getFormattedData = getFormattedData; | ||
static defaultProps = { | ||
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null), | ||
data: defaultData, | ||
dataComponent: /*#__PURE__*/React.createElement(Bar, null), | ||
groupComponent: /*#__PURE__*/React.createElement("g", { | ||
role: "presentation" | ||
}), | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null), | ||
samples: 50, | ||
sortOrder: "ascending", | ||
standalone: true, | ||
theme: VictoryTheme.grayscale | ||
}; | ||
static getDomain = getDomain; | ||
static getData = getData; | ||
static getBaseProps = props => getBaseProps(props, fallbackProps); | ||
static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"]; | ||
// Overridden in native versions | ||
shouldAnimate() { | ||
return !!this.props.animate; | ||
} | ||
}; | ||
VictoryHistogramBase.getFormattedData = getFormattedData; | ||
VictoryHistogramBase.defaultProps = { | ||
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null), | ||
data: defaultData, | ||
dataComponent: /*#__PURE__*/React.createElement(Bar, null), | ||
groupComponent: /*#__PURE__*/React.createElement("g", { | ||
role: "presentation" | ||
}), | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null), | ||
samples: 50, | ||
sortOrder: "ascending", | ||
standalone: true, | ||
theme: VictoryTheme.grayscale | ||
}; | ||
VictoryHistogramBase.getDomain = getDomain; | ||
VictoryHistogramBase.getData = getData; | ||
VictoryHistogramBase.getBaseProps = function (props) { | ||
return getBaseProps(props, fallbackProps); | ||
}; | ||
VictoryHistogramBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"]; | ||
export var VictoryHistogram = addEvents(VictoryHistogramBase); | ||
render() { | ||
const { | ||
animationWhitelist, | ||
role | ||
} = VictoryHistogramBase; | ||
const props = Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
} | ||
const children = this.renderData(props); | ||
const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return UserProps.withSafeUserProps(component, props); | ||
} | ||
} | ||
export const VictoryHistogram = addEvents(VictoryHistogramBase); |
@@ -7,41 +7,14 @@ "use strict"; | ||
exports.getFormattedData = exports.getDomain = exports.getData = exports.getBaseProps = void 0; | ||
var _victoryCore = require("victory-core"); | ||
var _victoryBar = require("victory-bar"); | ||
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare")); | ||
var d3Array = _interopRequireWildcard(require("victory-vendor/d3-array")); | ||
var d3Scale = _interopRequireWildcard(require("victory-vendor/d3-scale")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var cacheLastValue = function (func) { | ||
var called = false; | ||
var lastArgs; | ||
var lastReturnVal; | ||
const cacheLastValue = func => { | ||
let called = false; | ||
let lastArgs; | ||
let lastReturnVal; | ||
return function () { | ||
@@ -51,8 +24,6 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
if (called && (0, _reactFastCompare.default)(lastArgs, args)) { | ||
return lastReturnVal; | ||
} | ||
var value = func.apply(void 0, args); | ||
const value = func(...args); | ||
called = true; | ||
@@ -64,30 +35,23 @@ lastReturnVal = value; | ||
}; | ||
var dataOrBinsContainDates = function (_ref) { | ||
var data = _ref.data, | ||
bins = _ref.bins, | ||
x = _ref.x; | ||
var xAccessor = _victoryCore.Helpers.createAccessor(x || "x"); | ||
var dataIsDates = (data === null || data === void 0 ? void 0 : data.some(function (datum) { | ||
return xAccessor(datum) instanceof Date; | ||
})) || false; | ||
var binsHasDates = Array.isArray(bins) && bins.some(function (bin) { | ||
return bin instanceof Date; | ||
}); | ||
const dataOrBinsContainDates = _ref => { | ||
let { | ||
data, | ||
bins, | ||
x | ||
} = _ref; | ||
const xAccessor = _victoryCore.Helpers.createAccessor(x || "x"); | ||
const dataIsDates = data?.some(datum => xAccessor(datum) instanceof Date) || false; | ||
const binsHasDates = Array.isArray(bins) && bins.some(bin => bin instanceof Date); | ||
return dataIsDates || binsHasDates; | ||
}; | ||
var getBinningFunc = function (_ref2) { | ||
var data = _ref2.data, | ||
x = _ref2.x, | ||
bins = _ref2.bins, | ||
dataOrBinsContainsDates = _ref2.dataOrBinsContainsDates; | ||
var xAccessor = _victoryCore.Helpers.createAccessor(x || "x"); | ||
var bin = d3Array.bin().value(xAccessor); | ||
var niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice(); | ||
const getBinningFunc = _ref2 => { | ||
let { | ||
data, | ||
x, | ||
bins, | ||
dataOrBinsContainsDates | ||
} = _ref2; | ||
const xAccessor = _victoryCore.Helpers.createAccessor(x || "x"); | ||
const bin = d3Array.bin().value(xAccessor); | ||
const niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice(); | ||
if (Array.isArray(bins)) { | ||
@@ -98,3 +62,2 @@ bin.domain([bins[0], bins[bins.length - 1]]); | ||
} | ||
if (Number.isInteger(bins)) { | ||
@@ -105,3 +68,2 @@ bin.domain(niceScale.domain()); | ||
} | ||
if (dataOrBinsContainsDates) { | ||
@@ -112,50 +74,45 @@ bin.domain(niceScale.domain()); | ||
} | ||
bin.domain(niceScale.domain()); | ||
return bin; | ||
}; | ||
var getFormattedData = cacheLastValue(function (_ref3) { | ||
var _ref3$data = _ref3.data, | ||
data = _ref3$data === void 0 ? [] : _ref3$data, | ||
x = _ref3.x, | ||
bins = _ref3.bins; | ||
const getFormattedData = exports.getFormattedData = cacheLastValue(_ref3 => { | ||
let { | ||
data = [], | ||
x, | ||
bins | ||
} = _ref3; | ||
if ((!data || !data.length) && !Array.isArray(bins)) { | ||
return []; | ||
} | ||
var dataOrBinsContainsDates = dataOrBinsContainDates({ | ||
data: data, | ||
bins: bins, | ||
x: x | ||
const dataOrBinsContainsDates = dataOrBinsContainDates({ | ||
data, | ||
bins, | ||
x | ||
}); | ||
var binFunc = getBinningFunc({ | ||
data: data, | ||
x: x, | ||
bins: bins, | ||
dataOrBinsContainsDates: dataOrBinsContainsDates | ||
const binFunc = getBinningFunc({ | ||
data, | ||
x, | ||
bins, | ||
dataOrBinsContainsDates | ||
}); | ||
var foo = binFunc(data); | ||
var binnedData = _toConsumableArray(foo).filter(function (_ref4) { | ||
var x0 = _ref4.x0, | ||
x1 = _ref4.x1; | ||
const foo = binFunc(data); | ||
const binnedData = [...foo].filter(_ref4 => { | ||
let { | ||
x0, | ||
x1 | ||
} = _ref4; | ||
if (x0 instanceof Date && x1 instanceof Date) { | ||
return new Date(x0).getTime() !== new Date(x1).getTime(); | ||
} | ||
return x0 !== x1; | ||
}); | ||
var formattedData = binnedData.map(function (bin) { | ||
var x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0; | ||
var x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0; | ||
const formattedData = binnedData.map(bin => { | ||
const x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0; | ||
const x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0; | ||
return { | ||
x0: x0, | ||
x1: x1, | ||
x0, | ||
x1, | ||
x: dataOrBinsContainsDates ? new Date((x0.getTime() + x1.getTime()) / 2) : (x0 + x1) / 2, | ||
y: bin.length, | ||
binnedData: _toConsumableArray(bin) | ||
binnedData: [...bin] | ||
}; | ||
@@ -165,38 +122,36 @@ }); | ||
}); | ||
exports.getFormattedData = getFormattedData; | ||
var getData = function (props) { | ||
var bins = props.bins, | ||
data = props.data, | ||
x = props.x; | ||
var dataIsPreformatted = data === null || data === void 0 ? void 0 : data.some(function (_ref5) { | ||
var _y = _ref5._y; | ||
const getData = props => { | ||
const { | ||
bins, | ||
data, | ||
x | ||
} = props; | ||
const dataIsPreformatted = data?.some(_ref5 => { | ||
let { | ||
_y | ||
} = _ref5; | ||
return !_victoryCore.Helpers.isNil(_y); | ||
}); | ||
var formattedData = dataIsPreformatted ? data : getFormattedData({ | ||
data: data, | ||
x: x, | ||
bins: bins | ||
const formattedData = dataIsPreformatted ? data : getFormattedData({ | ||
data, | ||
x, | ||
bins | ||
}); | ||
return _victoryCore.Data.getData(_objectSpread(_objectSpread({}, props), {}, { | ||
return _victoryCore.Data.getData({ | ||
...props, | ||
data: formattedData, | ||
x: "x" | ||
})); | ||
}); | ||
}; | ||
exports.getData = getData; | ||
var getDomain = function (props, axis) { | ||
var _props$data; | ||
var data = getData(props); | ||
const getDomain = (props, axis) => { | ||
const data = getData(props); | ||
if (!data.length) { | ||
return [0, 1]; | ||
} | ||
if (axis === "x") { | ||
var firstBin = data[0]; | ||
var lastBin = data[data.length - 1]; | ||
return _victoryCore.Domain.getDomainWithZero(_objectSpread(_objectSpread({}, props), {}, { | ||
const firstBin = data[0]; | ||
const lastBin = data[data.length - 1]; | ||
return _victoryCore.Domain.getDomainWithZero({ | ||
...props, | ||
data: [{ | ||
@@ -208,28 +163,24 @@ x: firstBin.x0 | ||
x: "x" | ||
}), "x"); | ||
}, "x"); | ||
} | ||
return (_props$data = props.data) !== null && _props$data !== void 0 && _props$data.length ? _victoryCore.Domain.getDomainWithZero(_objectSpread(_objectSpread({}, props), {}, { | ||
data: data | ||
}), "y") : [0, 1]; | ||
return props.data?.length ? _victoryCore.Domain.getDomainWithZero({ | ||
...props, | ||
data | ||
}, "y") : [0, 1]; | ||
}; | ||
exports.getDomain = getDomain; | ||
var getCalculatedValues = function (props) { | ||
var defaultStyles = _victoryCore.Helpers.getDefaultStyles(props, "histogram"); | ||
var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles); | ||
var range = props.range || { | ||
const getCalculatedValues = props => { | ||
const defaultStyles = _victoryCore.Helpers.getDefaultStyles(props, "histogram"); | ||
const style = _victoryCore.Helpers.getStyles(props.style, defaultStyles); | ||
const range = props.range || { | ||
x: _victoryCore.Helpers.getRange(props, "x"), | ||
y: _victoryCore.Helpers.getRange(props, "y") | ||
}; | ||
var domain = { | ||
const domain = { | ||
x: getDomain(props, "x"), | ||
y: getDomain(props, "y") | ||
}; | ||
var data = getData(props); | ||
let data = getData(props); | ||
data = _victoryCore.Data.formatDataFromDomain(data, domain, 0); | ||
var scale = { | ||
const scale = { | ||
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x), | ||
@@ -239,89 +190,84 @@ y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y) | ||
return { | ||
style: style, | ||
data: data, | ||
scale: scale, | ||
domain: domain | ||
style, | ||
data, | ||
scale, | ||
domain | ||
}; | ||
}; | ||
var getBaseProps = function (initialProps, fallbackProps) { | ||
var modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "histogram"); | ||
var props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps)); | ||
var binSpacing = props.binSpacing, | ||
cornerRadius = props.cornerRadius, | ||
data = props.data, | ||
domain = props.domain, | ||
events = props.events, | ||
height = props.height, | ||
horizontal = props.horizontal, | ||
padding = props.padding, | ||
scale = props.scale, | ||
sharedEvents = props.sharedEvents, | ||
standalone = props.standalone, | ||
style = props.style, | ||
theme = props.theme, | ||
width = props.width, | ||
labels = props.labels, | ||
name = props.name, | ||
getPath = props.getPath, | ||
disableInlineStyles = props.disableInlineStyles; | ||
var initialChildProps = { | ||
const getBaseProps = (initialProps, fallbackProps) => { | ||
const modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "histogram"); | ||
const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps)); | ||
const { | ||
binSpacing, | ||
cornerRadius, | ||
data, | ||
domain, | ||
events, | ||
height, | ||
horizontal, | ||
padding, | ||
scale, | ||
sharedEvents, | ||
standalone, | ||
style, | ||
theme, | ||
width, | ||
labels, | ||
name, | ||
getPath, | ||
disableInlineStyles | ||
} = props; | ||
const initialChildProps = { | ||
parent: { | ||
horizontal: horizontal, | ||
domain: domain, | ||
scale: scale, | ||
width: width, | ||
height: height, | ||
data: data, | ||
standalone: standalone, | ||
name: name, | ||
theme: theme, | ||
padding: padding, | ||
horizontal, | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
data, | ||
standalone, | ||
name, | ||
theme, | ||
padding, | ||
style: style.parent | ||
} | ||
}; | ||
var getDistance = function (datum) { | ||
var current = scale.x(datum.x0); | ||
var next = scale.x(datum.x1); | ||
const getDistance = datum => { | ||
const current = scale.x(datum.x0); | ||
const next = scale.x(datum.x1); | ||
return Math.abs(next - current); | ||
}; | ||
var getBarWidth = function (datum) { | ||
const getBarWidth = datum => { | ||
if (binSpacing) { | ||
return getDistance(datum) - binSpacing; | ||
} | ||
return getDistance(datum); | ||
}; | ||
return data.reduce(function (childProps, datum, index) { | ||
var eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
var _getBarPosition = (0, _victoryBar.getBarPosition)(props, datum), | ||
x = _getBarPosition.x, | ||
y = _getBarPosition.y, | ||
y0 = _getBarPosition.y0, | ||
x0 = _getBarPosition.x0; | ||
var barWidth = getBarWidth(datum); | ||
var dataProps = { | ||
return data.reduce((childProps, datum, index) => { | ||
const eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
const { | ||
x, | ||
y, | ||
y0, | ||
x0 | ||
} = (0, _victoryBar.getBarPosition)(props, datum); | ||
const barWidth = getBarWidth(datum); | ||
const dataProps = { | ||
alignment: "middle", | ||
barWidth: barWidth, | ||
cornerRadius: cornerRadius, | ||
data: data, | ||
datum: datum, | ||
horizontal: horizontal, | ||
index: index, | ||
scale: scale, | ||
barWidth, | ||
cornerRadius, | ||
data, | ||
datum, | ||
horizontal, | ||
index, | ||
scale, | ||
style: disableInlineStyles ? {} : style.data, | ||
width: width, | ||
height: height, | ||
x: x, | ||
y: y, | ||
y0: y0, | ||
x0: x0, | ||
getPath: getPath, | ||
disableInlineStyles: disableInlineStyles | ||
width, | ||
height, | ||
x, | ||
y, | ||
y0, | ||
x0, | ||
getPath, | ||
disableInlineStyles | ||
}; | ||
@@ -331,13 +277,9 @@ childProps[eventKey] = { | ||
}; | ||
var text = _victoryCore.LabelHelpers.getText(props, datum, index); | ||
const text = _victoryCore.LabelHelpers.getText(props, datum, index); | ||
if (text !== undefined && text !== null || labels && (events || sharedEvents)) { | ||
childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index); | ||
} | ||
return childProps; | ||
}, initialChildProps); | ||
}; | ||
exports.getBaseProps = getBaseProps; |
@@ -6,5 +6,3 @@ "use strict"; | ||
}); | ||
var _victoryHistogram = require("./victory-histogram"); | ||
Object.keys(_victoryHistogram).forEach(function (key) { | ||
@@ -11,0 +9,0 @@ if (key === "default" || key === "__esModule") return; |
@@ -7,34 +7,8 @@ "use strict"; | ||
exports.VictoryHistogram = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _victoryBar = require("victory-bar"); | ||
var _victoryCore = require("victory-core"); | ||
var _helperMethods = require("./helper-methods"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var fallbackProps = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -44,4 +18,6 @@ height: 300, | ||
}; | ||
var defaultData = []; // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
const defaultData = []; | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
/** | ||
@@ -51,111 +27,78 @@ * Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes | ||
*/ | ||
var VictoryHistogramBase = /*#__PURE__*/function (_React$Component) { | ||
_inherits(VictoryHistogramBase, _React$Component); | ||
var _super = _createSuper(VictoryHistogramBase); | ||
function VictoryHistogramBase() { | ||
_classCallCheck(this, VictoryHistogramBase); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(VictoryHistogramBase, [{ | ||
key: "shouldAnimate", | ||
value: // Overridden in native versions | ||
function shouldAnimate() { | ||
return !!this.props.animate; | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var animationWhitelist = VictoryHistogramBase.animationWhitelist, | ||
role = VictoryHistogramBase.role; | ||
var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
} | ||
var children = this.renderData(props); | ||
var component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return _victoryCore.UserProps.withSafeUserProps(component, props); | ||
} | ||
}]); | ||
return VictoryHistogramBase; | ||
}(_react.default.Component); | ||
VictoryHistogramBase.animationWhitelist = ["data", "domain", "height", "padding", "style", "width"]; | ||
VictoryHistogramBase.displayName = "VictoryHistogram"; | ||
VictoryHistogramBase.role = "histogram"; | ||
VictoryHistogramBase.defaultTransitions = { | ||
onLoad: { | ||
duration: 2000, | ||
before: function () { | ||
return { | ||
class VictoryHistogramBase extends _react.default.Component { | ||
static animationWhitelist = ["data", "domain", "height", "padding", "style", "width"]; | ||
static displayName = "VictoryHistogram"; | ||
static role = "histogram"; | ||
static defaultTransitions = { | ||
onLoad: { | ||
duration: 2000, | ||
before: () => ({ | ||
_y: 0, | ||
_y1: 0, | ||
_y0: 0 | ||
}; | ||
}, | ||
after: function (datum) { | ||
return { | ||
}), | ||
after: datum => ({ | ||
_y: datum._y, | ||
_y1: datum._y1, | ||
_y0: datum._y0 | ||
}; | ||
} | ||
}, | ||
onExit: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
}) | ||
}, | ||
onExit: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
yOffset: 0 | ||
}; | ||
} | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
}) | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
_y1: 0, | ||
_y0: 0 | ||
}; | ||
}, | ||
after: function (datum) { | ||
return { | ||
}), | ||
after: datum => ({ | ||
_y: datum._y, | ||
_y1: datum._y1, | ||
_y0: datum._y0 | ||
}; | ||
}) | ||
} | ||
}; | ||
static getFormattedData = _helperMethods.getFormattedData; | ||
static defaultProps = { | ||
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null), | ||
data: defaultData, | ||
dataComponent: /*#__PURE__*/_react.default.createElement(_victoryBar.Bar, null), | ||
groupComponent: /*#__PURE__*/_react.default.createElement("g", { | ||
role: "presentation" | ||
}), | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryLabel, null), | ||
samples: 50, | ||
sortOrder: "ascending", | ||
standalone: true, | ||
theme: _victoryCore.VictoryTheme.grayscale | ||
}; | ||
static getDomain = _helperMethods.getDomain; | ||
static getData = _helperMethods.getData; | ||
static getBaseProps = props => (0, _helperMethods.getBaseProps)(props, fallbackProps); | ||
static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"]; | ||
// Overridden in native versions | ||
shouldAnimate() { | ||
return !!this.props.animate; | ||
} | ||
}; | ||
VictoryHistogramBase.getFormattedData = _helperMethods.getFormattedData; | ||
VictoryHistogramBase.defaultProps = { | ||
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null), | ||
data: defaultData, | ||
dataComponent: /*#__PURE__*/_react.default.createElement(_victoryBar.Bar, null), | ||
groupComponent: /*#__PURE__*/_react.default.createElement("g", { | ||
role: "presentation" | ||
}), | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryLabel, null), | ||
samples: 50, | ||
sortOrder: "ascending", | ||
standalone: true, | ||
theme: _victoryCore.VictoryTheme.grayscale | ||
}; | ||
VictoryHistogramBase.getDomain = _helperMethods.getDomain; | ||
VictoryHistogramBase.getData = _helperMethods.getData; | ||
VictoryHistogramBase.getBaseProps = function (props) { | ||
return (0, _helperMethods.getBaseProps)(props, fallbackProps); | ||
}; | ||
VictoryHistogramBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"]; | ||
var VictoryHistogram = (0, _victoryCore.addEvents)(VictoryHistogramBase); | ||
exports.VictoryHistogram = VictoryHistogram; | ||
render() { | ||
const { | ||
animationWhitelist, | ||
role | ||
} = VictoryHistogramBase; | ||
const props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
} | ||
const children = this.renderData(props); | ||
const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return _victoryCore.UserProps.withSafeUserProps(component, props); | ||
} | ||
} | ||
const VictoryHistogram = exports.VictoryHistogram = (0, _victoryCore.addEvents)(VictoryHistogramBase); |
{ | ||
"name": "victory-histogram", | ||
"version": "36.9.2", | ||
"version": "37.0.0", | ||
"description": "Histogram Component for Victory", | ||
@@ -25,5 +25,5 @@ "keywords": [ | ||
"react-fast-compare": "^3.2.0", | ||
"victory-bar": "^36.9.2", | ||
"victory-core": "^36.9.2", | ||
"victory-vendor": "^36.9.2" | ||
"victory-bar": "^37.0.0", | ||
"victory-core": "^37.0.0", | ||
"victory-vendor": "^37.0.0" | ||
}, | ||
@@ -30,0 +30,0 @@ "peerDependencies": { |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
1269068
22567
4
106
3
4
0
28
+ Addedvictory-bar@37.3.1(transitive)
+ Addedvictory-core@37.3.1(transitive)
+ Addedvictory-vendor@37.3.1(transitive)
- Removedvictory-bar@36.9.2(transitive)
- Removedvictory-core@36.9.2(transitive)
- Removedvictory-vendor@36.9.2(transitive)
Updatedvictory-bar@^37.0.0
Updatedvictory-core@^37.0.0
Updatedvictory-vendor@^37.0.0