-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcssLinegraph.vue
More file actions
172 lines (151 loc) · 3.27 KB
/
cssLinegraph.vue
File metadata and controls
172 lines (151 loc) · 3.27 KB
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
<template>
<section data-root="css-linegraph">
<div class="line-controls">
<button-style @click="makeData" >
Generate Data
</button-style>
</div>
<table class="line-graph">
<thead class="line-head">
<tr class="line-labels">
<th data-head="index">index</th>
<th data-head="value">value</th>
</tr>
</thead>
<tbody class="line-data"
:style="dataStyle()">
<tr v-for="(item, index) in getData"
:key="index"
:style="{'--value': item}"
:data-item="index" >
<td data-val="index">{{ index }}</td>
<td data-val="value">{{ item }}</td>
</tr>
</tbody>
</table>
</section>
</template>
<script>
import ButtonStyle from '~/components/utility/ButtonStyle.vue';
export default {
components: {
ButtonStyle,
},
data() {
return {
x: 15,
y: 100,
plot: [],
}
},
computed: {
getData() {
if (!this.plot.length) {
this.makeData();
}
return this.plot;
},
},
methods: {
randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
},
makeData() {
this.plot = [...Array(this.x)].map(() => this.randomInt(this.y));
},
dataStyle() {
const style = {};
this.plot.forEach((e, i) => style[`--i-${i}`] = e);
return style;
},
},
}
</script>
<style lang="scss" scoped>
[data-root='css-linegraph'] {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
}
.line-controls {
border-bottom: pattern('border');
display: flex;
justify-content: flex-end;
padding: size('quarter-shim');
text-align: right;
}
// Chart
// -----
.line-graph {
@include font-family('code');
display: grid;
font-size: size('code');
grid-template: 'y data' 1fr
'. x' size('gutter');
grid-template-columns: size('gutter') 1fr;
padding: size('shim') 0 size('shim') size('gutter');
}
.line-head,
.line-labels {
display: grid;
grid-area: 1 / 1 / -1 / -1;
grid-template: inherit;
}
[data-head] {
align-self: center;
justify-self: center;
}
[data-head='index'] {
grid-area: x;
}
[data-head='value'] {
display: block;
grid-area: y;
writing-mode: vertical-rl;
}
$x: 15;
$one: percentage(1 / $x);
$clip: ((0 100%),);
$gradients: ();
@for $i from 0 to $x {
$h: percentage($i / $x);
$point: ($h calc(100% - var(--i-#{$i}, 50) * 1%));
$clip: append($clip, $point);
$grad: radial-gradient(
circle at $point,
black 3px,
transparent 3px
);
$gradients: append($gradients, $grad, 'comma');
}
$clip: append($clip, (100% - $one 100%));
.line-data {
display: grid;
grid-area: data;
grid-template-columns: repeat($x, minmax(0, 1fr));
grid-template-rows: auto size('gutter');
position: relative;
@include before('') {
background-image:
$gradients,
linear-gradient(to top, pink, lightsteelblue)
;
clip-path: polygon($clip);
grid-area: 1 / 1 / span 1 / -1;
transition: all 300ms ease;
}
}
[data-item] {
grid-row: 2;
}
@for $i from 0 to $x {
[data-item='#{$i}'] {
grid-column: $i + 1;
}
}
[data-val='index'] {
transform: translateX(-50%);
}
[data-val='value'] {
@include is-hidden;
}
</style>