/
HomeMarimekkoDemo.tsx
88 lines (84 loc) · 2.74 KB
/
HomeMarimekkoDemo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React, { useMemo } from 'react'
import random from 'lodash/random'
import { Marimekko } from '@nivo/marimekko'
import { useHomeTheme } from './theme'
import { dimensions } from './dimensions'
const getRandomValue = () => random(0, 32)
const generateData = () =>
[`it's good`, `it's sweet`, `it's spicy`, 'worth eating', 'worth buying'].map(statement => ({
statement,
participation: getRandomValue(),
stronglyAgree: getRandomValue(),
agree: getRandomValue(),
disagree: getRandomValue(),
stronglyDisagree: getRandomValue(),
}))
export const HomeMarimekkoDemo = () => {
const data = useMemo(() => generateData(), [])
const { colors, nivoTheme } = useHomeTheme()
return (
<div id="marimekko">
<Marimekko
width={dimensions.width}
height={dimensions.height}
margin={dimensions.margin}
data={data}
id="statement"
value="participation"
dimensions={[
{
id: 'disagree strongly',
value: 'stronglyDisagree',
},
{
id: 'disagree',
value: 'disagree',
},
{
id: 'agree',
value: 'agree',
},
{
id: 'agree strongly',
value: 'stronglyAgree',
},
]}
colors={colors}
defs={[
{
id: 'lines',
type: 'patternLines',
background: 'rgba(0, 0, 0, 0)',
color: 'inherit',
rotation: -45,
lineWidth: 6,
spacing: 10,
},
]}
fill={[
{
match: {
id: 'agree strongly',
},
id: 'lines',
},
{
match: {
id: 'disagree strongly',
},
id: 'lines',
},
]}
borderWidth={1}
borderColor={colors[3]}
innerPadding={6}
offset="expand"
enableGridX={false}
enableGridY={false}
isInteractive={false}
animate={false}
theme={nivoTheme}
/>
</div>
)
}