update graph

This commit is contained in:
Alex Santos 2022-06-17 16:18:50 -03:00
parent 035c03afb5
commit a6feabd9de
7 changed files with 104 additions and 37 deletions

View File

@ -20,13 +20,16 @@ ChartJS.register(
interface SingleBarInterface{
title: string,
subtitle: string,
dataProps: Array<number>,
dataProps: any,
label: Array<string>,
dataset: string,
barLabel?: boolean | undefined,
year?: boolean | undefined,
month?: boolean | undefined,
dataset1?: string,
}
export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1, barLabel, year, month }: SingleBarInterface) {
@ -79,19 +82,14 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1
{
label: dataset,
data: dataProps.map((value, index) => {
return year? label[index]<=currentTime.getFullYear().toString()? value : null : month? label.indexOf(label[index])>currentTime.getMonth()? null : value : null
return value.economia_acumulada
}),
backgroundColor: (value, ctx) => {
return year? label[value.dataIndex]<=currentTime.getFullYear().toString()? '#255488' : 'transparent' : month? label.indexOf(label[value.dataIndex])<=currentTime.getMonth()? '#255488' : 'transparent' : null// parseInt(label[value.dataIndex])<=currentTime.getMonth()? '#255488' : draw('diagonal', '#C2D5FB') : null
console.log(dataProps[value.dataIndex])
return dataProps[value.dataIndex].dad_estimado == false ? '#255488' : '#C2d5fb'
},
},
{
label: dataset1,
data: dataProps.map((value, index) => {
return year? label[index]>=currentTime.getFullYear().toString()? value : null : month? label.indexOf(label[index])<=currentTime.getMonth()? null : value : null
}),
backgroundColor: typeof window !== 'undefined'? draw('diagonal', '#C2D5FB') : null
}
],
}

View File

@ -12,7 +12,7 @@ const style = {
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 900,
width: 600,
height: 500,
bgcolor: 'background.paper',
border: '2px solid #254F7F',

View File

@ -13,7 +13,7 @@ const style = {
left: '50%',
transform: 'translate(-50%, -50%)',
width: '80%',
height: '550px',
height: '200px',
bgcolor: 'background.paper',
border: '2px solid #254F7F',
boxShadow: 24,

View File

@ -1,4 +1,6 @@
import { GetServerSideProps } from 'next'
import Head from 'next/head'
import { parseCookies } from 'nookies'
import React from 'react'
import Chart from '../components/graph/Chart'
@ -7,9 +9,10 @@ import Header from '../components/header/Header'
import PageTitle from '../components/pageTitle/PageTitle'
import { EconomiaAcumulada } from '../services/economiaAcumulada'
import { dataEconomiaBruta } from '../services/economiaBruta'
import getAPIClient from '../services/ssrApi'
import { AccumulatedSavingsView } from '../styles/layouts/economy/accumulatedSavings/AccumulatedSavingsView'
export default function AccumulatedSavings() {
export default function AccumulatedSavings({graphData, years}: any) {
return (
<AccumulatedSavingsView>
<Head>
@ -19,8 +22,42 @@ export default function AccumulatedSavings() {
<PageTitle title='Economia Acumulada' subtitle='Economia Bruta Estimada e Acumulada anual (Valores em R$ mil)' />
<section>
<SingleBar title='Economia Bruta Estimada e Acumulada' subtitle='(Valores em R$ mil)' dataset='Consolidada'
dataset1='Estimada' label={EconomiaAcumulada.label} dataProps={EconomiaAcumulada.data2} barLabel month/>
dataset1='Estimada' dataProps={graphData}
label={years} barLabel month/>
</section>
</AccumulatedSavingsView>
)
}
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const apiClient = getAPIClient(ctx)
const { ['@smartAuth-token']: token } = parseCookies(ctx)
let graphData = [];
await apiClient.post('/economy/grossMonthly').then(res => {
graphData = res.data.data
console.log(graphData[0].mes)
}).catch(res => {
console.log(res)
})
const years = graphData.map((value) => value.mes)
if (!token) {
return {
redirect: {
destination: '/',
permanent: false
}
}
}
return {
props: {
graphData,
years,
}
}
}

View File

@ -55,7 +55,6 @@ type FaqInterface = {
}
export default function Sidebar({faqData} : any ) {
<<<<<<< HEAD
const [openModalInativar, setOpenModalInativar] = useState<boolean>(false)
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
@ -104,9 +103,6 @@ export default function Sidebar({faqData} : any ) {
const [selectedfaq, setSelectedfaq] = useState([])
=======
export default function Sidebar({faqData}: any) {
>>>>>>> b045a2e541bdcd6882d728bf6a7d600768b93f1d
async function handleRegisterNewFaq({question, answer}: FaqInterface) {
await api.post('/faq', {
"question": question,

View File

@ -22,7 +22,7 @@ import { parseCookies } from 'nookies'
import { GetServerSideProps } from 'next'
import getAPIClient from '../services/ssrApi'
export default function Dashboard() {
export default function Dashboard({grossAnualGraph, grossAnualYears} : any) {
return (
<DashboardView>
@ -44,7 +44,10 @@ export default function Dashboard() {
<section className='dashboard'>
<GraphCard title='Consumo' subtitle='Gráfico de Consumo'>
<SingleBar title='Economia Bruta' subtitle='(Valores em R$ mil)' label={dataEconomiaBruta.labels} dataset='Consolidada' dataset1='Estimada' dataProps={dataEconomiaBruta.data} barLabel year/>
<SingleBar title='Economia Bruta' subtitle='(Valores em R$ mil)'
dataset='Consolidada' dataset1='Estimada'
dataProps={grossAnualGraph}
label={grossAnualYears} barLabel year/>
</GraphCard>
<GraphCard title='Economia Acumulado' subtitle='Economia Acumulada' singleBar>
<SingleBar title='Economia Bruta Estimada e Acumulada' subtitle='(Valores em R$)' dataset='Acumulada' dataset1='Estimado' label={EconomiaAcumulada.label} dataProps={EconomiaAcumulada.data2} barLabel month/>
@ -66,8 +69,24 @@ export default function Dashboard() {
}
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const apiClient = getAPIClient(ctx)
const { ['@smartAuth-token']: token } = parseCookies(ctx)
let grossAnualGraph = [];
await apiClient.post('/economy/grossAnnual').then(res => {
grossAnualGraph = res.data.data
console.log(grossAnualGraph[0])
}).catch(res => {
console.log(res)
})
const grossAnualYears = grossAnualGraph.map((value) => value.ano)
if (!token) {
return {
redirect: {
@ -77,7 +96,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
}
}
return {
props: {}
props: {
grossAnualGraph,
grossAnualYears,
}
}
}

View File

@ -1,5 +1,6 @@
import { GetServerSideProps } from 'next'
import Head from 'next/head'
import { parseCookies } from 'nookies'
import React from 'react'
import Chart from '../components/graph/Chart'
@ -11,7 +12,19 @@ import getAPIClient from '../services/ssrApi'
import { GrossSavingsView } from '../styles/layouts/economy/grossSavings/GrossSavings'
export default function GrossSavings() {
function addMissingMonths(data) {
console.log(data[0].mes.slice(1, 1))
}
function verifyDataByYear(data) {
if (data.length === 12)
return true
else
return false
}
export default function GrossSavings({graphData, years}: any) {
return (
<GrossSavingsView>
<Head>
@ -20,7 +33,12 @@ export default function GrossSavings() {
<Header name='' />
<PageTitle title='Economia Bruta' subtitle='Economia Bruta Estimada e Acumulada anual (Valores em R$ mil)' />
<section>
<SingleBar title='Economia Bruta' subtitle='(Valores em R$ mil)' label={dataEconomiaBruta.labels} dataset='Consolidada' dataset1='Estimada' dataProps={dataEconomiaBruta.data} barLabel year/>
<SingleBar title='Economia Bruta' subtitle='(Valores em R$ mil)'
dataset='Consolidada' dataset1='Estimada'
dataProps={graphData}
label={years} barLabel year/>
</section>
</GrossSavingsView>
)
@ -29,23 +47,17 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
const apiClient = getAPIClient(ctx)
const { ['@smartAuth-token']: token } = parseCookies(ctx)
let clients = [];
let notifications = [];
await apiClient.get('/user').then(res => {
clients = res.data
}).catch(res => {
console.log(res)
})
await apiClient.get('/economy/grossAnnual').then(res => {
grossSaving = res.data
grossSaving.map(value)
let graphData = [];
await apiClient.post('/economy/grossAnnual').then(res => {
graphData = res.data.data
console.log(graphData[0])
}).catch(res => {
console.log(res)
})
const years = graphData.map((value) => value.ano)
console.log(years)
if (!token) {
return {
redirect: {
@ -55,10 +67,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
}
}
return {
props: {
clients,
grossSaving
graphData,
years,
}
}
}