import React, { Component } from 'react' import { Checkbox, FormControlLabel, Menu, Paper, Typography, Button } from '@material-ui/core' import Images from '../../assets/Images' import NumberFormat from 'react-number-format'; import ReactECharts from 'echarts-for-react'; export default class StrategiMap extends Component { constructor(props) { super(props) this.state = { openMenu: false, dataStrategy: this.props.data.kpi.category, checkAll: true, checkYTD: true, checkAB: true, checkYoy: true, loading: false, dataStrategyNew: [] } } componentDidMount() { this.setState({ loading: true }) this.olahDataKPI() } handleKPI(name) { let arrayCAT = this.props.tableCAT let indexID = this.props.tableCAT.findIndex((val) => String(val[5]).toLocaleLowerCase() == String(name).toLocaleLowerCase()) return arrayCAT[indexID][8] } olahDataKPI() { console.log(this.state.dataStrategy) let arrayNew = this.state.dataStrategyNew this.state.dataStrategy.map((item, index) => { let arrayNodes = [] item.nodes.map((itemz, indexz) => { let kpi = this.handleKPI(itemz.item_name) let act = [] let mbv = [] let yoy = [] let minACT = 0 let maxACT = 0 let minMBV = 0 let maxMBV = 0 let minYOY = 0 let maxYOY = 0 itemz.trends.map((items, indexs) => { act.push(items.nodes_actual_value) mbv.push(items.nodes_mb_value) yoy.push(items.nodes_yoy_value) if (minACT > items.nodes_actual_value) { minACT = items.nodes_actual_value } if (maxACT < items.nodes_actual_value) { maxACT = items.nodes_actual_value } if (minMBV > items.nodes_mb_value) { minMBV = items.nodes_mb_value } if (maxMBV < items.nodes_mb_value) { maxMBV = items.nodes_mb_value } if (minYOY > items.nodes_yoy_value) { minYOY = items.nodes_yoy_value } if (maxYOY < items.nodes_yoy_value) { maxYOY = items.nodes_yoy_value } }) let sortMin = [] let sortMax = [] if (this.state.checkAll) { sortMin = [minACT, minMBV, minYOY].sort((a, b) => a - b) sortMax = [maxACT, maxMBV, maxYOY].sort((a, b) => b - a) } else if (this.state.checkAB && this.state.checkYTD && !this.state.checkYoy) { sortMin = [minACT, minMBV].sort((a, b) => a - b) sortMax = [maxACT, maxMBV].sort((a, b) => b - a) } else if (this.state.checkAB && !this.state.checkYTD && this.state.checkYoy) { sortMin = [minACT, minYOY].sort((a, b) => a - b) sortMax = [maxACT, maxYOY].sort((a, b) => b - a) } else if (this.state.checkAB && !this.state.checkYTD && !this.state.checkYoy) { sortMin = [minMBV] sortMax = [maxMBV] } else if (!this.state.checkAB && this.state.checkYTD && this.state.checkYoy) { sortMin = [minMBV, minYOY].sort((a, b) => a - b) sortMax = [maxMBV, maxYOY].sort((a, b) => b - a) } else if (!this.state.checkAB && this.state.checkYTD && !this.state.checkYoy) { sortMin = [minMBV] sortMax = [maxMBV] } else if (!this.state.checkAB && !this.state.checkYTD && this.state.checkYoy) { sortMin = [minYOY] sortMax = [maxYOY] } arrayNodes.push({ ...itemz, kpi, trends: { act, mbv, yoy, minACT, maxACT, minMBV, maxMBV, minYOY, maxYOY, sortMin, sortMax } }) }) arrayNew.push({ ...item, nodes: arrayNodes }) }) console.log(arrayNew) console.log(this.state.checkAll) this.setState({ dataStrategyNew: arrayNew }, () => { setTimeout(() => { this.setState({ loading: false }) }, 500); }) } handleAch(item) { let value = String(item) value = String(value).substr(0, String(value).length - 1) return Number(value) } render() { const data = [ { color: "steelblue", points: [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: -2 }] }, { color: "green", points: [{ x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 5 }] } ]; const optionvv = { tooltip: { trigger: 'axis', axisPointer: { type: 'cross', crossStyle: { color: '#999' } } }, grid: { left: 0, bottom: 0 }, xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ data: [150, 230, 224, 218, 135, 147, 260], type: 'line' }] }; const newTitleCase = (val) => { let value = val return value.split(' ') .map(w => w[0].toUpperCase() + w.substr(1).toLowerCase()) .join(' ') } const handleIsHigher = (item) => { let actMo = 0 let prevMo = 0 let isHigh = 'false' let trends = [...item.trends.act] let trendsLength = trends.length if (trendsLength < 2) { actMo = trends[0] } else { actMo = trends[trendsLength-1] prevMo = trends[trendsLength-2] } if (actMo > prevMo) { isHigh = item.kpi == 'HIG' ? 'true' : 'false' } else if (actMo == prevMo) { isHigh = 'same' } else { isHigh = item.kpi == 'HIB' ? 'true' : 'false' } return isHigh } const handleColorAch = (item) => { let actMR = 0 let actMB = 0 let isHigh = false let trendsAct = [...item.trends.act] let trendsMB = [...item.trends.mbv] let trendsActLength = trendsAct.length let trendsMBLength = trendsMB.length actMR = trendsAct[trendsActLength-1] actMB = trendsMB[trendsMBLength-1] let percentage = String(item.achievement).includes('%')? Number(String(item.achievement).substr(0,String(item.achievement).length -1)) : Number(item.achievement) if (percentage < 100) { isHigh = false } else { isHigh = true } return isHigh } return (
this.setState({ openMenu: false })} >
{ this.setState({ checkAll: true, checkYTD: true, checkAB: true, checkYoy: true, loading: true, }, () => { setTimeout(() => { this.setState({ loading: false }) }, 500); }) }} name="checkedB" color="primary" /> } style={{ marginRight: 20 }} label={"Pilih Semua"} /> { this.setState({ checkAll: false, checkYTD: false, checkAB: false, checkYoy: false }) }} name="checkedB" color="primary" /> } label={"Hapus Semua"} />
{ this.setState({ checkYTD: !this.state.checkYTD, loading: true }, () => { this.setState({ checkAll: this.state.checkYoy && this.state.checkAB && this.state.checkYTD }, () => { setTimeout(() => { this.setState({ loading: false }) }, 500); }) }) }} name="checkedB" color="primary" /> } label={"Tren YTD"} /> { this.setState({ checkAB: !this.state.checkAB, loading: true }, () => { this.setState({ checkAll: this.state.checkYoy && this.state.checkAB && this.state.checkYTD }, () => { setTimeout(() => { this.setState({ loading: false }) }, 500); }) }) }} name="checkedB" color="primary" /> } label={"Actual vs Budget"} /> { this.setState({ checkYoy: !this.state.checkYoy, loading: true }, () => { this.setState({ checkAll: this.state.checkYoy && this.state.checkAB && this.state.checkYTD }, () => { setTimeout(() => { this.setState({ loading: false }) }, 500); }) }) }} name="checkedB" color="primary" /> } label={"Yoy"} />
Category
KPI
Trends
Current ({this.props.dataPayload.month.month_value})
Achievement
vs Prev. Month
{this.state.dataStrategyNew.map((i) => ( i.nodes.map((item, index) => { // let dataYTD = [] // let dataAB = [] // let dataYoy = [] // let option = [] // if (this.state.checkYTD === true) { // option.push({ // color: "steelblue", // points: dataYTD // }) // } // if (this.state.checkAB === true) { // option.push({ // color: "#e3e16d", // points: dataAB // }) // } // if (this.state.checkYoy === true) { // option.push({ // color: "#f27f77", // points: dataYoy // }) // } // item.trends.map((val, idx) => { // dataYTD.push({ // x: idx + 1, // y: val.nodes_actual_value // }) // dataAB.push({ // x: idx + 1, // y: val.nodes_mb_value // }) // dataYoy.push({ // x: idx + 1, // y: val.nodes_yoy_value // }) // }) return (
{index > 0 ? '' : newTitleCase(String(i.category_name).toLocaleLowerCase())}
{item.item_name} {item.unit}
{!this.state.loading && (this.state.checkAB || this.state.checkYTD || this.state.checkYoy) && }
{/* {item.current_value} */}
{item.achievement == '-' || item.achievement == "" ? - : }
{item.trends.act.length == 0 ? - : (handleIsHigher(item) == 'same' ? - : ) }
) }) ))} {/*
Category
KPI
Trends
Current
Achievement
KPI
Trends
Current
Achievement
*/}
) } }