-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcade-popup-chart
98 lines (93 loc) · 2.81 KB
/
arcade-popup-chart
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
/// get the intersecting sites per Autonomous Community and change the Spanish words of the attribute "tecnologia_primaria" to Egnlish
var intersectProductionSite = Intersects(FeatureSetByName($map, "Energy Production Sites"), $feature)
var oldName1 = "Eolica"
var newName1 = "Wind Power"
var oldName2 = "Solar"
var newName2 = "Solar"
var oldName3 = "Hidraulica"
var newName3 = "Hydraulics"
var oldName4 = "Gas"
var newName4 = "Gas"
var oldName5 = "Petroleo"
var newName5 = "Oil"
var oldName6 = "Carbon"
var newName6 = "Carbon"
var oldName7 = "Residuos"
var newName7 = "Waste"
var oldName8 = "Nuclear"
var newName8 = "Nuclear"
var oldName9 = "Biomasa"
var newName9 = "Biomass"
// group by the Technology Type of the Production Site and count them
var ProductionTypeList = GroupBy(intersectProductionSite, 'tecnologia_primaria', {name: 'count', expression: '1', statistic:'COUNT'})
// order the grouped list by the count (descending)
var sortedProduction = OrderBy(ProductionTypeList, 'count DESC')
var chartValues = {}
var chartNames = []
/// load the values for the chart and set the new defined English words
for (var f in sortedProduction) {
if (f.tecnologia_primaria == oldName1) {
chartValues[newName1] = f.count
Push(chartNames, newName1)
} else {
if (f.tecnologia_primaria == oldName2) {
chartValues[newName2] = f.count
Push(chartNames, newName2)
} else {
if (f.tecnologia_primaria == oldName3) {
chartValues[newName3] = f.count
Push(chartNames, newName3)
} else {
if (f.tecnologia_primaria == oldName4) {
chartValues[newName4] = f.count
Push(chartNames, newName4)
} else {
if (f.tecnologia_primaria == oldName5) {
chartValues[newName5] = f.count
Push(chartNames, newName5)
} else {
if (f.tecnologia_primaria == oldName6) {
chartValues[newName6] = f.count
Push(chartNames, newName6)
} else {
if (f.tecnologia_primaria == oldName7) {
chartValues[newName7] = f.count
Push(chartNames, newName7)
} else {
if (f.tecnologia_primaria == oldName8) {
chartValues[newName8] = f.count
Push(chartNames, newName8)
} else {
if (f.tecnologia_primaria == oldName9) {
chartValues[newName9] = f.count
Push(chartNames, newName9)
}
}
}
}
}
}
}
}
}
}
/// return a text if there are no Energy Production Sites in a Autonomous Community
if (Count(chartNames) == 0) {
return {
type: 'text',
text: 'There are no Energy Production Sites here!'
}
}
/// return the bar chart
return {
type: 'media',
title: 'Energy Production Sites by Technology',
description: 'Chart showing the total of Energy Production Sites by Technology type',
attributes: chartValues,
mediaInfos: [{
type: 'columnchart',
value: {
fields: chartNames
}
}]
}