Skip to content
This repository has been archived by the owner on Jul 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from AndresMorelos/Statistics
Browse files Browse the repository at this point in the history
Adding statistics views.
  • Loading branch information
AndresMorelos authored Jan 17, 2022
2 parents a648f5a + dd968ff commit ceec048
Show file tree
Hide file tree
Showing 35 changed files with 890 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports[`Renders correctly to the DOM matches snapshot 1`] = `
Pending
</label>
<p>
01/16/22
01/17/22
</p>
</div>
<div
Expand Down
5 changes: 4 additions & 1 deletion app/components/layout/AppMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import Form from '../../containers/Form';
import Invoices from '../../containers/Invoices';
import Contacts from '../../containers/Contacts';
import Settings from '../../containers/Settings';
import Statistics from '../../containers/Statistics';

// Layout
import { AppMainContent } from '../shared/Layout';


class AppMain extends Component {
shouldComponentUpdate(nextProps) {
return this.props.activeTab !== nextProps.activeTab;
const { activeTab } = this.props;
return activeTab !== nextProps.activeTab;
}

render() {
Expand All @@ -24,6 +26,7 @@ class AppMain extends Component {
{activeTab === 'form' && <Form />}
{activeTab === 'invoices' && <Invoices />}
{activeTab === 'contacts' && <Contacts />}
{activeTab === 'statistics' && <Statistics />}
{activeTab === 'settings' && <Settings />}
</AppMainContent>
);
Expand Down
6 changes: 6 additions & 0 deletions app/components/layout/AppNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const allTabs = [
name: 'contacts',
icon: 'ion-person-stalker',
},
{
title: 'Statistics',
name: 'statistics',
icon: 'ion-arrow-graph-up-right'
},
{
title: 'Settings',
name: 'settings',
Expand Down Expand Up @@ -78,6 +83,7 @@ export const Icon = styled.i`
${props => props.id === 'form' && `color: #6bbb69;`};
${props => props.id === 'contacts' && `color: #469fe5;`};
${props => props.id === 'settings' && `color: #C4C8CC;`};
${props => props.id === 'statics' && `color: #ffffff`};
${props => props.id === 'invoices' && `color: #cbc189;`};
`;

Expand Down
7 changes: 4 additions & 3 deletions app/components/layout/AppUpdate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ class AppUpdate extends PureComponent {
}

render() {
const { checking, downloading, progress } = this.state;
return (
<Indicator>
{this.state.checking && <i className="ion-cloud" />}
{this.state.downloading && (
{checking && <i className="ion-cloud" />}
{downloading && (
<Circle
percent={this.state.progress}
percent={progress}
strokeWidth={16}
trailWidth={16}
trailColor="#4F555C"
Expand Down
4 changes: 2 additions & 2 deletions app/components/layout/__tests__/AppNav.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('Renders correctly to the DOM', () => {
wrapper = mount(<AppNav activeTab="form" changeTab={changeTab} />);
});

it('renders 4 tabs', () => {
expect(wrapper.find('a')).toHaveLength(4);
it('renders 5 tabs', () => {
expect(wrapper.find('a')).toHaveLength(5);
});

it('has correct porps', () => {
Expand Down
44 changes: 44 additions & 0 deletions app/components/statistics/CalendarChart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Libs
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { ResponsiveCalendar } from '@nivo/calendar';

// Component
class CalendarChart extends PureComponent {
render() {
const { data } = this.props;
return (
<ResponsiveCalendar
data={data}
from={new Date(new Date().getFullYear(), 0, 1)}
to={new Date(new Date().getFullYear(), 12, 0)}
granularity="month"
emptyColor="#eeeeee"
colors={['#61cdbb', '#97e3d5', '#e8c1a0', '#f47560']}
margin={{ top: 40, right: 40, bottom: 40, left: 40 }}
yearSpacing={40}
monthBorderColor="#ffffff"
dayBorderWidth={2}
dayBorderColor="#ffffff"
legends={[
{
anchor: 'bottom-right',
direction: 'row',
translateY: 36,
itemCount: 4,
itemWidth: 42,
itemHeight: 36,
itemsSpacing: 14,
itemDirection: 'right-to-left',
},
]}
/>
);
}
}

CalendarChart.propTypes = {
data: PropTypes.arrayOf(PropTypes.object).isRequired,
};

export default CalendarChart;
23 changes: 23 additions & 0 deletions app/components/statistics/CustomSymbol.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'

const CustomSymbol = function({ size, color, borderWidth, borderColor }){
return (
<g>
<circle
fill="#fff"
r={size / 2}
strokeWidth={borderWidth}
stroke={borderColor}
/>
<circle
r={size / 5}
strokeWidth={borderWidth}
stroke={borderColor}
fill={color}
fillOpacity={0.35}
/>
</g>
)
};

export default CustomSymbol;
72 changes: 72 additions & 0 deletions app/components/statistics/PieChart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Libs
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { ResponsivePie } from '@nivo/pie';

const commonProperties = {
margin: { top: 80, right: 120, bottom: 80, left: 120 },
animate: true,
activeOuterRadiusOffset: 8,
};

// Component
class PieChart extends PureComponent {
render() {
const { data } = this.props;
return (
<ResponsivePie
data={data}
margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
innerRadius={0.5}
padAngle={0.7}
cornerRadius={3}
activeOuterRadiusOffset={8}
borderWidth={1}
borderColor={{
from: 'color',
modifiers: [['darker', 0.2]],
}}
arcLinkLabelsSkipAngle={10}
arcLinkLabelsTextColor="#333333"
arcLinkLabelsThickness={2}
arcLinkLabelsColor={{ from: 'color' }}
arcLabelsSkipAngle={10}
arcLabelsTextColor={{
from: 'color',
modifiers: [['darker', 2]],
}}
legends={[
{
anchor: 'bottom',
direction: 'row',
justify: false,
translateX: 0,
translateY: 56,
itemsSpacing: 0,
itemWidth: 100,
itemHeight: 18,
itemTextColor: '#999',
itemDirection: 'left-to-right',
itemOpacity: 1,
symbolSize: 18,
symbolShape: 'circle',
effects: [
{
on: 'hover',
style: {
itemTextColor: '#000',
},
},
],
},
]}
/>
);
}
}

PieChart.propTypes = {
data: PropTypes.arrayOf(PropTypes.object).isRequired,
};

export default PieChart;
93 changes: 93 additions & 0 deletions app/components/statistics/TimeLineChart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Libs
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { ResponsiveLine } from '@nivo/line';
import CustomSymbol from './CustomSymbol';

const commonProperties = {
margin: { top: 50, right: 20, bottom: 60, left: 80 },
animate: true,
enableSlices: 'x',
};

// Component
class TimeLineChart extends PureComponent {
render() {
const { data, yLegend, xLegend } = this.props;
return (
<ResponsiveLine
{...commonProperties}
data={data}
xScale={{
type: 'time',
format: '%Y-%m-%d',
useUTC: false,
precision: 'day',
}}
xFormat="time:%Y/%m/%d"
yScale={{
type: 'linear',
stacked: false,
}}
yFormat=" >-$.2f"
axisLeft={{
legend: yLegend,
legendOffset: -60,
legendPosition: 'middle',
}}
axisBottom={{
format: '%b %d',
tickValues: 'every 2 days',
legend: xLegend,
legendOffset: 36,
legendPosition: 'middle',
}}
curve="monotoneX"
enablePointLabel
pointSymbol={CustomSymbol}
pointSize={16}
pointLabelYOffset={-12}
pointBorderWidth={1}
pointBorderColor={{
from: 'color',
modifiers: [['darker', 0.3]],
}}
useMesh
colors={{ scheme: 'category10' }}
enableSlices={false}
legends={[
{
anchor: 'bottom-right',
direction: 'row',
translateX: 0,
translateY: 60,
itemsSpacing: 15,
itemWidth: 80,
itemHeight: 20,
itemOpacity: 0.75,
symbolSize: 12,
symbolShape: 'circle',
symbolBorderColor: 'rgba(0, 0, 0, .5)',
effects: [
{
on: 'hover',
style: {
itemBackground: 'rgba(0, 0, 0, .03)',
itemOpacity: 1,
},
},
],
},
]}
/>
);
}
}

TimeLineChart.propTypes = {
data: PropTypes.arrayOf(PropTypes.object).isRequired,
yLegend: PropTypes.string.isRequired,
xLegend: PropTypes.string.isRequired,
};

export default TimeLineChart;
Loading

0 comments on commit ceec048

Please sign in to comment.