Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 27 additions & 113 deletions src/components/ECharts/UnlocksChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDarkModeManager } from '~/contexts/LocalStorage'
import type { IChartProps } from '../types'
import { useDefaults } from '../useDefaults'
import { mergeDeep, stringToColour } from '../utils'
import useWindowSize from '~/hooks/useWindowSize'

// TODO remove color prop and use stackColors by default
export default function AreaChart({
Expand Down Expand Up @@ -34,6 +35,8 @@ export default function AreaChart({
const chartsStack = stacks || customLegendOptions

const [isThemeDark] = useDarkModeManager()
const windowSize = useWindowSize()
const isMobile = windowSize.width && windowSize.width < 768

const defaultChartSettings = useDefaults({
color,
Expand Down Expand Up @@ -83,62 +86,17 @@ export default function AreaChart({
},
data: [],
...(hallmarks && {
markLine:
hallmarks.length > 8
? {
symbol: 'none',
data: hallmarks.map(([date, event]) => [
{
name: event,
xAxis: +date * 1e3,
yAxis: 0,
label: {
show: false,
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontWeight: 500,
position: 'insideEndTop'
},
emphasis: {
label: {
show: true, // Show on hover
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontWeight: 500,
position: 'insideEndTop'
}
}
},
{
name: 'end',
xAxis: +date * 1e3,
yAxis: 'max',
y: 0
}
])
}
: {
data: hallmarks.map(([date, event], index) => [
{
name: event,
xAxis: +date * 1e3,
yAxis: 0,
label: {
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontWeight: 500
}
},
{
name: 'end',
xAxis: +date * 1e3,
yAxis: 'max',
y: Math.max(hallmarks.length * 40 - index * 40, 40)
}
])
markLine: {
data: hallmarks.map(([date, event], index) => [
{
name: event,
xAxis: +date * 1e3,
yAxis: 0,
label: {
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: isMobile ? 10 : 14,
fontWeight: 500
}
})
}
Expand Down Expand Up @@ -188,62 +146,17 @@ export default function AreaChart({
} as { color?: echarts.graphic.LinearGradient }),
data: [],
...(hallmarks && {
markLine:
hallmarks.length > 8
? {
symbol: 'none',
data: hallmarks.map(([date, event]) => [
{
name: event,
xAxis: +date * 1e3,
yAxis: 0,
label: {
show: false,
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontWeight: 500,
position: 'insideEndTop'
},
emphasis: {
label: {
show: true, // Show on hover
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontWeight: 500,
position: 'insideEndTop'
}
}
},
{
name: 'end',
xAxis: +date * 1e3,
yAxis: 'max',
y: 0
}
])
}
: {
data: hallmarks.map(([date, event], index) => [
{
name: event,
xAxis: +date * 1e3,
yAxis: 0,
label: {
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontWeight: 500
}
},
{
name: 'end',
xAxis: +date * 1e3,
yAxis: 'max',
y: Math.max(hallmarks.length * 40 - index * 40, 40)
}
])
markLine: {
data: hallmarks.map(([date, event], index) => [
{
name: event,
xAxis: +date * 1e3,
yAxis: 0,
label: {
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: isMobile ? 10 : 14,
fontWeight: 500
}
})
}
Expand Down Expand Up @@ -286,7 +199,8 @@ export default function AreaChart({
hideGradient,
customLegendName,
legendOptions,
expandTo100Percent
expandTo100Percent,
isMobile
])

const createInstance = useCallback(() => {
Expand Down
7 changes: 5 additions & 2 deletions src/containers/ProtocolOverview/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDefaults } from '~/components/ECharts/useDefaults'
import { mergeDeep } from '~/components/ECharts/utils'
import { formattedNum } from '~/utils'
import { BAR_CHARTS, ProtocolChartsLabels, yAxisByChart } from './constants'
import useWindowSize from '~/hooks/useWindowSize'

const customOffsets = {
Contributors: 60,
Expand Down Expand Up @@ -32,6 +33,8 @@ export default function ProtocolLineBarChart({
}) {
const id = useId()
const isCumulative = groupBy === 'cumulative'
const windowSize = useWindowSize()
const isMobile = windowSize.width && windowSize.width < 768

const defaultChartSettings = useDefaults({
color,
Expand Down Expand Up @@ -138,7 +141,7 @@ export default function ProtocolLineBarChart({
label: {
color: isThemeDark ? 'rgba(255, 255, 255, 1)' : 'rgba(0, 0, 0, 1)',
fontFamily: 'sans-serif',
fontSize: 14,
fontSize: isMobile ? 10 : 14,
fontWeight: 500
}
},
Expand All @@ -163,7 +166,7 @@ export default function ProtocolLineBarChart({
series,
allYAxis: Object.entries(indexByYAxis) as Array<[ProtocolChartsLabels, number | undefined]>
}
}, [chartData, chartColors, hallmarks, isThemeDark, isCumulative, rangeHallmarks])
}, [chartData, chartColors, hallmarks, isThemeDark, isCumulative, rangeHallmarks, isMobile])

const createInstance = useCallback(() => {
const instance = echarts.getInstanceByDom(document.getElementById(id))
Expand Down