Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

victory-chart

Package Overview
Dependencies
Maintainers
8
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 14.0.1 to 14.0.2

70

lib/components/victory-zoom/victory-zoom.js

@@ -1,6 +0,6 @@

Object.defineProperty(exports,"__esModule",{value:true});var _isEqual2=require("lodash/isEqual");var _isEqual3=_interopRequireDefault(_isEqual2);var _groupBy3=require("lodash/groupBy");var _groupBy4=_interopRequireDefault(_groupBy3);var _assign2=require("lodash/assign");var _assign3=_interopRequireDefault(_assign2);var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[typeof Symbol==="function"?Symbol.iterator:"@@iterator"](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"])_i["return"]();}finally{if(_d)throw _e;}}return _arr;}return function(arr,i){if(Array.isArray(arr)){return arr;}else if((typeof Symbol==="function"?Symbol.iterator:"@@iterator")in Object(arr)){return sliceIterator(arr,i);}else{throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _createClass=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);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require("react");var _react2=_interopRequireDefault(_react);
Object.defineProperty(exports,"__esModule",{value:true});var _isEqual2=require("lodash/isEqual");var _isEqual3=_interopRequireDefault(_isEqual2);var _assign2=require("lodash/assign");var _assign3=_interopRequireDefault(_assign2);var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[typeof Symbol==="function"?Symbol.iterator:"@@iterator"](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"])_i["return"]();}finally{if(_d)throw _e;}}return _arr;}return function(arr,i){if(Array.isArray(arr)){return arr;}else if((typeof Symbol==="function"?Symbol.iterator:"@@iterator")in Object(arr)){return sliceIterator(arr,i);}else{throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _createClass=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);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require("react");var _react2=_interopRequireDefault(_react);
var _helperMethods=require("../victory-chart/helper-methods");var _helperMethods2=_interopRequireDefault(_helperMethods);
var _helperMethods3=require("./helper-methods");var _helperMethods4=_interopRequireDefault(_helperMethods3);
var _victoryCore=require("victory-core");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}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);}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}
var _victoryCore=require("victory-core");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 _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}

@@ -97,5 +97,3 @@ var fallbackProps={

allowZoom){var _this3=this;
return[{
target:"parent",
eventHandlers:_extends({
var standardEvents={
onMouseDown:function onMouseDown(evt){

@@ -122,4 +120,6 @@ _this3.targetBounds=_this3.chartRef.getSvgBounds();

}
}},
allowZoom&&{onWheel:function onWheel(evt){
}};
var wheelEvent={
onWheel:function onWheel(evt){
evt.preventDefault();

@@ -135,5 +135,9 @@ var deltaY=evt.deltaY;

});
}})}];
}};
return[{
target:"parent",
eventHandlers:allowZoom?(0,_assign3.default)({},standardEvents,wheelEvent):standardEvents}];
}},{key:"setDomain",value:function setDomain(

@@ -155,21 +159,39 @@

children,props){var _groupBy2=
(0,_groupBy4.default)(children,function(child){
return child.type.displayName==="VictoryAxis"?
"axes":
"data";
}),data=_groupBy2.data,_groupBy2$axes=_groupBy2.axes,axes=_groupBy2$axes===undefined?[]:_groupBy2$axes;var _Helpers$getRange3=
children,props){var _this5=this;var _Helpers$getRange3=
_victoryCore.Helpers.getRange(props,"x"),_Helpers$getRange4=_slicedToArray(_Helpers$getRange3,2),rangex0=_Helpers$getRange4[0],rangex1=_Helpers$getRange4[1];
var childComponents=[];
var group=[];
var groupNumber=0;
return[
_react2.default.cloneElement(this.props.clipContainerComponent,{
key:"ZoomClipContainer",
var makeGroup=function makeGroup(arr,index){
return _react2.default.cloneElement(_this5.props.clipContainerComponent,{
key:"ZoomClipContainer-"+index,
clipWidth:rangex1-rangex0,
clipHeight:fallbackProps.height,
translateX:rangex0,
children:data})].concat(_toConsumableArray(
children:arr});
axes));
};
var findNextAxis=function findNextAxis(start){
var subset=children.slice(start);
return subset.findIndex(function(child){return child.type.displayName==="VictoryAxis";})+start;
};
var axisIndex=findNextAxis(0);
if(axisIndex===-1){
return makeGroup(children,groupNumber);
}
for(var i=0,len=children.length;i<len;i++){
if(i===axisIndex){
childComponents.push(makeGroup(group,groupNumber),children[i]);
axisIndex=findNextAxis(i+1);
group=[];
groupNumber++;
}
group.push(children[i]);
}
childComponents.push(makeGroup(group,groupNumber));
return childComponents;
}},{key:"renderChart",value:function renderChart(

@@ -181,6 +203,10 @@

{var _chart$props$events;
{
var chart=_react2.default.Children.only(this.props.children);
var events=chart.props.events?
(this.events||[]).concat(chart.props.events):
this.events;
var nextProps=(0,_assign3.default)({},chart.props,{
events:chart.props.events?(_chart$props$events=chart.props.events).unshift.apply(_chart$props$events,_toConsumableArray(this.events)):this.events,
events:events,
domain:this.state.domain,

@@ -187,0 +213,0 @@ ref:this.getChartRef,

{
"name": "victory-chart",
"version": "14.0.1",
"version": "14.0.2",
"description": "Chart Component for Victory",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import React, {Component, PropTypes} from "react";
import { assign, groupBy, isEqual } from "lodash";
import { assign, isEqual } from "lodash";
import ChartHelpers from "../victory-chart/helper-methods";

@@ -97,40 +97,44 @@ import ZoomHelpers from "./helper-methods";

getEvents(allowZoom) {
return [{
target: "parent",
eventHandlers: {
onMouseDown: (evt) => {
this.targetBounds = this.chartRef.getSvgBounds();
const x = evt.clientX - this.targetBounds.left;
this.isPanning = true;
this.startX = x;
this.lastDomain = this.state.domain;
},
onMouseUp: () => { this.isPanning = false; },
onMouseLeave: () => { this.isPanning = false; },
onMouseMove: (evt) => {
const clientX = evt.clientX;
if (this.isPanning) {
requestAnimationFrame(() => { // eslint-disable-line no-undef
const domain = this.getDataDomain();
const delta = this.startX - (clientX - this.targetBounds.left);
const calculatedDx = delta / this.getDomainScale();
const nextXDomain = ZoomHelpers.pan(this.lastDomain.x, domain.x, calculatedDx);
this.setDomain({x: nextXDomain});
this.setState({domain: {x: nextXDomain}});
});
}
},
...allowZoom && {onWheel: (evt) => {
evt.preventDefault();
const deltaY = evt.deltaY;
const standardEvents = {
onMouseDown: (evt) => {
this.targetBounds = this.chartRef.getSvgBounds();
const x = evt.clientX - this.targetBounds.left;
this.isPanning = true;
this.startX = x;
this.lastDomain = this.state.domain;
},
onMouseUp: () => { this.isPanning = false; },
onMouseLeave: () => { this.isPanning = false; },
onMouseMove: (evt) => {
const clientX = evt.clientX;
if (this.isPanning) {
requestAnimationFrame(() => { // eslint-disable-line no-undef
const {x} = this.state.domain;
const xBounds = this.getDataDomain().x;
// TODO: Check scale factor
const nextXDomain = ZoomHelpers.scale(x, xBounds, 1 + (deltaY / 300));
const domain = this.getDataDomain();
const delta = this.startX - (clientX - this.targetBounds.left);
const calculatedDx = delta / this.getDomainScale();
const nextXDomain = ZoomHelpers.pan(this.lastDomain.x, domain.x, calculatedDx);
this.setDomain({x: nextXDomain});
this.setState({domain: {x: nextXDomain}});
});
}}
}
}
};
const wheelEvent = {
onWheel: (evt) => {
evt.preventDefault();
const deltaY = evt.deltaY;
requestAnimationFrame(() => { // eslint-disable-line no-undef
const {x} = this.state.domain;
const xBounds = this.getDataDomain().x;
// TODO: Check scale factor
const nextXDomain = ZoomHelpers.scale(x, xBounds, 1 + (deltaY / 300));
this.setDomain({x: nextXDomain});
});
}
};
return [{
target: "parent",
eventHandlers: allowZoom ? assign({}, standardEvents, wheelEvent) : standardEvents
}];

@@ -153,21 +157,39 @@ }

clipDataComponents(children, props) {
const {data, axes = []} = groupBy(children, (child) => {
return child.type.displayName === "VictoryAxis"
? "axes"
: "data";
});
clipDataComponents(children, props) { //eslint-disable-line max-statements
const [rangex0, rangex1] = Helpers.getRange(props, "x");
const childComponents = [];
let group = [];
let groupNumber = 0;
return [
React.cloneElement(this.props.clipContainerComponent, {
key: "ZoomClipContainer",
const makeGroup = (arr, index) => {
return React.cloneElement(this.props.clipContainerComponent, {
key: `ZoomClipContainer-${index}`,
clipWidth: rangex1 - rangex0,
clipHeight: fallbackProps.height,
translateX: rangex0,
children: data
}),
...axes
];
children: arr
});
};
const findNextAxis = (start) => {
const subset = children.slice(start);
return subset.findIndex((child) => child.type.displayName === "VictoryAxis") + start;
};
let axisIndex = findNextAxis(0);
if (axisIndex === -1) {
return makeGroup(children, groupNumber);
}
for (let i = 0, len = children.length; i < len; i++) {
if (i === axisIndex) {
childComponents.push(makeGroup(group, groupNumber), children[i]);
axisIndex = findNextAxis(i + 1);
group = [];
groupNumber++;
}
group.push(children[i]);
}
childComponents.push(makeGroup(group, groupNumber));
return childComponents;
}

@@ -181,4 +203,8 @@

const chart = React.Children.only(this.props.children);
const events = chart.props.events
? (this.events || []).concat(chart.props.events)
: this.events;
const nextProps = assign({}, chart.props, {
events: chart.props.events ? chart.props.events.unshift(...this.events) : this.events,
events,
domain: this.state.domain,

@@ -185,0 +211,0 @@ ref: this.getChartRef,

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