292a68a7345cd866cfc8a5cd67aa32d2f80d03ca
[aai/sparky-fe.git] / src / app / vnfSearch / VnfSearchNfTypeVisualization.jsx
1 /* eslint-disable max-len,max-len,max-len,max-len,max-len,max-len */
2 /*
3  * ============LICENSE_START===================================================
4  * SPARKY (AAI UI service)
5  * ============================================================================
6  * Copyright © 2017 AT&T Intellectual Property.
7  * Copyright © 2017 Amdocs
8  * All rights reserved.
9  * ============================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=====================================================
22  *
23  * ECOMP and OpenECOMP are trademarks
24  * and service marks of AT&T Intellectual Property.
25  */
26
27 import React, {Component} from 'react';
28 import {connect} from 'react-redux';
29 import {
30   BarChart,
31   Bar,
32   XAxis,
33   YAxis,
34   CartesianGrid,
35   Tooltip,
36   ResponsiveContainer,
37 } from 'recharts';
38
39 import i18n from 'utils/i18n/i18n';
40
41 import {CHART_NF_TYPE} from 'app/vnfSearch/VnfSearchConstants.js';
42 import {COLOR_BLUE} from 'utils/GlobalConstants.js';
43
44 let mapStateToProps = ({vnfSearch}) => {
45   let {
46         processedNfTypeCountChartData = CHART_NF_TYPE.emptyData
47       } = vnfSearch;
48
49   return {
50     processedNfTypeCountChartData
51   };
52 };
53
54 class VnfSearchNfTypeVisualization extends Component {
55   static propTypes = {
56     processedNfTypeCountChartData: React.PropTypes.object
57   };
58
59   render() {
60     let {
61           processedNfTypeCountChartData
62         } = this.props;
63
64     let visualizationClass = 'visualizations';
65     if (processedNfTypeCountChartData.values ===
66       null ||
67       processedNfTypeCountChartData.values.size <=
68       0) {
69       visualizationClass = 'visualizations hidden';
70     }
71     const xAxisAttrName = 'x';
72     const yAxisAttrName = 'y';
73
74     return (
75       <div id='audit-visualizations' className={visualizationClass}>
76         <div className='visualization-charts'>
77           <div >
78             <h3>{i18n(CHART_NF_TYPE.title)}</h3>
79             <ResponsiveContainer width='100%' height={300}>
80               <BarChart data={processedNfTypeCountChartData.values}>
81                 <XAxis dataKey={xAxisAttrName}/>
82                 <YAxis   />
83                 <CartesianGrid strokeDasharray='3 3'/>
84                 <Tooltip/>
85                 <Bar name={i18n(CHART_NF_TYPE.yAxisLabel)}
86                      dataKey={yAxisAttrName} fill={COLOR_BLUE}/>
87               </BarChart>
88             </ResponsiveContainer>
89           </div>
90         </div>
91       </div>
92     );
93   }
94
95 }
96 export default connect(mapStateToProps)(VnfSearchNfTypeVisualization);