Updated rankings styling and filters.

This commit is contained in:
Mike Cao 2020-07-31 21:56:25 -07:00
parent 65d44ff6a1
commit e4e7f5b05c
5 changed files with 50 additions and 20 deletions

View File

@ -5,7 +5,7 @@
} }
.value { .value {
padding: 4px 24px 4px 8px; padding: 4px 32px 4px 16px;
border: 1px solid #b3b3b3; border: 1px solid #b3b3b3;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
@ -24,12 +24,12 @@
.option { .option {
background: #fff; background: #fff;
padding: 4px 8px; padding: 4px 16px;
cursor: pointer; cursor: pointer;
} }
.option:hover { .option:hover {
background: #eaeaea; background: #f5f5f5;
} }
.caret { .caret {
@ -41,6 +41,6 @@
transform: rotate(45deg); transform: rotate(45deg);
top: -4px; top: -4px;
bottom: 0; bottom: 0;
right: 8px; right: 12px;
margin: auto; margin: auto;
} }

View File

@ -16,7 +16,12 @@ export default function RankingsChart({
}) { }) {
const [data, setData] = useState(); const [data, setData] = useState();
const rankings = useMemo(() => (data && dataFilter ? dataFilter(data) : data), [data]); const rankings = useMemo(() => {
if (data) {
return (dataFilter ? dataFilter(data) : data).filter((e, i) => i < 10);
}
return [];
}, [data]);
const total = useMemo(() => rankings?.reduce((n, { y }) => n + y, 0) || 0, [rankings]); const total = useMemo(() => rankings?.reduce((n, { y }) => n + y, 0) || 0, [rankings]);
@ -46,13 +51,16 @@ export default function RankingsChart({
<div className={styles.title}>{title}</div> <div className={styles.title}>{title}</div>
<div className={styles.heading}>{heading}</div> <div className={styles.heading}>{heading}</div>
</div> </div>
{rankings.map(({ x, y }, i) => (i <= 10 ? <Row label={x} value={y} total={total} /> : null))} {rankings.map(({ x, y }) => (
<Row key={x} label={x} value={y} total={total} />
))}
</div> </div>
); );
} }
const Row = ({ label, value, total }) => { const Row = ({ label, value, total }) => {
const props = useSpring({ width: (value / total) * 100, from: { width: 0 } }); const pct = total ? (value / total) * 100 : 0;
const props = useSpring({ width: pct, from: { width: 0 } });
const valueProps = useSpring({ y: value, from: { y: 0 } }); const valueProps = useSpring({ y: value, from: { y: 0 } });
return ( return (

View File

@ -1,7 +1,19 @@
.container { .container {
position: relative; position: relative;
min-height: 390px; min-height: 430px;
font-size: 14px; font-size: 14px;
border-left: 1px solid #e1e1e1;
border-top: 1px solid #e1e1e1;
padding: 20px;
}
.container:first-child {
padding-left: 0;
border-left: 0;
}
.container:last-child {
padding-right: 0;
} }
.header { .header {
@ -29,6 +41,7 @@
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 5px; margin-bottom: 5px;
overflow: hidden;
} }
.label { .label {
@ -38,6 +51,14 @@
flex: 2; flex: 2;
} }
.label:empty {
color: #b3b3b3;
}
.label:empty:before {
content: 'Unknown';
}
.value { .value {
width: 50px; width: 50px;
text-align: right; text-align: right;
@ -49,7 +70,7 @@
width: 50px; width: 50px;
color: #6e6e6e; color: #6e6e6e;
position: relative; position: relative;
border-left: 1px solid #6e6e6e; border-left: 1px solid #8e8e8e;
padding-left: 10px; padding-left: 10px;
} }
@ -60,4 +81,5 @@
height: 30px; height: 30px;
opacity: 0.1; opacity: 0.1;
background: #2680eb; background: #2680eb;
z-index: -1;
} }

View File

@ -6,7 +6,8 @@ import RankingsChart from './RankingsChart';
import { getDateRange } from '../lib/date'; import { getDateRange } from '../lib/date';
import styles from './WebsiteDetails.module.css'; import styles from './WebsiteDetails.module.css';
const osFilter = data => data.map(({ x, y }) => ({ x: !x ? 'Unknown' : x, y })); const pageviewClasses = 'col-md-12 col-lg-6';
const sessionClasses = 'col-12 col-lg-4';
const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWith('#')); const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWith('#'));
@ -48,7 +49,7 @@ const browsers = {
chrome: 'Chrome', chrome: 'Chrome',
'chromium-webview': 'Chrome (webview)', 'chromium-webview': 'Chrome (webview)',
phantomjs: 'PhantomJS', phantomjs: 'PhantomJS',
crios: 'CriOS', crios: 'Chrome (iOS)',
firefox: 'Firefox', firefox: 'Firefox',
fxios: 'Firefox (iOS)', fxios: 'Firefox (iOS)',
'opera-mini': 'Opera Mini', 'opera-mini': 'Opera Mini',
@ -92,7 +93,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
return ( return (
<> <>
<div className="row"> <div className="row">
<div className="col"> <div className={classNames(styles.chart, 'col')}>
<h1>{data.label}</h1> <h1>{data.label}</h1>
<WebsiteChart websiteId={data.website_id} onDateChange={handleDateChange} /> <WebsiteChart websiteId={data.website_id} onDateChange={handleDateChange} />
</div> </div>
@ -102,7 +103,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
title="Top URLs" title="Top URLs"
type="url" type="url"
heading="Views" heading="Views"
className="col-12 col-md-8 col-lg-6" className={pageviewClasses}
websiteId={data.website_id} websiteId={data.website_id}
startDate={startDate} startDate={startDate}
endDate={endDate} endDate={endDate}
@ -112,7 +113,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
title="Top referrers" title="Top referrers"
type="referrer" type="referrer"
heading="Views" heading="Views"
className="col-12 col-md-8 col-lg-6" className={pageviewClasses}
websiteId={data.website_id} websiteId={data.website_id}
startDate={startDate} startDate={startDate}
endDate={endDate} endDate={endDate}
@ -124,7 +125,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
title="Browsers" title="Browsers"
type="browser" type="browser"
heading="Visitors" heading="Visitors"
className="col-12 col-md-8 col-lg-4" className={sessionClasses}
websiteId={data.website_id} websiteId={data.website_id}
startDate={startDate} startDate={startDate}
endDate={endDate} endDate={endDate}
@ -134,17 +135,16 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
title="Operating system" title="Operating system"
type="os" type="os"
heading="Visitors" heading="Visitors"
className="col-12 col-md-8 col-lg-4" className={sessionClasses}
websiteId={data.website_id} websiteId={data.website_id}
startDate={startDate} startDate={startDate}
endDate={endDate} endDate={endDate}
dataFilter={osFilter}
/> />
<RankingsChart <RankingsChart
title="Devices" title="Devices"
type="screen" type="screen"
heading="Visitors" heading="Visitors"
className="col-12 col-md-8 col-lg-4" className={sessionClasses}
websiteId={data.website_id} websiteId={data.website_id}
startDate={startDate} startDate={startDate}
endDate={endDate} endDate={endDate}

View File

@ -1,3 +1,3 @@
.row { .chart {
margin: 20px 0; margin-bottom: 30px;
} }