generated from taylorbryant/gatsby-starter-tailwind
-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
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,17 @@ | ||
import { TickType } from '../../js/types' | ||
import DifficultyPyramid from './DifficultyPyramid' | ||
import OverviewChart from './OverviewChart' | ||
|
||
export interface ChartsSectionProps { | ||
tickList: TickType[] | ||
} | ||
const ChartsSection: React.FC<ChartsSectionProps> = ({ tickList }) => { | ||
return ( | ||
<section className='flex flex-col gap-6'> | ||
<OverviewChart tickList={tickList} /> | ||
<DifficultyPyramid tickList={tickList} /> | ||
</section> | ||
) | ||
} | ||
|
||
export default ChartsSection |
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,91 @@ | ||
import { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, CartesianGrid } from 'recharts' | ||
import { getScale } from '@openbeta/sandbag' | ||
|
||
import { TickType } from '../../js/types' | ||
import { maxSorted } from 'simple-statistics' | ||
/** | ||
* Assume grades are YDS or Vscale for now since we don't store | ||
* grade context with ticks, nor do we have a way to get score | ||
* without knowing the grade system | ||
*/ | ||
export const ydsScale = getScale('yds') | ||
export const vScale = getScale('vscale') | ||
|
||
interface DifficultyPyramidProps { | ||
tickList: TickType[] | ||
} | ||
|
||
const DifficultyPyramid: React.FC<DifficultyPyramidProps> = ({ tickList }) => { | ||
const gradeHistogram = new Map<number, number>() | ||
|
||
if (tickList == null || tickList.length < 1) return null | ||
|
||
tickList.forEach((tick) => { | ||
const score = getScoreUSAForRouteAndBoulder(tick.grade) | ||
if (score > 0) { | ||
const count = gradeHistogram.get(score) | ||
if (count == null) { | ||
gradeHistogram.set(score, 0) | ||
} else { | ||
gradeHistogram.set(score, count + 1) | ||
} | ||
} | ||
}) | ||
|
||
const sortedKeys = Array.from(gradeHistogram.keys()).sort((a, b) => a - b) | ||
const sortedValues = Array.from(gradeHistogram.values()).sort((a, b) => a - b) | ||
const yOffset = maxSorted(sortedValues) | ||
|
||
const chartData = sortedKeys.map(key => { | ||
const value = gradeHistogram.get(key) ?? 0 | ||
return ({ | ||
x: key, | ||
xBottom: key, | ||
hackRange: [value + yOffset, -value + yOffset] | ||
}) | ||
}) | ||
return ( | ||
<div className='w-full'> | ||
<h3 className='ml-16 py-4'> | ||
Difficulty Pyramid | ||
</h3> | ||
<ResponsiveContainer height={300}> | ||
<AreaChart data={chartData} margin={{ right: 80 }}> | ||
<CartesianGrid stroke='#f5f5f5' /> | ||
|
||
<XAxis | ||
orientation='bottom' | ||
dataKey='xBottom' | ||
tick={{ fontSize: '10' }} | ||
tickFormatter={(value) => { | ||
if (value == null) return '' | ||
const yds = ydsScale?.getGrade(parseInt(value)) ?? '' | ||
const vscale = vScale?.getGrade(parseInt(value)) ?? '' | ||
return `${yds}/${vscale}` | ||
}} | ||
/> | ||
|
||
<YAxis | ||
// tickCount={8} | ||
tickFormatter={(value) => { | ||
const actual = parseInt(value) - yOffset | ||
return `${actual > 0 ? actual : ''}` | ||
}} | ||
/> | ||
|
||
<Area type='basis' stroke='none' dataKey='hackRange' fillOpacity={1} fill='rgb(6 182 212)' /> | ||
</AreaChart> | ||
</ResponsiveContainer> | ||
</div> | ||
) | ||
} | ||
|
||
export default DifficultyPyramid | ||
|
||
const getScoreUSAForRouteAndBoulder = (grade: string): number => { | ||
let score = ydsScale?.getScore(grade)[0] as number ?? -1 | ||
if (score < 0) { | ||
score = vScale?.getScore(grade)[0] as number ?? -1 | ||
} | ||
return score | ||
} |
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
1f5d605
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
open-tacos – ./
open-tacos-git-develop-openbeta-dev.vercel.app
open-tacos-openbeta-dev.vercel.app
openbeta.io
openclimbmap.com
www.openbeta.io
tacos.openbeta.io