-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Onboarding: Create Issuance modelling chart
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/components/Onboarding/Screens/Apps/IssuanceSettings/IssuanceChart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useMemo } from 'react' | ||
import { ChartBase } from '@components/Onboarding/kit/ChartComponents' | ||
import { ResponsiveLine } from '@nivo/line' | ||
import { useCharts } from '@/providers/Charts' | ||
import { generateElements } from '@/utils/conviction-modelling-helpers' | ||
import { YEARS_IN_SECONDS } from '@/utils/kit-utils' | ||
|
||
const DEFAULT_MAX_MONTH = 12 | ||
const DEFAULT_INCREMENT = 1 / 2 | ||
|
||
const calculateRatio = maxAdjustmentRatioPerSeconds => { | ||
// TODO: calculate ratio... | ||
return 0 | ||
} | ||
const computeChartData = ( | ||
maxAdjustmentRatioPerYear, | ||
targetRatio, | ||
maxMonth, | ||
increment | ||
) => { | ||
const maxAdjustmentRatioPerSeconds = | ||
maxAdjustmentRatioPerYear * YEARS_IN_SECONDS | ||
const timeData = generateElements(maxMonth, increment) | ||
|
||
return timeData.map(time => ({ | ||
x: time, | ||
y: calculateRatio(maxAdjustmentRatioPerSeconds), | ||
})) | ||
} | ||
|
||
const IssuanceChart = ({ | ||
height, | ||
width, | ||
maxAdjustmentRatioPerYear, | ||
targetRatio, | ||
}) => { | ||
const { commonProps, createAxis } = useCharts() | ||
const chartData = useMemo( | ||
() => | ||
computeChartData( | ||
maxAdjustmentRatioPerYear, | ||
targetRatio, | ||
DEFAULT_MAX_MONTH, | ||
DEFAULT_INCREMENT | ||
), | ||
[maxAdjustmentRatioPerYear, targetRatio] | ||
) | ||
return ( | ||
<div> | ||
<ChartBase title="Ratio vs Time" height={height} width={width}> | ||
<ResponsiveLine | ||
{...commonProps} | ||
data={[{ id: 'ratio-time', data: chartData }]} | ||
axisBottom={createAxis('time (months)', 'bottom')} | ||
axisLeft={createAxis('ratio(%)', 'left')} | ||
/> | ||
</ChartBase> | ||
</div> | ||
) | ||
} | ||
|
||
export default IssuanceChart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const MINUTE_IN_SECONDS = 60 | ||
export const HOUR_IN_SECONDS = MINUTE_IN_SECONDS * 60 | ||
export const DAY_IN_SECONDS = HOUR_IN_SECONDS * 24 | ||
export const YEARS_IN_SECONDS = 365 * DAY_IN_SECONDS |