-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsparklines.html
141 lines (137 loc) · 6.65 KB
/
sparklines.html
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>eurostat-map.js</title>
</head>
<body>
<svg id="map"></svg>
<svg id="map2"></svg>
<!-- <script src="https://unpkg.com/eurostat-map"></script> -->
<script src="../build/eurostatmap.js"></script>
<script>
const MAPWIDTH = 800
const zoom = 6500
const MAP1 = eurostatmap
.map('sparkline')
.width(MAPWIDTH)
.title('Population change across Europe over time')
.subtitle(
'2009 - 2023. <tspan style="fill:#1f77b4 ">Blue</tspan> = overall increase, <tspan style="fill:#d62728">red</tspan> = overall decrease.'
)
//.position({ x: 4900000, y: 3500000, z: zoom })
.bottomText('Line thickness determined by latest population figure. By NUTS1 regions. Source: Eurostat (demo_r_pjanaggr3)')
.nutsLevel(1)
.statSpark(
{ eurostatDatasetCode: 'demo_r_pjanaggr3', filters: { sex: 'T', unit: 'NR' }, unitText: 'people' },
['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023'], //dates
['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023'] //labels
)
.sparkType('line')
.sparkLineWidth(30)
.sparkLineHeight(200)
.sparkLineStrokeWidth((data, index) => {
// console.log(data, index)
let val = data[data.length - 1]?.value
if (val > 10000000) return 3
if (val > 5000000) return 2.5
if (val > 2000000) return 2
if (val > 1000000) return 1.5
return 1
})
.sparkLineColor((dataArray, i) => {
const startPopulation = dataArray[0].value
const endPopulation = dataArray[dataArray.length - 1].value
return endPopulation > startPopulation ? '#1f77b4' : '#d62728'
})
// .sparkLineOpacity((data, index) => {
// let val = data[data.length - 1]?.value
// if (val > 10000000) return 1
// if (val > 5000000) return 0.75
// if (val > 2000000) return 0.5
// if (val > 1000000) return 0.25
// return 0.15
// })
.sparkLineCircleRadius(0)
.nutsbnStroke({ 0: 'black', 1: 'grey', 2: 'grey', 3: 'grey', oth: 'black', co: 'black' })
.nutsbnStrokeWidth({ 0: 0.2, 1: 0.1, 2: 0, 3: 0, oth: 0.1, co: 0.2 })
.tooltip({
xOffset: 30,
yOffset: 10,
fontSize: '12px',
maxWidth: Math.min(400, window.innerWidth),
})
.sparkTooltipChart({
width: 150,
height: 150,
margin: { left: 60, right: 40, top: 20, bottom: 40 },
circleRadius: 1.5,
})
.nutsrgSelFillSty('yellow')
.build()
const MAP2 = eurostatmap
.map('sparkline')
.svgId('map2')
.width(MAPWIDTH)
.title('Percentage population change across Europe over time')
.subtitle(
'2009 - 2023. <tspan style="fill:#1f77b4 ">Blue</tspan> represents an overall increase in total population and <tspan style="fill:#d62728">red</tspan> an overall decrease.'
)
.position({ x: 4900000, y: 3500000, z: zoom })
.bottomText('Line thickness determined by latest population figure. By NUTS1 regions. Source: Eurostat (demo_r_pjanaggr3)')
.nutsLevel(1)
.sparkPercentageChange(true)
.statSpark(
{ eurostatDatasetCode: 'demo_r_pjanaggr3', filters: { sex: 'T', unit: 'NR' }, unitText: 'people' },
['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023'], //dates
['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023'] //labels
)
.sparkType('line')
.sparkLineWidth(35)
.sparkLineHeight(20)
.sparkLineStrokeWidth((data, index) => {
// console.log(data, index)
let val = data[data.length - 1]?.value
if (val > 10000000) return 3
if (val > 5000000) return 2.5
if (val > 2000000) return 2
if (val > 1000000) return 1.5
return 1
})
.sparkLineColor((dataArray, i) => {
const startPopulation = dataArray[0].value
const endPopulation = dataArray[dataArray.length - 1].value
return endPopulation > startPopulation ? '#1f77b4' : '#d62728'
})
// .sparkLineOpacity((data, index) => {
// let val = data[data.length - 1]?.value
// if (val > 10000000) return 1
// if (val > 5000000) return 0.75s
// if (val > 2000000) return 0.5
// if (val > 1000000) return 0.25
// return 0.15
// })
.sparkLineCircleRadius(0)
.nutsbnStroke({ 0: 'black', 1: 'grey', 2: 'grey', 3: 'grey', oth: 'black', co: 'black' })
.nutsbnStrokeWidth({ 0: 0.2, 1: 0.1, 2: 0, 3: 0, oth: 0.1, co: 0.2 })
.tooltip({
xOffset: 30,
yOffset: 10,
fontSize: '12px',
maxWidth: Math.min(400, window.innerWidth),
})
.sparkTooltipChart({
width: 150,
height: 150,
margin: { left: 60, right: 40, top: 20, bottom: 40 },
circleRadius: 1.5,
})
.nutsrgSelFillSty('yellow')
.build()
// setTimeout(() => {
// MAP2.exportMapToPNG()
// }, 3000)
</script>
</body>
</html>