-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
230 lines (216 loc) · 8.36 KB
/
index.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<html lang="pl">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>BJCP beer styles matrix</title>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/components/icon.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="application">
<div class="flex p-8 flex-wrap justify-start lg:justify-center xl:justify-center bg-gray-100">
<div class="flex p-4 flex-wrap">
<div class="w-full md:w-16 lg:w-16 xl:w-16 h-16 p-2 text-md m-0 md:m-1 lg:m-1 xl:m-1 flex justify-start lg:justify-center xl:justify-center text-center sm:text-left items-center uppercase">
<span class="opacity-50">display by</span>
</div>
<div class="w-16 h-16 p-2 text-xs m-1 cursor-pointer flex justify-start lg:justify-center xl:justify-center text-center items-center uppercase" v-for="trait in traits" @click="setDisplayBy(trait)" :class="'bg-'+trait.background+'-400'" v-if="trait.groupable">
<span class="w-full opacity-50 text-center">{{ trait.label }}</span>
</div>
</div>
<div class="flex p-4 flex-wrap">
<div class="w-full md:w-16 lg:w-16 xl:w-16 h-8 md:h-16 lg:h-16 xl:h-16 p-2 text-md m-0 md:m-1 lg:m-1 xl:m-1 ml-0 lg:ml-8 xl:ml-12 flex justify-start lg:justify-center xl:justify-center text-center sm:text-left items-center uppercase">
<span class="opacity-50">order by</span>
</div>
<div class="w-16 h-16 p-2 text-xs m-1 cursor-pointer flex justify-center text-center items-center uppercase" v-for="trait in traits" @click="setOrderBy(trait)" :class="'bg-'+trait.background+'-400'">
<span class="w-full opacity-50 text-center">{{ trait.label }}</span>
</div>
</div>
<div class="flex p-4 flex-wrap">
<div class="w-16 h-16 p-2 text-sm m-1 ml-0 lg:ml-8 xl:ml-8 flex justify-center text-center items-center uppercase">
<span class="opacity-50">filter by tag</span>
</div>
<div class="inline-block relative">
<select class="w-48 h-16 p-2 text-xs m-1 flex justify-center text-center items-center uppercase bg-gray-300 appearance-none" @change="selectTag($event)">
<option value="" @click="tagFilter = null"></option>
<option v-for="tag in tags">{{ tag.label }}</option>
</select>
</div>
</div>
</div>
<div class="flex" id="content">
<div class="m-4 flex-1 flex flex-wrap content-start justify-center" id="matrix">
<div class="m-1 cursor-pointer flex justify-center text-center items-center uppercase" v-for="style in computedStyles" :class="styleBox(style)" @click="selectStyle(style)">
<span class="opacity-50">{{ style.label.name }}</span>
</div>
</div>
<div id="details" class="flex-1 m-4" v-if="selected">
<h1 class="text-4xl mb-8">
{{ selected.label.name }}
</h1>
<div class="flex mb-8 justify-between" v-if="selected.stats">
<div class="flex-1" v-for="stat in stats" v-if="selected.stats[stat.index]">
<h2 class="uppercase text-gray-700 text-sm">{{ stat.label }}</h2>
<div class="text-2xl">{{ selected.stats[stat.index].low }}-{{ selected.stats[stat.index].high }}</div>
</div>
</div>
<div v-for="p in paragraphs" class="mb-8" v-if="selected[p]">
<h2 class="uppercase text-gray-700 text-sm">{{ p }}</h2>
<p>{{ selected[p] }}</p>
</div>
<div class="flex mb-8">
<div class="flex-1">
<h2 class="uppercase text-gray-700 text-sm">tags</h2>
<div v-for="tag in selected.tags">
<i class="text-gray-500 tag icon"></i>
{{ tag }}
</div>
</div>
<div class="flex-1">
<h2 class="uppercase text-gray-700 text-sm">commercial examples</h2>
<div v-for="example in selected.examples">
<a :href="'https://www.google.com/search?q=' + example" target="_blank">
<i class="text-gray-500 google icon"></i>
{{ example }}
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
new Vue({
el: "#application",
data() {
return {
styles: [],
selected: null,
paragraphs: ["impression", "aroma", "appearance", "flavor", "mouthfeel", "comments", "history", "ingredients", "comparison"],
traits: [
{ label: "index", index: "index", background: "orange", groupable: false },
{ label: "name", index: "name", background: "purple", groupable: false },
{ label: "color", index: "srm", background: "yellow", groupable: true },
{ label: "IBU", index: "ibu", background: "green", groupable: true },
{ label: "ABV", index: "abv", background: "red", groupable: true },
],
stats: [
{ label: "original gravity", index: "og" },
{ label: "final gravity", index: "fg" },
{ label: "alcohol by volume", index: "abv" },
{ label: "SRM color", index: "srm" },
{ label: "IBU bitterness", index: "ibu" },
],
displayBy: null,
orderBy: null,
tagFilter: null,
tags: {},
mappings: {
srm: [0, 5, 10, 15, 20, 25, 30],
ibu: [0, 15, 25, 40, 55, 65, 85],
abv: [0, 3, 4, 5, 6, 7.5, 9],
background: [300, 400, 500, 600, 700, 800, 900],
},
}
},
computed: {
computedStyles() {
let styles = this.styles.sort((a, b) => {
if(typeof a.label[this.orderBy.index] === "string") {
return a.label[this.orderBy.index].localeCompare(b.label[this.orderBy.index])
}
return a.label[this.orderBy.index] - b.label[this.orderBy.index]
})
if(this.tagFilter) {
styles = styles.filter(style => this.tagFilter.styles.includes(style.label.index))
}
return styles
},
},
mounted() {
this.displayBy = this.traits[2]
this.orderBy = this.traits[0]
fetch("https://raw.githubusercontent.com/gthmb/bjcp-2015-json/master/json/styleguide-2015.min.json").then(response => response.json()).then(data => {
let index = 0
data.styleguide.class[0].category.forEach(category => {
category.subcategory.forEach(style => {
this.buildStyleLabel(style, index)
this.styles.push(style)
index++
})
})
let ordered = {}
Object.keys(this.tags).sort().forEach(key => {
ordered[key] = this.tags[key]
})
this.tags = ordered
})
},
methods: {
selectStyle(style) {
if(!this.selected || this.selected.id !== style.id) {
this.selected = style
} else {
this.selected = null
}
document.getElementById("content").scrollIntoView()
},
selectTag(event) {
if(!event.target.value) {
this.tagFilter = null
} else {
this.tagFilter = this.tags[event.target.value]
}
},
setDisplayBy(trait) {
this.displayBy = trait
},
setOrderBy(trait) {
this.orderBy = trait
},
buildStyleLabel(style, index) {
let name = style.name.split(": ")
let id = style.id.split("-")
style.label = []
style.label.name = name[name.length - 1]
style.label.id = id[0]
style.label.index = index
style.label.srm = (style.stats && style.stats.srm) ? ((Number(style.stats.srm.low) + Number(style.stats.srm.high)) / 2) : 0
style.label.ibu = (style.stats && style.stats.ibu) ? ((Number(style.stats.ibu.low) + Number(style.stats.ibu.high)) / 2) : 0
style.label.abv = (style.stats && style.stats.abv) ? ((Number(style.stats.abv.low) + Number(style.stats.abv.high)) / 2) : 0
if(style.tags) {
style.tags = style.tags.map(tag => tag.replace("-", " ").replace("-", " "))
style.tags.forEach(tag => {
if(!this.tags[tag]) {
this.tags[tag] = {
label: tag,
styles: [index],
}
} else {
this.tags[tag].styles.push(index)
}
})
}
},
styleBox(style) {
let stat = this.displayBy.index
let background = "bg-gray-300"
for(let i in this.mappings.background) {
if(this.mappings[stat][i] >= style.label[stat]) {
break
}
background = "bg-" + this.displayBy.background + "-" + this.mappings.background[i]
}
if(this.selected) {
if(this.selected.id === style.id) {
return "w-24 h-24 p-2 text-xs shadow-lg " + background
}
return "w-24 h-24 p-2 text-xs opacity-75 " + background
}
return "w-40 h-40 p-5 text-lg " + background
},
},
})
</script>
</html>