react-vis
Version:
Data visualization library based on React and d3.
550 lines (549 loc) • 18.4 kB
HTML
<html lang="en">
<head>
<title>Code coverage report for dist/lib/utils/series-utils.js</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="../../../prettify.css" />
<link rel="stylesheet" href="../../../base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(../../../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="../../../index.html">all files</a> / <a href="index.html">dist/lib/utils/</a> series-utils.js
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">75.34% </span>
<span class="quiet">Statements</span>
<span class='fraction'>55/73</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">37.04% </span>
<span class="quiet">Branches</span>
<span class='fraction'>10/27</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">69.23% </span>
<span class="quiet">Functions</span>
<span class='fraction'>9/13</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">76.67% </span>
<span class="quiet">Lines</span>
<span class='fraction'>46/60</span>
</div>
<div class='fl pad1y'>
<span class="strong">2 statements</span>
<span class="quiet">Ignored</span>
</div>
</div>
</div>
<div class='status-line medium'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161</td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">12×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (<span class="missing-if-branch" title="else path not taken" >E</span>Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
exports.isSeriesChild = isSeriesChild;
exports.getSeriesChildren = getSeriesChildren;
exports.getStackedData = getStackedData;
exports.getSeriesPropsFromChildren = getSeriesPropsFromChildren;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _abstractSeries = require('../plot/series/abstract-series');
var _abstractSeries2 = _interopRequireDefault(_abstractSeries);
var _theme = require('../theme');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
<span class="fstat-no" title="function not covered" >function _defineProperty(obj, key, value) {</span> if (<span class="cstat-no" title="statement not covered" >key in obj) { Object.<span class="cstat-no" title="statement not covered" >defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[<span class="cstat-no" title="statement not covered" >key] = value; } <span class="cstat-no" title="statement not covered" >r</span>eturn obj; }</span></span></span>
/**
* Check if the component is series or not.
* @param {React.Component} child Component.
* @returns {boolean} True if the child is series, false otherwise.
*/
function isSeriesChild(child) {
var prototype = child.type.prototype;
return prototype instanceof _abstractSeries2.default;
}
/**
* Get all series from the 'children' object of the component.
* @param {Object} children Children.
* @returns {Array} Array of children.
*/
function getSeriesChildren(children) {
return _react2.default.Children.toArray(children).filter(<span class="fstat-no" title="function not covered" >function (child) {</span>
return <span class="cstat-no" title="statement not covered" >child && isSeriesChild(child);</span>
});
}
/**
* Collect the map of repetitions of the series type for all children.
* @param {Array} children Array of children.
* @returns {{}} Map of repetitions where sameTypeTotal is the total amount and
* sameTypeIndex is always 0.
*/
function collectSeriesTypesInfo(children) {
var result = {};
children.filter(isSeriesChild).forEach(function (child) {
var displayName = child.type.displayName;
if (!result[displayName]) {
result[displayName] = {
sameTypeTotal: 0,
sameTypeIndex: 0
};
}
result[displayName].sameTypeTotal++;
});
return result;
}
/**
* Collect the stacked data for all children in use. If the children don't have
* the data (e.g. the child is invalid series or something else), then the child
* is skipped.
* Each next value of attr is equal to the previous value plus the difference
* between attr0 and attr.
* @param {Array} children Array of children.
* @param {string} attr Attribute.
* @returns {Array} New array of children for the series.
*/
function getStackedData(children, attr) {
var childData = [];
var prevIndex = -1;
children.forEach(<span class="fstat-no" title="function not covered" >function (child, childIndex) {</span>
// Skip the children that are not series (e.g. don't have any data).
if (<span class="cstat-no" title="statement not covered" >!child) {</span>
childData.<span class="cstat-no" title="statement not covered" >push(null);</span>
return;
}
var <span class="cstat-no" title="statement not covered" >data = child.props.data;</span>
if (<span class="cstat-no" title="statement not covered" >!attr || !data || !data.length) {</span>
childData.<span class="cstat-no" title="statement not covered" >push(data);</span>
return;
}
var <span class="cstat-no" title="statement not covered" >attr0 = attr + '0';</span>
childData.<span class="cstat-no" title="statement not covered" >push(data.map(<span class="fstat-no" title="function not covered" >function (d, dIndex) {</span></span>
var <span class="cstat-no" title="statement not covered" >_extends2;</span>
// In case if it's the first series don't try to override any values.
if (<span class="cstat-no" title="statement not covered" >prevIndex < 0) {</span>
return <span class="cstat-no" title="statement not covered" >_extends({}, d);</span>
}
// In case if the series is not the first, try to get the attr0 values
// from the previous series.
var <span class="cstat-no" title="statement not covered" >prevD = childData[prevIndex][dIndex];</span>
return <span class="cstat-no" title="statement not covered" >_extends({}, d, (_extends2 = {}, _defineProperty(_extends2, attr0, prevD[attr]), _defineProperty(_extends2, attr, prevD[attr] + d[attr] - (d[attr0] || 0)), _extends2));</span>
}));
prevIndex = <span class="cstat-no" title="statement not covered" >childIndex;</span>
});
return childData;
}
/**
* Get the list of series props for a child.
* @param {Array} children Array of all children.
* @returns {Array} Array of series props for each child. If a child is not a
* series, than it's undefined.
*/
function getSeriesPropsFromChildren(children) {
var result = [];
var seriesTypesInfo = collectSeriesTypesInfo(children);
var seriesIndex = 0;
var _opacityValue = _theme.DEFAULT_OPACITY;
children.forEach(function (child) {
var props = void 0;
if (<span class="missing-if-branch" title="else path not taken" >E</span>isSeriesChild(child)) {
var seriesTypeInfo = seriesTypesInfo[child.type.displayName];
var _colorValue = _theme.DISCRETE_COLOR_RANGE[seriesIndex % _theme.DISCRETE_COLOR_RANGE.length];
props = _extends({}, seriesTypeInfo, {
seriesIndex: seriesIndex,
ref: 'series' + seriesIndex,
_colorValue: _colorValue,
_opacityValue: _opacityValue
});
seriesTypeInfo.sameTypeIndex++;
seriesIndex++;
}
result.push(props);
});
return result;
}</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri May 20 2016 11:46:43 GMT-0700 (PDT)
</div>
</div>
<script src="../../../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../../../sorter.js"></script>
</body>
</html>