2019-05-06 04:39:10 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { Card, Chart } from '@woocommerce/components';
|
2019-11-21 21:51:52 +00:00
|
|
|
import Currency from '@woocommerce/currency';
|
|
|
|
|
2020-05-19 02:38:02 +00:00
|
|
|
const storeCurrency = Currency();
|
2019-05-06 04:39:10 +00:00
|
|
|
const data = [];
|
|
|
|
|
|
|
|
for ( let i = 1; i <= 20; i++ ) {
|
|
|
|
const date = moment().subtract( i, 'days' );
|
|
|
|
data.push( {
|
|
|
|
date: date.format( 'YYYY-MM-DDT00:00:00' ),
|
|
|
|
primary: {
|
|
|
|
label: 'Global Apple Prices, last 20 days',
|
|
|
|
labelDate: date.format( 'YYYY-MM-DD 00:00:00' ),
|
|
|
|
value: Math.floor( Math.random() * 100 ),
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
const GlobalPrices = () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
const average =
|
|
|
|
data.reduce( ( total, item ) => total + item.primary.value, 0 ) /
|
|
|
|
data.length;
|
2019-05-06 04:39:10 +00:00
|
|
|
return (
|
2020-02-14 02:23:21 +00:00
|
|
|
<Card
|
|
|
|
className="woocommerce-dashboard__chart-block woocommerce-analytics__card"
|
|
|
|
title="Global Apple Prices"
|
|
|
|
>
|
2019-05-06 04:39:10 +00:00
|
|
|
<Chart
|
|
|
|
title="Global Apple Prices"
|
|
|
|
interval="day"
|
|
|
|
data={ data.reverse() }
|
|
|
|
dateParser="%Y-%m-%dT%H:%M:%S"
|
2019-06-11 12:31:53 +00:00
|
|
|
legendTotals={ { primary: average } }
|
2019-05-06 04:39:10 +00:00
|
|
|
showHeaderControls={ false }
|
|
|
|
valueType={ 'currency' }
|
2020-05-19 02:38:02 +00:00
|
|
|
tooltipValueFormat={ storeCurrency.formatCurrency }
|
2019-05-06 04:39:10 +00:00
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GlobalPrices;
|