code
stringlengths
28
313k
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
74
language
stringclasses
1 value
repo
stringlengths
5
60
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
_updateInterpolator(oldProps, newProps) { this._interpolator = interpolate( extractAnimatedPropValues(oldProps), newProps ? extractAnimatedPropValues(newProps) : null ); }
Update the interpolator function and assign it to this._interpolator. @param {Object} oldProps Old props. @param {Object} newProps New props. @private
_updateInterpolator
javascript
uber/react-vis
packages/react-vis/src/animation.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/animation.js
MIT
function debounceEmitResize() { window.clearTimeout(timeoutId); timeoutId = window.setTimeout(emitResize, DEBOUNCE_DURATION); }
Calls each subscriber, debounced to the
debounceEmitResize
javascript
uber/react-vis
packages/react-vis/src/make-vis-flexible.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/make-vis-flexible.js
MIT
function subscribeToDebouncedResize(cb) { resizeSubscribers.push(cb); // if we go from zero to one Flexible components instances, add the listener if (resizeSubscribers.length === 1) { window.addEventListener('resize', debounceEmitResize); } return function unsubscribe() { removeSubscriber(cb); ...
Add the given callback to the list of subscribers to be caled when the window resizes. Returns a function that, when called, removes the given callback from the list of subscribers. This function is also resposible for adding and removing the resize listener on `window`. @param {Function} cb - Subscriber callback func...
subscribeToDebouncedResize
javascript
uber/react-vis
packages/react-vis/src/make-vis-flexible.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/make-vis-flexible.js
MIT
function removeSubscriber(cb) { const index = resizeSubscribers.indexOf(cb); if (index > -1) { resizeSubscribers.splice(index, 1); } }
Helper for removing the given callback from the list of subscribers. @param {Function} cb - Subscriber callback function
removeSubscriber
javascript
uber/react-vis
packages/react-vis/src/make-vis-flexible.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/make-vis-flexible.js
MIT
function getDisplayName(Component) { return Component.displayName || Component.name || 'Component'; }
Helper for getting a display name for the child component @param {*} Component React class for the child component. @returns {String} The child components name
getDisplayName
javascript
uber/react-vis
packages/react-vis/src/make-vis-flexible.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/make-vis-flexible.js
MIT
function makeFlexible(Component, isWidthFlexible, isHeightFlexible) { const ResultClass = class extends React.Component { static get propTypes() { const {height, width, ...otherPropTypes} = Component.propTypes; // eslint-disable-line no-unused-vars return otherPropTypes; } constructor(props) ...
Add the ability to stretch the visualization on window resize. @param {*} Component React class for the child component. @returns {*} Flexible component.
makeFlexible
javascript
uber/react-vis
packages/react-vis/src/make-vis-flexible.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/make-vis-flexible.js
MIT
componentDidMount() { this._onResize(); this.cancelSubscription = subscribeToDebouncedResize(this._onResize); }
Get the width of the container and assign the width. @private
componentDidMount
javascript
uber/react-vis
packages/react-vis/src/make-vis-flexible.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/make-vis-flexible.js
MIT
function getAxes(props) { const {animation, domains, style, tickFormat} = props; return domains.map((domain, index) => { const sortedDomain = domain.domain; const domainTickFormat = t => { return domain.tickFormat ? domain.tickFormat(t) : tickFormat(t); }; return ( <DecorativeAxis ...
Generate axes for each of the domains @param {Object} props - props.animation {Boolean} - props.domains {Array} array of object specifying the way each axis is to be plotted - props.style {object} style object for the whole chart - props.tickFormat {Function} formatting function for axes @return {Array} the plotted...
getAxes
javascript
uber/react-vis
packages/react-vis/src/parallel-coordinates/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/parallel-coordinates/index.js
MIT
function getLabels(props) { const {domains, style} = props; return domains.map(domain => { return { x: domain.name, y: 1.1, label: domain.name, style }; }); }
Generate labels for the ends of the axes @param {Object} props - props.domains {Array} array of object specifying the way each axis is to be plotted - props.style {object} style object for just the labels @return {Array} the prepped data for the labelSeries
getLabels
javascript
uber/react-vis
packages/react-vis/src/parallel-coordinates/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/parallel-coordinates/index.js
MIT
function getLines(props) { const { animation, brushFilters, colorRange, domains, data, style, showMarks } = props; const scales = domains.reduce((acc, {domain, name}) => { acc[name] = scaleLinear() .domain(domain) .range([0, 1]); return acc; }, {}); // const ...
Generate the actual lines to be plotted @param {Object} props - props.animation {Boolean} - props.data {Array} array of object specifying what values are to be plotted - props.domains {Array} array of object specifying the way each axis is to be plotted - props.style {object} style object for the whole chart - pro...
getLines
javascript
uber/react-vis
packages/react-vis/src/parallel-coordinates/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/parallel-coordinates/index.js
MIT
function defaultTitleFormat(values) { const value = getFirstNonEmptyValue(values); if (value) { return { title: 'x', value: transformValueToString(value.x) }; } }
Format title by detault. @param {Array} values List of values. @returns {*} Formatted value or undefined.
defaultTitleFormat
javascript
uber/react-vis
packages/react-vis/src/plot/crosshair.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/crosshair.js
MIT
function defaultItemsFormat(values) { return values.map((v, i) => { if (v) { return {value: v.y, title: i}; } }); }
Format items by default. @param {Array} values Array of values. @returns {*} Formatted list of items.
defaultItemsFormat
javascript
uber/react-vis
packages/react-vis/src/plot/crosshair.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/crosshair.js
MIT
function getFirstNonEmptyValue(values) { return (values || []).find(v => Boolean(v)); }
Get the first non-empty item from an array. @param {Array} values Array of values. @returns {*} First non-empty value or undefined.
getFirstNonEmptyValue
javascript
uber/react-vis
packages/react-vis/src/plot/crosshair.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/crosshair.js
MIT
_renderCrosshairItems() { const {values, itemsFormat} = this.props; const items = itemsFormat(values); if (!items) { return null; } return items .filter(i => i) .map(function renderValue(item, i) { return ( <div className="rv-crosshair__item" key={`item${i}`}> ...
Render crosshair items (title + value for each series). @returns {*} Array of React classes with the crosshair values. @private
_renderCrosshairItems
javascript
uber/react-vis
packages/react-vis/src/plot/crosshair.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/crosshair.js
MIT
_renderCrosshairTitle() { const {values, titleFormat, style} = this.props; const titleItem = titleFormat(values); if (!titleItem) { return null; } return ( <div className="rv-crosshair__title" key="title" style={style.title}> <span className="rv-crosshair__title__title">{titleIte...
Render crosshair title. @returns {*} Container with the crosshair title. @private
_renderCrosshairTitle
javascript
uber/react-vis
packages/react-vis/src/plot/crosshair.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/crosshair.js
MIT
function defaultFormat(value) { return Object.keys(value).map(function getProp(key) { return {title: key, value: transformValueToString(value[key])}; }); }
Default format function for the value. @param {Object} value Value. @returns {Array} title-value pairs.
defaultFormat
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getAlign(x, y) { const { innerWidth, innerHeight, orientation, align: {horizontal, vertical} } = this.props; const align = orientation ? this._mapOrientationToAlign(orientation) : {horizontal, vertical}; if (horizontal === ALIGN.AUTO) { align.horizontal = x > i...
Obtain align object with horizontal and vertical settings but convert any AUTO values to the non-auto ALIGN depending on the values of x and y. @param {number} x X value. @param {number} y Y value. @returns {Object} Align object w/ horizontal, vertical prop strings. @private
_getAlign
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getAlignClassNames(align) { const {orientation} = this.props; const orientationClass = orientation ? `rv-hint--orientation-${orientation}` : ''; return `${orientationClass} rv-hint--horizontalAlign-${align.horizontal} rv-hint--verticalAlign-${align.vertical}`; }
Get the class names from align values. @param {Object} align object with horizontal and vertical prop strings. @returns {string} Class names. @private
_getAlignClassNames
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getAlignStyle(align, x, y) { return { ...this._getXCSS(align.horizontal, x), ...this._getYCSS(align.vertical, y) }; }
Get a CSS mixin for a proper positioning of the element. @param {Object} align object with horizontal and vertical prop strings. @param {number} x X position. @param {number} y Y position. @returns {Object} Object, that may contain `left` or `right, `top` or `bottom` properties. @private
_getAlignStyle
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getCSSBottom(y) { if (y === undefined || y === null) { return { bottom: 0 }; } const {innerHeight, marginBottom} = this.props; return { bottom: marginBottom + innerHeight - y }; }
Get the bottom coordinate of the hint. When y undefined or null, edge case, pin bottom. @param {number} y Y. @returns {{bottom: *}} Mixin. @private
_getCSSBottom
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getCSSLeft(x) { if (x === undefined || x === null) { return { left: 0 }; } const {marginLeft} = this.props; return { left: marginLeft + x }; }
Get the left coordinate of the hint. When x undefined or null, edge case, pin left. @param {number} x X. @returns {{left: *}} Mixin. @private
_getCSSLeft
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getCSSRight(x) { if (x === undefined || x === null) { return { right: 0 }; } const {innerWidth, marginRight} = this.props; return { right: marginRight + innerWidth - x }; }
Get the right coordinate of the hint. When x undefined or null, edge case, pin right. @param {number} x X. @returns {{right: *}} Mixin. @private
_getCSSRight
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getCSSTop(y) { if (y === undefined || y === null) { return { top: 0 }; } const {marginTop} = this.props; return { top: marginTop + y }; }
Get the top coordinate of the hint. When y undefined or null, edge case, pin top. @param {number} y Y. @returns {{top: *}} Mixin. @private
_getCSSTop
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
_getPositionInfo() { const {value, getAlignStyle} = this.props; const x = getAttributeFunctor(this.props, 'x')(value); const y = getAttributeFunctor(this.props, 'y')(value); const align = this._getAlign(x, y); return { position: getAlignStyle ? getAlignStyle(align, x, y) : t...
Get the position for the hint and the appropriate class name. @returns {{style: Object, positionClassName: string}} Style and className for the hint. @private
_getPositionInfo
javascript
uber/react-vis
packages/react-vis/src/plot/hint.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/hint.js
MIT
function cleanseData(data) { return data.map(series => { if (!Array.isArray(series)) { return series; } return series.map(row => ({...row, parent: null})); }); }
Remove parents from tree formatted data. deep-equal doesnt play nice with data that has circular structures, so we make every node single directional by pruning the parents. @param {Array} data - the data object to have circular deps resolved in @returns {Array} the sanitized data
cleanseData
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
function checkIfMixinsAreEqual(nextScaleMixins, scaleMixins, hasTreeStructure) { const newMixins = { ...nextScaleMixins, _allData: hasTreeStructure ? cleanseData(nextScaleMixins._allData) : nextScaleMixins._allData }; const oldMixins = { ...scaleMixins, _allData: hasTreeStructure ...
Wrapper on the deep-equal method for checking equality of next props vs current props @param {Object} scaleMixins - Scale object. @param {Object} nextScaleMixins - Scale object. @param {Boolean} hasTreeStructure - Whether or not to cleanse the data of possible cyclic structures @returns {Boolean} whether or not the two...
checkIfMixinsAreEqual
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
_getClonedChildComponents() { const props = this.props; const {animation} = this.props; const {scaleMixins, data} = this.state; const dimensions = getInnerDimensions(this.props, DEFAULT_MARGINS); const children = React.Children.toArray(this.props.children); const seriesProps = getSeriesPropsFrom...
Prepare the child components (including series) for rendering. @returns {Array} Array of child components. @private
_getClonedChildComponents
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
static _getDefaultScaleProps(props) { const {innerWidth, innerHeight} = getInnerDimensions( props, DEFAULT_MARGINS ); const colorRanges = ['color', 'fill', 'stroke'].reduce((acc, attr) => { const range = props[`${attr}Type`] === 'category' ? EXTENDED_DISCRETE_COLOR_RANGE...
Get the list of scale-related settings that should be applied by default. @param {Object} props Object of props. @returns {Object} Defaults. @private
_getDefaultScaleProps
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
static _getScaleMixins(data, props) { const filteredData = data.filter(d => d); const allData = [].concat(...filteredData); const defaultScaleProps = XYPlot._getDefaultScaleProps(props); const optionalScaleProps = getOptionalScaleProps(props); const userScaleProps = extractScalePropsFromProps(props...
Get the map of scales from the props, apply defaults to them and then pass them further. @param {Object} data Array of all data. @param {Object} props Props of the component. @returns {Object} Map of scale-related props. @private
_getScaleMixins
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
_isPlotEmpty() { const {data} = this.state; return ( !data || !data.length || !data.some(series => series && series.some(d => d)) ); }
Checks if the plot is empty or not. Currently checks the data only. @returns {boolean} True for empty. @private
_isPlotEmpty
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
renderCanvasComponents(components) { const componentsToRender = components.filter( c => c && !c.type.requiresSVG && c.type.isCanvas ); if (componentsToRender.length === 0) { return null; } const { marginLeft, marginTop, marginBottom, marginRight, innerHeigh...
Trigger touch-start related callbacks if they are available. @param {React.SyntheticEvent} event Touch start event. @private
renderCanvasComponents
javascript
uber/react-vis
packages/react-vis/src/plot/xy-plot.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/xy-plot.js
MIT
_areTicksWrapped() { const {orientation} = this.props; return orientation === LEFT || orientation === TOP; }
Check if axis ticks should be mirrored (for the right and top positions. @returns {boolean} True if mirrored. @private
_areTicksWrapped
javascript
uber/react-vis
packages/react-vis/src/plot/axis/axis-ticks.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/axis-ticks.js
MIT
_getTickLabelProps() { const { orientation, tickLabelAngle, tickSize, tickSizeOuter = tickSize, tickPadding = tickSize } = this.props; // Assign the text orientation inside the label of the tick mark. let textAnchor; if (orientation === LEFT || (orientation === BOTTOM ...
Get attributes for the label of the tick. @returns {Object} Object with properties. @private
_getTickLabelProps
javascript
uber/react-vis
packages/react-vis/src/plot/axis/axis-ticks.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/axis-ticks.js
MIT
_getTickLineProps() { const { tickSize, tickSizeOuter = tickSize, tickSizeInner = tickSize } = this.props; const isVertical = this._isAxisVertical(); const tickXAttr = isVertical ? 'y' : 'x'; const tickYAttr = isVertical ? 'x' : 'y'; const wrap = this._areTicksWrapped() ? -1 : ...
Get the props of the tick line. @returns {Object} Props. @private
_getTickLineProps
javascript
uber/react-vis
packages/react-vis/src/plot/axis/axis-ticks.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/axis-ticks.js
MIT
_isAxisVertical() { const {orientation} = this.props; return orientation === LEFT || orientation === RIGHT; }
Gets if the axis is vertical. @returns {boolean} True if vertical. @private
_isAxisVertical
javascript
uber/react-vis
packages/react-vis/src/plot/axis/axis-ticks.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/axis-ticks.js
MIT
transformation = (width, height) => ({ [LEFT]: { end: { x: ADJUSTMENT_FOR_TEXT_SIZE, y: MARGIN, rotation: -90, textAnchor: 'end' }, middle: { x: ADJUSTMENT_FOR_TEXT_SIZE, y: height / 2 - MARGIN, rotation: -90, textAnchor: 'middle' }, start: { x...
Compute transformations, keyed by orientation @param {number} width - width of axis @param {number} height - height of axis @returns {Object} Object of transformations, keyed by orientation
transformation
javascript
uber/react-vis
packages/react-vis/src/plot/axis/axis-title.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/axis-title.js
MIT
_getDefaultAxisProps() { const { innerWidth, innerHeight, marginTop, marginBottom, marginLeft, marginRight, orientation } = this.props; if (orientation === BOTTOM) { return { tickTotal: getTicksTotalFromSize(innerWidth), top: innerHeight + marg...
Define the default values depending on the data passed from the outside. @returns {*} Object of default properties. @private
_getDefaultAxisProps
javascript
uber/react-vis
packages/react-vis/src/plot/axis/axis.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/axis.js
MIT
function decorativeAxisTick(props) { const { axisDomain, numberOfTicks, axisStart, axisEnd, tickValue, tickSize, style } = props; const {points} = generatePoints({ axisStart, axisEnd, numberOfTicks, axisDomain }); // add a quarter rotation to make ticks orthogonal t...
Generate the actual polygons to be plotted @param {Object} props - props.animation {Boolean} - props.axisDomain {Array} a pair of values specifying the domain of the axis - props.numberOfTicks{Number} the number of ticks on the axis - props.axisStart {Object} a object specify in cartesian space the start of the axi...
decorativeAxisTick
javascript
uber/react-vis
packages/react-vis/src/plot/axis/decorative-axis-ticks.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/axis/decorative-axis-ticks.js
MIT
static getParentConfig() { return {}; }
Get a default config for the parent. @returns {Object} Empty config.
getParentConfig
javascript
uber/react-vis
packages/react-vis/src/plot/series/abstract-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/abstract-series.js
MIT
static get requiresSVG() { return true; }
Tells the rest of the world that it requires SVG to work. @returns {boolean} Result.
requiresSVG
javascript
uber/react-vis
packages/react-vis/src/plot/series/abstract-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/abstract-series.js
MIT
_getAttr0Functor(attr) { return getAttr0Functor(this.props, attr); }
Get the attr0 functor. @param {string} attr Attribute name. @returns {*} Functor. @private
_getAttr0Functor
javascript
uber/react-vis
packages/react-vis/src/plot/series/abstract-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/abstract-series.js
MIT
_getAttributeFunctor(attr) { return getAttributeFunctor(this.props, attr); }
Get attribute functor. @param {string} attr Attribute name @returns {*} Functor. @protected
_getAttributeFunctor
javascript
uber/react-vis
packages/react-vis/src/plot/series/abstract-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/abstract-series.js
MIT
_getAttributeValue(attr) { return getAttributeValue(this.props, attr); }
Get the attribute value if it is available. @param {string} attr Attribute name. @returns {*} Attribute value if available, fallback value or undefined otherwise. @protected
_getAttributeValue
javascript
uber/react-vis
packages/react-vis/src/plot/series/abstract-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/abstract-series.js
MIT
_getScaleDistance(attr) { const scaleObject = getScaleObjectFromProps(this.props, attr); return scaleObject ? scaleObject.distance : 0; }
Get the scale object distance by the attribute from the list of properties. @param {string} attr Attribute name. @returns {number} Scale distance. @protected
_getScaleDistance
javascript
uber/react-vis
packages/react-vis/src/plot/series/abstract-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/abstract-series.js
MIT
function modifyRow(row) { const {radius, angle, angle0} = row; const truedAngle = -1 * angle + Math.PI / 2; const truedAngle0 = -1 * angle0 + Math.PI / 2; return { ...row, x: radius * Math.cos(truedAngle), y: radius * Math.sin(truedAngle), angle: truedAngle, angle0: truedAngle0 }; }
Prepare the internal representation of row for real use. This is necessary because d3 insists on starting at 12 oclock and moving clockwise, rather than starting at 3 oclock and moving counter clockwise as one might expect from polar @param {Object} row - coordinate object to be modifed @return {Object} angle corrected...
modifyRow
javascript
uber/react-vis
packages/react-vis/src/plot/series/arc-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/arc-series.js
MIT
_getAllScaleProps(props) { const defaultScaleProps = this._getDefaultScaleProps(props); const userScaleProps = extractScalePropsFromProps(props, ATTRIBUTES); const missingScaleProps = getMissingScaleProps( { ...defaultScaleProps, ...userScaleProps }, props.data, ATTRI...
Get the map of scales from the props. @param {Object} props Props. @param {Array} data Array of all data. @returns {Object} Map of scales. @private
_getAllScaleProps
javascript
uber/react-vis
packages/react-vis/src/plot/series/arc-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/arc-series.js
MIT
function engageDrawLoop(ctx, height, width, layers) { let drawIteration = 0; // using setInterval because request animation frame goes too fast const drawCycle = setInterval(() => { if (!ctx) { clearInterval(drawCycle); return; } drawLayers(ctx, height, width, layers, drawIteration); i...
Draw loop draws each of the layers until it should draw more @param {CanvasContext} ctx - the context where the drawing will take place @param {Number} height - height of the canvas @param {Number} width - width of the canvas @param {Array} layers - the layer objects to render
engageDrawLoop
javascript
uber/react-vis
packages/react-vis/src/plot/series/canvas-wrapper.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/canvas-wrapper.js
MIT
function drawLayers(ctx, height, width, layers, drawIteration) { ctx.clearRect(0, 0, width, height); layers.forEach(layer => { const {interpolator, newProps, animation} = layer; // return an empty object if dont need to be animating const interpolatedProps = animation ? interpolator ? inte...
Loops across each of the layers to be drawn and draws them @param {CanvasContext} ctx - the context where the drawing will take place @param {Number} height - height of the canvas @param {Number} width - width of the canvas @param {Array} layers - the layer objects to render @param {Number} drawIteration - width of the...
drawLayers
javascript
uber/react-vis
packages/react-vis/src/plot/series/canvas-wrapper.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/canvas-wrapper.js
MIT
function buildLayers(newChildren, oldChildren) { return newChildren.map((child, index) => { const oldProps = oldChildren[index] ? oldChildren[index].props : {}; const newProps = child.props; const oldAnimatedProps = extractAnimatedPropValues({ ...oldProps, animatedProps: ANIMATED_SERIES_PROPS...
Build an array of layer of objects the contain the method for drawing each series as well as an interpolar (specifically a d3-interpolate interpolator) @param {Object} newChildren the new children to be rendered. @param {Object} oldChildren the old children to be rendered. @returns {Array} Object for rendering
buildLayers
javascript
uber/react-vis
packages/react-vis/src/plot/series/canvas-wrapper.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/canvas-wrapper.js
MIT
drawChildren(oldProps, newProps, ctx) { const { children, innerHeight, innerWidth, marginBottom, marginLeft, marginRight, marginTop } = newProps; if (!ctx) { return; } const childrenShouldAnimate = children.find(child => child.props.animation); c...
Check that we can and should be animating, then kick off animations as apporpriate @param {Object} newProps the new props to be interpolated to @param {Object} oldProps the old props to be interpolated against @param {DomRef} ctx the canvas context to be drawn on. @returns {Array} Object for rendering
drawChildren
javascript
uber/react-vis
packages/react-vis/src/plot/series/canvas-wrapper.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/canvas-wrapper.js
MIT
renderWhiskerMark = whiskerMarkProps => (d, i) => { const { crossBarWidth, opacityFunctor, sizeFunctor, strokeFunctor, strokeWidth, style, valueClickHandler, valueMouseOutHandler, valueMouseOverHandler, valueRightClickHandler, xFunctor, yFunctor } = whiskerMarkProps; ...
Render whisker lines for a data point. @param {Object} whiskerMarkProps All the properties of the whisker mark. @private
renderWhiskerMark
javascript
uber/react-vis
packages/react-vis/src/plot/series/whisker-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/whisker-series.js
MIT
render() { const { animation, className, crossBarWidth, data, marginLeft, marginTop, strokeWidth, style } = this.props; if (!data) { return null; } if (animation) { return ( <Animation {...this.props} animatedProps={ANIMATED_SERIES_...
Determine whether on not we should draw whiskers in each direction. We need to see an actual variance value, and also have that value extend past the radius "buffer" region in which we won't be drawing (if any).
render
javascript
uber/react-vis
packages/react-vis/src/plot/series/whisker-series.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/plot/series/whisker-series.js
MIT
function getAxes(props) { const { animation, domains, startingAngle, style, tickFormat, hideInnerMostValues } = props; return domains.map((domain, index) => { const angle = (index / domains.length) * Math.PI * 2 + startingAngle; const sortedDomain = domain.domain; const domain...
Generate axes for each of the domains @param {Object} props - props.animation {Boolean} - props.domains {Array} array of object specifying the way each axis is to be plotted - props.style {object} style object for the whole chart - props.tickFormat {Function} formatting function for axes - props.startingAngle {num...
getAxes
javascript
uber/react-vis
packages/react-vis/src/radar-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radar-chart/index.js
MIT
function getCoordinate(axisEndPoint) { const epsilon = 10e-13; if (Math.abs(axisEndPoint) <= epsilon) { axisEndPoint = 0; } else if (axisEndPoint > 0) { if (Math.abs(axisEndPoint - 0.5) <= epsilon) { axisEndPoint = 0.5; } } else if (axisEndPoint < 0) { if (Math.abs(axisEndPoint + 0.5) <= e...
Generate x or y coordinate for axisEnd @param {Number} axisEndPoint - epsilon is an arbitrarily chosen small number to approximate axisEndPoints - to true values resulting from trigonometry functions (sin, cos) on angles @return {Number} the x or y coordinate accounting for exact trig values
getCoordinate
javascript
uber/react-vis
packages/react-vis/src/radar-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radar-chart/index.js
MIT
function getLabels(props) { const {domains, startingAngle, style} = props; return domains.map(({name}, index) => { const angle = (index / domains.length) * Math.PI * 2 + startingAngle; const radius = 1.2; return { x: radius * Math.cos(angle), y: radius * Math.sin(angle), label: name, ...
Generate labels for the ends of the axes @param {Object} props - props.domains {Array} array of object specifying the way each axis is to be plotted - props.startingAngle {number} the initial angle offset - props.style {object} style object for just the labels @return {Array} the prepped data for the labelSeries
getLabels
javascript
uber/react-vis
packages/react-vis/src/radar-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radar-chart/index.js
MIT
function getPolygons(props) { const { animation, colorRange, domains, data, style, startingAngle, onSeriesMouseOver, onSeriesMouseOut } = props; const scales = domains.reduce((acc, {domain, name}) => { acc[name] = scaleLinear() .domain(domain) .range([0, 1]); r...
Generate the actual polygons to be plotted @param {Object} props - props.animation {Boolean} - props.data {Array} array of object specifying what values are to be plotted - props.domains {Array} array of object specifying the way each axis is to be plotted - props.startingAngle {number} the initial angle offset - ...
getPolygons
javascript
uber/react-vis
packages/react-vis/src/radar-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radar-chart/index.js
MIT
function getPolygonPoints(props) { const { animation, domains, data, startingAngle, style, onValueMouseOver, onValueMouseOut } = props; if (!onValueMouseOver) { return; } const scales = domains.reduce((acc, {domain, name}) => { acc[name] = scaleLinear() .domain(domain...
Generate circles at the polygon points for Hover functionality @param {Object} props - props.animation {Boolean} - props.data {Array} array of object specifying what values are to be plotted - props.domains {Array} array of object specifying the way each axis is to be plotted - props.startingAngle {number} the init...
getPolygonPoints
javascript
uber/react-vis
packages/react-vis/src/radar-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radar-chart/index.js
MIT
function getWedgesToRender({data, getAngle}) { const pie = pieBuilder() .sort(null) .value(getAngle); const pieData = pie(data).reverse(); return pieData.map((row, index) => { return { ...row.data, angle0: row.startAngle, angle: row.endAngle, radius0: row.data.innerRadius || 0,...
Create the list of wedges to render. @param {Object} props props.data {Object} - tree structured data (each node has a name anc an array of children) @returns {Array} Array of nodes.
getWedgesToRender
javascript
uber/react-vis
packages/react-vis/src/radial-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radial-chart/index.js
MIT
function getMaxRadius(width, height) { return Math.min(width, height) / 2 - DEFAULT_RADIUS_MARGIN; }
Get the max radius so the chart can extend to the margin. @param {Number} width - container width @param {Number} height - container height @return {Number} radius
getMaxRadius
javascript
uber/react-vis
packages/react-vis/src/radial-chart/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/radial-chart/index.js
MIT
function getNodesToRender({data, height, hideRootNode, width, getSize}) { const partitionFunction = partition(); const structuredInput = hierarchy(data).sum(getSize); const radius = Math.min(width, height) / 2 - 10; const x = scaleLinear().range([0, 2 * Math.PI]); const y = scaleSqrt().range([0, radius]); ...
Create the list of nodes to render. @param {Object} props props.data {Object} - tree structured data (each node has a name anc an array of children) props.height {number} - the height of the graphic to be rendered props.hideRootNode {boolean} - whether or not to hide the root node props.width {number} - the...
getNodesToRender
javascript
uber/react-vis
packages/react-vis/src/sunburst/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/sunburst/index.js
MIT
function buildLabels(mappedData, accessors) { const {getAngle, getAngle0, getLabel, getRadius0} = accessors; return mappedData.filter(getLabel).map(row => { const truedAngle = -1 * getAngle(row) + Math.PI / 2; const truedAngle0 = -1 * getAngle0(row) + Math.PI / 2; const angle = (truedAngle0 + truedAngl...
Convert arc nodes into label rows. Important to use mappedData rather than regular data, bc it is already unrolled @param {Array} mappedData - Array of nodes. @param {Object} accessors - object of accessors @returns {Array} array of node for rendering as labels
buildLabels
javascript
uber/react-vis
packages/react-vis/src/sunburst/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/sunburst/index.js
MIT
function _getScaleFns(props) { const {data} = props; const allData = data.children || []; // Adding _allData property to the object to reuse the existing // getAttributeFunctor function. const compatibleProps = { ...props, ...getMissingScaleProps(props, allData, ATTRIBUTES), _allData: allData }...
Get the map of scale functions from the given props. @param {Object} props Props for the component. @returns {Object} Map of scale functions. @private
_getScaleFns
javascript
uber/react-vis
packages/react-vis/src/treemap/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/treemap/index.js
MIT
function _getNodesToRender() { const {innerWidth, innerHeight} = innerDimensions; const {data, mode, padding, sortFunction, getSize} = props; if (!data) { return []; } if (mode === 'partition' || mode === 'partition-pivot') { const partitionFunction = partition() .size( ...
Create the list of nodes to render. @returns {Array} Array of nodes. @private
_getNodesToRender
javascript
uber/react-vis
packages/react-vis/src/treemap/index.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/treemap/index.js
MIT
function getTicksTotalFromSize(size) { if (size < 700) { if (size > 300) { return 10; } return 5; } return 20; }
Get total amount of ticks from a given size in pixels. @param {number} size Size of the axis in pixels. @returns {number} Total amount of ticks.
getTicksTotalFromSize
javascript
uber/react-vis
packages/react-vis/src/utils/axis-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/axis-utils.js
MIT
function getTickValues(scale, tickTotal, tickValues) { return !tickValues ? scale.ticks ? scale.ticks(tickTotal) : scale.domain() : tickValues; }
Get the tick values from a given d3 scale. @param {d3.scale} scale Scale function. @param {number} tickTotal Total number of ticks @param {Array} tickValues Array of tick values if they exist. @returns {Array} Array of tick values.
getTickValues
javascript
uber/react-vis
packages/react-vis/src/utils/axis-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/axis-utils.js
MIT
function generateFit(axisStart, axisEnd) { // address the special case when the slope is infinite if (axisStart.x === axisEnd.x) { return { left: axisStart.y, right: axisEnd.y, slope: 0, offset: axisStart.x }; } const slope = (axisStart.y - axisEnd.y) / (axisStart.x - axisEnd.x);...
Generate a description of a decorative axis in terms of a linear equation y = slope * x + offset in coordinates @param {Object} axisStart Object of format {x, y} describing in coordinates the start position of the decorative axis @param {Object} axisEnd Object of format {x, y} describing in coordinates the start positi...
generateFit
javascript
uber/react-vis
packages/react-vis/src/utils/axis-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/axis-utils.js
MIT
function generatePoints({ axisStart, axisEnd, numberOfTicks, axisDomain }) { const {left, right, slope, offset} = generateFit(axisStart, axisEnd); // construct a linear band of points, then map them const pointSlope = (right - left) / numberOfTicks; const axisScale = scaleLinear() .domain([left, rig...
Generate a description of a decorative axis in terms of a linear equation y = slope * x + offset in coordinates @param props props.@param {Object} axisStart Object of format {x, y} describing in coordinates the start position of the decorative axis props.@param {Object} axisEnd Object of format {x, y} describing in coo...
generatePoints
javascript
uber/react-vis
packages/react-vis/src/utils/axis-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/axis-utils.js
MIT
function getAxisAngle(axisStart, axisEnd) { if (axisStart.x === axisEnd.x) { return axisEnd.y > axisStart.y ? Math.PI / 2 : (3 * Math.PI) / 2; } return Math.atan((axisEnd.y - axisStart.y) / (axisEnd.x - axisStart.x)); }
Compute the angle (in radians) of a decorative axis @param {Object} axisStart Object of format {x, y} describing in coordinates the start position of the decorative axis @param {Object} axisEnd Object of format {x, y} describing in coordinates the start position of the decorative axis @returns {Number} Angle in radials
getAxisAngle
javascript
uber/react-vis
packages/react-vis/src/utils/axis-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/axis-utils.js
MIT
function getInnerDimensions(props, defaultMargins) { const {margin, width, height} = props; const marginProps = { ...defaultMargins, ...(typeof margin === 'number' ? { left: margin, right: margin, top: margin, bottom: margin } : margin) }; cons...
Get the dimensions of the component for the future use. @param {Object} props Props. @param {Object} defaultMargins Object with default margins. @returns {Object} Dimensions of the component.
getInnerDimensions
javascript
uber/react-vis
packages/react-vis/src/utils/chart-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/chart-utils.js
MIT
function getRadialLayoutMargin(width, height, radius) { const marginX = width / 2 - radius; const marginY = height / 2 - radius; return { bottom: marginY, left: marginX, right: marginX, top: marginY }; }
Calculate the margin of the sunburst, so it can be at the center of the container @param {Number} width - the width of the container @param {Number} height - the height of the container @param {Number} radius - the max radius of the sunburst @return {Object} an object includes {bottom, left, right, top}
getRadialLayoutMargin
javascript
uber/react-vis
packages/react-vis/src/utils/chart-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/chart-utils.js
MIT
function getUniquePropertyValues(arr, accessor) { const setOfValues = new Set(arr.map(accessor)); return Array.from(setOfValues); }
Get unique property values from an array. @param {Array} arr Array of data. @param {string} propertyName Prop name. @returns {Array} Array of unique values.
getUniquePropertyValues
javascript
uber/react-vis
packages/react-vis/src/utils/data-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/data-utils.js
MIT
function addValueToArray(arr, value) { const result = [].concat(arr); if (result[0] > value) { result[0] = value; } if (result[result.length - 1] < value) { result[result.length - 1] = value; } return result; }
Add zero to the domain. @param {Array} arr Add zero to the domain. @param {Number} value Add zero to domain. @returns {Array} Adjusted domain.
addValueToArray
javascript
uber/react-vis
packages/react-vis/src/utils/data-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/data-utils.js
MIT
function transformValueToString(value) { return Object.prototype.toString.call(value) === '[object Date]' ? value.toDateString() : value; }
Transforms a value ( number or date ) to a string. @param {Date | number} value The value as date or number. @returns {string | number} The value as string.
transformValueToString
javascript
uber/react-vis
packages/react-vis/src/utils/data-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/data-utils.js
MIT
getDOMNode = ref => { if (!isReactDOMSupported()) { return ref && ref.getDOMNode(); } return ref; }
Support React 0.13 and greater where refs are React components, not DOM nodes. @param {*} ref React's ref. @returns {Element} DOM element.
getDOMNode
javascript
uber/react-vis
packages/react-vis/src/utils/react-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/react-utils.js
MIT
function warning(message, onlyShowMessageOnce = false) { /* eslint-disable no-undef, no-process-env */ if (global.process && HIDDEN_PROCESSES[process.env.NODE_ENV]) { return; } /* eslint-enable no-undef, no-process-env */ if (!onlyShowMessageOnce || !USED_MESSAGES[message]) { /* eslint-disable no-cons...
Warn the user about something @param {String} message - the message to be shown @param {Boolean} onlyShowMessageOnce - whether or not we allow the - message to be show multiple times
warning
javascript
uber/react-vis
packages/react-vis/src/utils/react-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/react-utils.js
MIT
function warnOnce(message) { warning(message, true); }
Convience wrapper for warning @param {String} message - the message to be shown
warnOnce
javascript
uber/react-vis
packages/react-vis/src/utils/react-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/react-utils.js
MIT
function toTitleCase(str) { return `${str[0].toUpperCase()}${str.slice(1)}`; }
Title case a given string @param {String} str Array of values. @returns {String} titlecased string
toTitleCase
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _getSmallestDistanceIndex(values, scaleObject) { const scaleFn = getScaleFnFromScaleObject(scaleObject); let result = 0; if (scaleFn) { let nextValue; let currentValue = scaleFn(values[0]); let distance = Infinity; let nextDistance; for (let i = 1; i < values.length; i++) { nex...
Find the smallest distance between the values on a given scale and return the index of the element, where the smallest distance was found. It returns the first occurrence of i where `scale(value[i]) - scale(value[i - 1])` is minimal @param {Array} values Array of values. @param {Object} scaleObject Scale object. @retur...
_getSmallestDistanceIndex
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function addInvertFunctionToOrdinalScaleObject(scale) { if (scale.invert) { return; } scale.invert = function invert(value) { const [lower, upper] = scale.range(); const start = Math.min(lower, upper); const stop = Math.max(lower, upper); if (value < start + scale.padding() * scale.step()) {...
This is a workaround for issue that ordinal scale does not have invert method implemented in d3-scale. @param {Object} Ordinal d3-scale object. @returns {void} @private
addInvertFunctionToOrdinalScaleObject
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getScaleFnFromScaleObject(scaleObject) { if (!scaleObject) { return null; } const {type, domain, range} = scaleObject; const modDomain = domain[0] === domain[1] ? domain[0] === 0 ? [-1, 0] : [-domain[0], domain[0]] : domain; if (type === LITERAL_SCALE_TYPE) { r...
Crate a scale function from the scale object. @param {Object} scaleObject Scale object. - scaleObject.domain {Array} - scaleObject.range {Array} - scaleObject.type {string} - scaleObject.attr {string} @returns {*} Scale function. @private
getScaleFnFromScaleObject
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getDomainByAccessor(allData, accessor, accessor0, type) { let domain; // Collect both attr and available attr0 values from the array of data. const values = allData.reduce((data, d) => { const value = accessor(d); const value0 = accessor0(d); if (_isDefined(value)) { data.push(value); ...
Get the domain from the array of data. @param {Array} allData All data. @param {function} accessor - accessor for main value. @param {function} accessor0 - accessor for the naught value. @param {string} type Scale type. @returns {Array} Domain. @private
getDomainByAccessor
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _createScaleObjectForValue(attr, value, type, accessor, accessor0) { if (type === LITERAL_SCALE_TYPE) { return { type: LITERAL_SCALE_TYPE, domain: [], range: [value], distance: 0, attr, baseValue: undefined, isValue: true, accessor, accessor0 }; ...
Create custom scale object from the value. When the scale is created from this object, it should return the same value all time. @param {string} attr Attribute. @param {*} value Value. @param {string} type - the type of scale being used @param {function} accessor - the accessor function @param {function} accessor0 - th...
_createScaleObjectForValue
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _createScaleObjectForFunction({ domain, range, type, distance, attr, baseValue, accessor, accessor0 }) { return { domain, range, type, distance, attr, baseValue, isValue: false, accessor, accessor0 }; }
Create a regular scale object for a further use from the existing parameters. @param {Array} domain - Domain. @param {Array} range - Range. @param {string} type - Type. @param {number} distance - Distance. @param {string} attr - Attribute. @param {number} baseValue - Base value. @param {function} accessor - Attribute a...
_createScaleObjectForFunction
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _collectScaleObjectFromProps(props, attr) { const { [attr]: value, [`_${attr}Value`]: fallbackValue, [`${attr}Range`]: range, [`${attr}Distance`]: distance = 0, [`${attr}BaseValue`]: baseValue, [`${attr}Type`]: type = LINEAR_SCALE_TYPE, [`${attr}NoFallBack`]: noFallBack, [`get...
Get scale object from props. E. g. object like {xRange, xDomain, xDistance, xType} is transformed into {range, domain, distance, type}. @param {Object} props Props. @param {string} attr Attribute. @returns {*} Null or an object with the scale. @private
_collectScaleObjectFromProps
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _computeLeftDomainAdjustment(values) { if (values.length > 1) { return (values[1] - values[0]) / 2; } if (values.length === 1) { return values[0] - 0.5; } return 0; }
Compute left domain adjustment for the given values. @param {Array} values Array of values. @returns {number} Domain adjustment. @private
_computeLeftDomainAdjustment
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _computeRightDomainAdjustment(values) { if (values.length > 1) { return (values[values.length - 1] - values[values.length - 2]) / 2; } if (values.length === 1) { return values[0] - 0.5; } return 0; }
Compute right domain adjustment for the given values. @param {Array} values Array of values. @returns {number} Domain adjustment. @private
_computeRightDomainAdjustment
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _computeScaleDistance(values, domain, bestDistIndex, scaleFn) { if (values.length > 1) { // Avoid zero indexes. const i = Math.max(bestDistIndex, 1); return Math.abs(scaleFn(values[i]) - scaleFn(values[i - 1])); } if (values.length === 1) { return Math.abs(scaleFn(domain[1]) - scaleFn(dom...
Compute distance for the given values. @param {Array} values Array of values. @param {Array} domain Domain. @param {number} bestDistIndex Index of a best distance found. @param {function} scaleFn Scale function. @returns {number} Domain adjustment. @private
_computeScaleDistance
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _normalizeValues(data, values, accessor0, type) { if (type === TIME_SCALE_TYPE && values.length === 1) { const attr0 = accessor0(data[0]); return [attr0, ...values]; } return values; }
Normilize array of values with a single value. @param {Array} arr Array of data. @param {Array} values Array of values. @param {string} attr Attribute. @param {string} type Type. @private
_normalizeValues
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _getScaleDistanceAndAdjustedDomain(data, scaleObject) { const {domain, type, accessor, accessor0} = scaleObject; const uniqueValues = getUniquePropertyValues(data, accessor); // Fix time scale if a data has only one value. const values = _normalizeValues(data, uniqueValues, accessor0, type); const ...
Get the distance, the smallest and the largest value of the domain. @param {Array} data Array of data for the single series. @param {Object} scaleObject Scale object. @returns {{domain0: number, domainN: number, distance: number}} Result. @private
_getScaleDistanceAndAdjustedDomain
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _isScaleAdjustmentPossible(props, scaleObject) { const {attr} = scaleObject; const {_adjustBy: adjustBy = [], _adjustWhat: adjustWhat = []} = props; // The scale cannot be adjusted if there's no attributes to adjust, no // suitable values return adjustWhat.length && adjustBy.length && adjustBy.index...
Returns true if scale adjustments are possible for a given scale. @param {Object} props Props. @param {Object} scaleObject Scale object. @returns {boolean} True if scale adjustments possible. @private
_isScaleAdjustmentPossible
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _adjustContinuousScale(props, scaleObject) { const {_allData: allSeriesData, _adjustWhat: adjustWhat = []} = props; // Assign the initial values. const domainLength = scaleObject.domain.length; const {domain} = scaleObject; let scaleDomain0 = domain[0]; let scaleDomainN = domain[domainLength - 1];...
Adjust continuous scales (e.g. 'linear', 'log' and 'time') by adding the space from the left and right of them and by computing the best distance. @param {Object} props Props. @param {Object} scaleObject Scale object. @returns {*} Scale object with adjustments. @private
_adjustContinuousScale
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _adjustCategoricalScale(scaleObject) { const scaleFn = getScaleFnFromScaleObject(scaleObject); const {domain, range} = scaleObject; if (domain.length > 1) { scaleObject.distance = Math.abs(scaleFn(domain[1]) - scaleFn(domain[0])); } else { scaleObject.distance = Math.abs(range[1] - range[0]); ...
Get an adjusted scale. Suitable for 'category' and 'ordinal' scales. @param {Object} scaleObject Scale object. @returns {*} Scale object with adjustments. @private
_adjustCategoricalScale
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getScaleObjectFromProps(props, attr) { // Create the initial scale object. const scaleObject = _collectScaleObjectFromProps(props, attr); if (!scaleObject) { return null; } // Make sure if it's possible to add space to the scale object. If not, // return the object immediately. if (!_isScale...
Retrieve a scale object or a value from the properties passed. @param {Object} props Object of props. @param {string} attr Attribute. @returns {*} Scale object, value or null.
getScaleObjectFromProps
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getAttributeScale(props, attr) { const scaleObject = getScaleObjectFromProps(props, attr); return getScaleFnFromScaleObject(scaleObject); }
Get d3 scale for a given prop. @param {Object} props Props. @param {string} attr Attribute. @returns {function} d3 scale function.
getAttributeScale
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function _getAttrValue(d, accessor) { return accessor(d.data ? d.data : d); }
Get the value of `attr` from the object. @param {Object} d - data Object. @param {Function} accessor - accessor function. @returns {*} Value of the point. @private
_getAttrValue
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getAttributeFunctor(props, attr) { const scaleObject = getScaleObjectFromProps(props, attr); if (scaleObject) { const scaleFn = getScaleFnFromScaleObject(scaleObject); return d => scaleFn(_getAttrValue(d, scaleObject.accessor)); } return null; }
Get prop functor (either a value or a function) for a given attribute. @param {Object} props Series props. @param {Function} accessor - Property accessor. @returns {*} Function or value.
getAttributeFunctor
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getAttr0Functor(props, attr) { const scaleObject = getScaleObjectFromProps(props, attr); if (scaleObject) { const {domain} = scaleObject; const {baseValue = domain[0]} = scaleObject; const scaleFn = getScaleFnFromScaleObject(scaleObject); return d => { const value = _getAttrValue(d, s...
Get the functor which extracts value form [attr]0 property. Use baseValue if no attr0 property for a given object is defined. Fall back to domain[0] if no base value is available. @param {Object} props Object of props. @param {string} attr Attribute name. @returns {*} Function which returns value or null if no values a...
getAttr0Functor
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getAttributeValue(props, attr) { const scaleObject = getScaleObjectFromProps(props, attr); if (scaleObject) { if (!scaleObject.isValue && props[`_${attr}Value`] === undefined) { warning( `[React-vis] Cannot use data defined ${attr} for this ` + 'series type. Using fallback value...
Tries to get the string|number value of the attr and falls back to a fallback property in case if the value is a scale. @param {Object} props Series props. @param {string} attr Property name. @returns {*} Function or value.
getAttributeValue
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function getScalePropTypesByAttribute(attr) { return { [`_${attr}Value`]: PropTypes.any, [`${attr}Domain`]: PropTypes.array, [`get${toTitleCase(attr)}`]: PropTypes.func, [`get${toTitleCase(attr)}0`]: PropTypes.func, [`${attr}Range`]: PropTypes.array, [`${attr}Type`]: PropTypes.oneOf(Object.key...
Get prop types by the attribute. @param {string} attr Attribute. @returns {Object} Object of xDomain, xRange, xType, xDistance and _xValue, where x is an attribute passed to the function.
getScalePropTypesByAttribute
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT
function extractScalePropsFromProps(props, attributes) { const result = {}; Object.keys(props).forEach(key => { // this filtering is critical for extracting the correct accessors! const attr = attributes.find(a => { // width const isPlainSet = key.indexOf(a) === 0; // Ex: _data const...
Extract the list of scale properties from the entire props object. @param {Object} props Props. @param {Array<String>} attributes Array of attributes for the given components (for instance, `['x', 'y', 'color']`). @returns {Object} Collected props.
extractScalePropsFromProps
javascript
uber/react-vis
packages/react-vis/src/utils/scales-utils.js
https://github.com/uber/react-vis/blob/master/packages/react-vis/src/utils/scales-utils.js
MIT