import React, { useState, useEffect, useMemo } from 'react'; import { FixedSizeList } from 'react-window'; import { useSpring, animated, config } from 'react-spring'; import classNames from 'classnames'; import Button from 'components/common/Button'; import Arrow from 'assets/arrow-right.svg'; import { get } from 'lib/web'; import { percentFilter } from 'lib/filters'; import { formatNumber, formatLongNumber } from 'lib/format'; import styles from './RankingsChart.module.css'; export default function RankingsChart({ title, websiteId, startDate, endDate, type, heading, className, dataFilter, limit, onDataLoad = () => {}, onExpand = () => {}, }) { const [data, setData] = useState(); const [format, setFormat] = useState(true); const formatFunc = format ? formatLongNumber : formatNumber; const rankings = useMemo(() => { if (data) { const items = dataFilter ? dataFilter(data) : data; if (limit) { return items.filter((e, i) => i < limit); } return items; } return []; }, [data]); async function loadData() { const data = await get(`/api/website/${websiteId}/rankings`, { start_at: +startDate, end_at: +endDate, type, }); const updated = percentFilter(data); setData(updated); onDataLoad(updated); } function handleSetFormat() { setFormat(state => !state); } const Row = ({ index, style }) => { const { x, y, z } = rankings[index]; return (