UNPKG

victory-chart

Version:
165 lines (98 loc) 4.15 kB
Object.defineProperty(exports,"__esModule",{value:true});var _identity2=require("lodash/identity");var _identity3=_interopRequireDefault(_identity2);var _victoryCore=require("victory-core"); var _react=require("react");var _react2=_interopRequireDefault(_react);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);}}exports.default= { getAxis:function getAxis(props){ if(props.orientation){ var vertical={top:"x",bottom:"x",left:"y",right:"y"}; return vertical[props.orientation]; } return props.dependentAxis?"y":"x"; }, getCurrentAxis:function getCurrentAxis(axis,horizontal){ var otherAxis=axis==="x"?"y":"x"; return horizontal?otherAxis:axis; }, getAxisComponent:function getAxisComponent(childComponents,axis){ var matchesAxis=function matchesAxis(component){ var type=component.type.getAxis(component.props); return type===axis; }; return this.findAxisComponents(childComponents,matchesAxis)[0]; }, findAxisComponents:function findAxisComponents(childComponents,predicate){ predicate=predicate||_identity3.default; var findAxes=function findAxes(children){ return children.reduce(function(memo,child){ if(child.type&&child.type.role==="axis"&&predicate(child)){ return memo.concat(child); }else if(child.props&&child.props.children){ return memo.concat(findAxes(_react2.default.Children.toArray(child.props.children))); } return memo; },[]); }; return findAxes(childComponents); }, getAxisComponentsWithParent:function getAxisComponentsWithParent(childComponents,type){ var matchesType=function matchesType(child){ return type==="dependent"?child.props.dependentAxis:!child.props.dependentAxis; }; var findAxisComponents=function findAxisComponents(children){ return children.reduce(function(memo,child){ if(child.type&&child.type.role==="axis"&&matchesType(child)){ return memo.concat(child); }else if(child.props&&child.props.children){ var childAxis=findAxisComponents(_react2.default.Children.toArray(child.props.children)); return childAxis.length>0?memo.concat(child):memo; } return memo; },[]); }; return findAxisComponents(childComponents); }, getOrigin:function getOrigin(domain){ var getSingleOrigin=function getSingleOrigin(){ var domainMin=Math.min.apply(Math,_toConsumableArray(domain)); var domainMax=Math.max.apply(Math,_toConsumableArray(domain)); return domainMax<0?domainMax:Math.max(0,domainMin); }; return _victoryCore.Collection.containsDates(domain)? new Date(Math.min.apply(Math,_toConsumableArray(domain))):getSingleOrigin(); }, getOriginSign:function getOriginSign(origin,domain){ var getSign=function getSign(){ return origin<=0&&Math.max.apply(Math,_toConsumableArray(domain))<=0?"negative":"positive"; }; return _victoryCore.Collection.containsDates(domain)?"positive":getSign(); }, getOrientation:function getOrientation(component,axis,originSign){ if(component&&component.props&&component.props.orientation){ return component.props.orientation; } var sign=originSign||"positive"; var typicalOrientations={ positive:{x:"bottom",y:"left"}, negative:{x:"top",y:"right"}}; var flippedOrientations={ positive:{x:"left",y:"bottom"}, negative:{x:"right",y:"top"}}; if(!component){ return typicalOrientations[sign][axis]; } var dependent=component.props.dependentAxis; return!dependent&&axis==="y"||dependent&&axis==="x"? flippedOrientations[sign][axis]:typicalOrientations[sign][axis]; }, getAxisOrientations:function getAxisOrientations(childComponents){ return{ x:this.getOrientation(this.getAxisComponent(childComponents,"x"),"x"), y:this.getOrientation(this.getAxisComponent(childComponents,"y"),"y")}; }, isVertical:function isVertical(props){ var orientation=props.orientation||(props.dependentAxis?"left":"bottom"); var vertical={top:false,bottom:false,left:true,right:true}; return vertical[orientation]; }, stringTicks:function stringTicks(props){ return props.tickValues!==undefined&&_victoryCore.Collection.containsStrings(props.tickValues); }};