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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
import d3 from 'd3';
import React from 'react';
import { getMeasuresAndVariations } from '../../../api/measures';
import { DetailedMeasure } from '../components/detailed-measure';
import { DomainTimeline } from '../components/domain-timeline';
import { DomainTreemap } from '../components/domain-treemap';
import { DomainBubbleChart } from '../components/domain-bubble-chart';
import { getPeriodLabel, getPeriodDate } from './../helpers/periods';
import { TooltipsMixin } from '../../../components/mixins/tooltips-mixin';
import { filterMetrics, filterMetricsForDomains } from '../helpers/metrics';
import { DomainLeakTitle } from '../main/components';
import { CHART_COLORS_RANGE_PERCENT } from '../../../helpers/constants';
import { formatMeasure, formatMeasureVariation } from '../../../helpers/measures';
import { DonutChart } from '../../../components/charts/donut-chart';
import { DrilldownLink } from '../../../components/shared/drilldown-link';
import { getMetricName } from '../helpers/metrics';
export const DuplicationsMain = React.createClass({
mixins: [TooltipsMixin],
getInitialState() {
return {
ready: false,
leakPeriodLabel: getPeriodLabel(this.props.component.periods, this.props.leakPeriodIndex),
leakPeriodDate: getPeriodDate(this.props.component.periods, this.props.leakPeriodIndex)
};
},
componentDidMount() {
this.requestMeasures().then(r => {
let measures = this.getMeasuresValues(r, 'value');
let leak = this.getMeasuresValues(r, 'var' + this.props.leakPeriodIndex);
this.setState({ ready: true, measures, leak });
});
},
getMeasuresValues (measures, fieldKey) {
let values = {};
Object.keys(measures).forEach(measureKey => {
values[measureKey] = measures[measureKey][fieldKey];
});
return values;
},
getMetricsForDomain() {
return this.props.metrics
.filter(metric => ['Duplication'].indexOf(metric.domain) !== -1)
.map(metric => metric.key);
},
getMetricsForTimeline() {
return filterMetricsForDomains(this.props.metrics, ['Duplication']);
},
getAllMetricsForTimeline() {
return filterMetrics(this.props.metrics);
},
requestMeasures () {
return getMeasuresAndVariations(this.props.component.key, this.getMetricsForDomain());
},
renderLoading () {
return <div className="text-center">
<i className="spinner spinner-margin"/>
</div>;
},
renderEmpty() {
return <div className="overview-detailed-page">
<div className="page">
<p>{window.t('overview.no_duplications')}</p>
</div>
</div>;
},
renderLegend () {
return <DomainLeakTitle inline={true} label={this.state.leakPeriodLabel} date={this.state.leakPeriodDate}/>;
},
renderMeasures() {
let metrics = filterMetricsForDomains(this.props.metrics, ['Duplication'])
.filter(metric => metric.key !== 'duplicated_lines_density')
.map(metric => {
return <DetailedMeasure key={metric.key}
{...this.props}
{...this.state}
metric={metric.key}
type={metric.type}/>;
});
return <div>{metrics}</div>;
},
renderDonut() {
const duplicationsMetric = 'duplicated_lines_density';
const duplications = this.state.measures[duplicationsMetric];
const donutData = [
{ value: duplications, fill: '#f3ca8e' },
{ value: Math.max(0, 20 - duplications), fill: '#e6e6e6' }
];
return <DonutChart width="30"
height="30"
thickness="4"
data={donutData}/>;
},
renderDuplicationsLeak() {
if (!this.state.leakPeriodDate) {
return null;
}
const duplicationsMetric = 'duplicated_lines_density';
const leak = this.state.leak[duplicationsMetric];
return <div className="overview-detailed-measure-leak">
<span className="overview-detailed-measure-value">
{formatMeasureVariation(leak, 'PERCENT')}
</span>
</div>;
},
render () {
if (!this.state.ready) {
return this.renderLoading();
}
const duplicationsMetric = 'duplicated_lines_density';
const duplications = this.state.measures[duplicationsMetric];
if (duplications == null) {
return this.renderEmpty();
}
let treemapScale = d3.scale.linear()
.domain([0, 25, 50, 75, 100])
.range(CHART_COLORS_RANGE_PERCENT);
return <div className="overview-detailed-page">
<div className="overview-cards-list">
<div className="overview-card overview-card-fixed-width">
<div className="overview-card-header">
<div className="overview-title">{window.t('overview.domain.duplications')}</div>
{this.renderLegend()}
</div>
<div className="overview-detailed-measures-list">
<div className="overview-detailed-measure" style={{ lineHeight: '30px' }}>
<div className="overview-detailed-measure-nutshell">
<span className="overview-detailed-measure-name big">
{getMetricName('duplications')}
</span>
<span className="overview-detailed-measure-value">
<span className="spacer-right">{this.renderDonut()}</span>
<DrilldownLink component={this.props.component.key} metric={duplicationsMetric}>
{formatMeasure(duplications, 'PERCENT')}
</DrilldownLink>
</span>
</div>
{this.renderDuplicationsLeak()}
</div>
{this.renderMeasures()}
</div>
</div>
<div className="overview-card">
<DomainBubbleChart {...this.props}
xMetric="ncloc"
yMetric="duplicated_lines"
sizeMetrics={['duplicated_blocks']}/>
</div>
</div>
<div className="overview-cards-list">
<div className="overview-card">
<DomainTimeline {...this.props} {...this.state}
initialMetric="duplicated_lines_density"
metrics={this.getMetricsForTimeline()}
allMetrics={this.getAllMetricsForTimeline()}/>
</div>
<div className="overview-card">
<DomainTreemap {...this.props}
sizeMetric="ncloc"
colorMetric="duplicated_lines_density"
scale={treemapScale}/>
</div>
</div>
</div>;
}
});
|