import React, { useState } from 'react'
import { Icon, Popup } from 'UI'
import { numberCompact } from 'App/utils';
import { BarChart, Bar, Cell, XAxis, YAxis, CartesianGrid, Tooltip, Legend, LabelList, Label } from 'recharts';
import { connect } from 'react-redux';
import { setActiveStages } from 'Duck/funnels';
import { Styles } from '../../Dashboard/Widgets/common';
import { numberWithCommas } from 'App/utils'
import { truncate } from 'App/utils'
const MIN_BAR_HEIGHT = 20;
function CustomTick(props) {
const { x, y, payload } = props;
return (
{payload.value}
);
}
function FunnelGraph(props) {
const { data, activeStages, funnelId, liveFilters } = props;
const [activeIndex, setActiveIndex] = useState(activeStages)
const renderPercentage = (props) => {
const {
x, y, width, height, value,
} = props;
const radius = 10;
const _x = (x + width / 2) + 45;
return (
{numberCompact(value)}
);
};
const renderCustomizedLabel = (props) => {
const {
x, y, width, height, value, textColor = '#fff'
} = props;
const radius = 10;
if (value === 0) return;
return (
{numberCompact(value)}
);
};
const handleClick= (data, index) => {
if (activeStages.length === 1 && activeStages.includes(index)) { // selecting the same bar
props.setActiveStages([], null);
return;
}
if (activeStages.length === 2) { // already having two bars
return;
}
// new selection
const arr = activeStages.concat([index]);
props.setActiveStages(arr.sort(), arr.length === 2 && liveFilters, funnelId);
};
const resetActiveSatges = () => {
props.setActiveStages([], liveFilters, funnelId, true);
}
const renderDropLabel = ({ x, y, width, value }) => {
if (value === 0) return;
return (
{value}
)
}
const renderMainLabel = ({ x, y, width, value }) => {
return (
{numberWithCommas(value)}
)
}
const CustomBar = (props) => {
const { fill, x, y, width, height, sessionsCount, index, dropDueToIssues } = props;
const yp = sessionsCount < MIN_BAR_HEIGHT ? (MIN_BAR_HEIGHT - 1): dropDueToIssues
const tmp = (height <= 20 ? 20 : height) - (TEMP[index].height > 20 ? 0 : TEMP[index].height);
return (
)
}
const MainBar = (props) => {
const { fill, x, y, width, height, sessionsCount, index, dropDueToIssues, hasSelection = false } = props;
const yp = sessionsCount < MIN_BAR_HEIGHT ? (MIN_BAR_HEIGHT - 1): dropDueToIssues
TEMP[index] = {height,y};
return (
)
}
const renderDropPct = (props) => { // TODO
const { fill, x, y, width, height, value, totalBars } = props;
const barW = x + ((730 / totalBars) / 2);
return (
)
}
const CustomTooltip = (props) => {
const { payload } = props;
if (payload.length === 0) return null;
const { value, headerText } = payload[0].payload;
// const value = payload[0].payload.value;
if (!value) return null;
return (
{headerText}
{value.map(i => (
{truncate(i, 30)}
))}
)
};
// const CustomTooltip = ({ active, payload, msg = '' }) => {
// return (
//
// );
// };
const TEMP = {}
return (
{ activeStages.length === 2 && (
}
content={ `Reset Selection` }
size="tiny"
inverted
position="top center"
/>
)}
{/* {activeStages.length < 2 && 0 ? 'Select one more event.' : 'Select any two events to analyze in depth.'} />} />} */}
}
cursor="pointer"
minPointSize={MIN_BAR_HEIGHT}
background={false}
>
{
data.map((entry, index) => {
const selected = activeStages.includes(index) || (index > activeStages[0] && index < activeStages[1]);
const opacity = activeStages.length > 0 && !selected ? 0.4 : 1;
return (
|
)
})
}
}
minPointSize={MIN_BAR_HEIGHT}
>
{
data.map((entry, index) => {
const selected = activeStages.includes(index) || (index > activeStages[0] && index < activeStages[1]);
const opacity = activeStages.length > 0 && !selected ? 0.4 : 1;
return (
|
)
})
}
}
xAxisId={0}
/>
{/* '"' + val + '"'}
/> */}
Styles.tickFormatter(val)} />
)
}
export default connect(state => ({
activeStages: state.getIn(['funnels', 'activeStages']).toJS(),
liveFilters: state.getIn(['funnelFilters', 'appliedFilter']),
}), { setActiveStages })(FunnelGraph)