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';
|
|
|
|
|
|
|
|
const storeCurrency = new Currency(); // give this store settings.
|
|
|
|
const formatCurrency = storeCurrency.formatCurrency.bind( storeCurrency );
|
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' }
|
|
|
|
tooltipValueFormat={ formatCurrency }
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GlobalPrices;
|