-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
188 lines (183 loc) · 5.67 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lets draw some Venn Diagrams</title>
<link rel="stylesheet" href="./src/index.css" />
<script type="module" src="/src/venn.ts"></script>
<script
defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"
></script>
</head>
<body>
<div
style="
display: flex;
flex-direction: column;
gap: 0.5em;
padding: 1em;
flex-wrap: wrap;
"
>
<h1>
This is a demo of drawing Venn Diagrams using Canvas element, from
within a web-component!
</h1>
<p>
This canvas is brought to you by a Web Component called
<code><draw-venn></draw-venn></code>. This web-component is
written in Lit.
</p>
<p>Accompanying blog: TODO</p>
<p>
While the core is written to be extensive, this is still not! For now,
the best bet to tinker would be to clone the backing repo. Don't forget
to give a star if you think this deserves it!
</p>
<p>Interaction brought to you by AlpineJS</p>
<p>Your host is Saro @ Saravana kumar, and I am looking for a job right now!</p>
<div style="display: flex; gap: 0.5em; flex-wrap: wrap">
<div>
<draw-venn value="A∩B" />
</div>
<div>
<draw-venn value="(A∩B)-C" />
</div>
<div>
<draw-venn value="A∪B" />
</div>
<div>
<draw-venn value="A∩C" />
</div>
<div>
<draw-venn value="A∪C" />
</div>
<div>
<draw-venn value="(A∪C)∩B" />
</div>
<div x-data="vennCommands" style="border:1px solid gray;border-radius: 5px;padding: 1em;">
<p style="background-color: yellow; flex-wrap: wrap">
!!! Click/Hover on the expressions below to see a live popup of the
results!
>
</p>
<template
x-for="(commandSequence,seqIndex) in commands"
:key="seqIndex"
>
<div>
<div style="display: flex">
<template
x-for="(command,commandIndex) in commandSequence"
:key="commandIndex"
>
<div
style="display: flex; font-size: 2em"
x-on:mouseover="currentCommand = command; window.scrollBy(0, window.innerHeight)"
x-on:click="currentCommand = command;"
>
<span
x-text="command.label"
:style="hiStyleFor(command, commandIndex, seqIndex)"
></span>
</div>
</template>
</div>
</div>
</template>
<div class="result-holder">
<draw-venn :value="currentCommand && currentCommand.command" />
</div>
</div>
</div>
</div>
<div>
<p> Initial Version: 25th July 2024 </p>
</div>
<script>
document.addEventListener("alpine:init", () => {
Alpine.data("vennCommands", () => ({
currentCommand: null,
commands: [
[
{
command: "A∪C",
label: "(A∪C)",
range: [0, 0],
},
{
command: "(A∪C)∩B",
label: "∩B",
range: [1, 0],
},
],
[
{
command: "A∩(B∪C)",
label: "A∩",
range: [0, 1],
},
{
command: "B∪C",
label: "(B∪C)",
range: [0, 0],
},
],
[
{
command: "A∩B",
label: "(A∩B)",
range: [0, 0],
},
{
command: "(A∩B)∪(A∩C)",
label: "∪",
range: [1, 1],
},
{
command: "A∩C",
label: "(A∩C)",
range: [0, 0],
},
],
],
hiStyleFor: function (command, commandIndex, seqIndex) {
if (!this.currentCommand) {
return {};
}
const currentCommandSeqIndex = this.commands.findIndex((part) =>
part.find((p) => p.command == this.currentCommand.command)
);
if (currentCommandSeqIndex != seqIndex) {
return {};
}
const currentCommandIndex = this.commands[seqIndex].findIndex(
(v) => v.command == this.currentCommand.command
);
const [leftRange, rightRange] = this.currentCommand.range;
let color;
if (commandIndex == currentCommandIndex) {
color = "yellow";
} else if (commandIndex < currentCommandIndex) {
color =
currentCommandIndex - commandIndex <= leftRange
? "yellow"
: "none";
} else if (commandIndex > currentCommandIndex) {
color =
commandIndex - currentCommandIndex <= rightRange
? "yellow"
: "none";
}
return {
backgroundColor: color,
};
},
}));
});
</script>
</body>
</html>