Skip to content

Commit 8338ef2

Browse files
committed
Add links to the menu
1 parent 7c649b2 commit 8338ef2

3 files changed

Lines changed: 58 additions & 13 deletions

File tree

example/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@
175175
background: rgba(32, 32, 32, 1);
176176
}
177177

178+
#topbar hr {
179+
border-color: rgba(255, 255, 255, 0.1);
180+
}
181+
178182
#title {
179183
padding: 0;
180184
margin: 0;
@@ -234,6 +238,27 @@
234238
line-height: 0.9rem;
235239
}
236240

241+
#examples {
242+
margin: 0;
243+
padding: 0 0 0 1.25em;
244+
}
245+
246+
#examples li {
247+
margin: 0.125em 0;
248+
}
249+
250+
#examples li:last-child {
251+
margin-bottom: 0;
252+
}
253+
254+
#examples li a {
255+
color: white;
256+
}
257+
258+
#examples li a.active {
259+
font-style: italic;
260+
}
261+
237262
#num-points-value {
238263
min-width: 5rem;
239264
}
@@ -314,6 +339,18 @@ <h1 id="title">Regl Scatterplot</h1>
314339
/>
315340
</label>
316341
<button id="reset">Reset</button>
342+
<hr />
343+
<label>Examples:</label>
344+
<ul id="examples">
345+
<li>
346+
<a id="example-basic" href="index.html">Basic</a>
347+
</li>
348+
<li>
349+
<a id="example-background" href="texture-background.html"
350+
>Background Image</a
351+
>
352+
</li>
353+
</ul>
317354
</aside>
318355
</header>
319356
<div id="canvas-wrapper">

example/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const pointSizeValEl = document.querySelector('#point-size-value');
1010
const opacityEl = document.querySelector('#opacity');
1111
const opacityValEl = document.querySelector('#opacity-value');
1212
const resetEl = document.querySelector('#reset');
13+
const exampleEl = document.querySelector('#example-basic');
14+
15+
exampleEl.setAttribute('class', 'active');
16+
exampleEl.removeAttribute('href');
1317

1418
let { width, height } = canvas.getBoundingClientRect();
1519

@@ -24,13 +28,13 @@ const lassoMinDist = 2;
2428
const showRecticle = true;
2529
const recticleColor = [1, 1, 0.878431373, 0.33];
2630

27-
const pointoverHandler = pointId => {
31+
const pointoverHandler = (pointId) => {
2832
console.log('Over point:', pointId);
2933
const [x, y, category, value] = points[pointId];
3034
console.log(`X: ${x}\nY: ${y}\nCategory: ${category}\nValue: ${value}`);
3135
};
3236

33-
const pointoutHandler = pointId => {
37+
const pointoutHandler = (pointId) => {
3438
console.log('Out point:', pointId);
3539
const [x, y, category, value] = points[pointId];
3640
console.log(`X: ${x}\nY: ${y}\nCategory: ${category}\nValue: ${value}`);
@@ -60,7 +64,7 @@ const scatterplot = createScatterplot({
6064
lassoMinDist,
6165
pointSize,
6266
showRecticle,
63-
recticleColor
67+
recticleColor,
6468
});
6569

6670
console.log(scatterplot.get('pointColorActive'));
@@ -78,52 +82,52 @@ const resizeHandler = () => {
7882

7983
window.addEventListener('resize', resizeHandler);
8084

81-
const generatePoints = num =>
85+
const generatePoints = (num) =>
8286
new Array(num).fill().map(() => [
8387
-1 + Math.random() * 2, // x
8488
-1 + Math.random() * 2, // y
8589
Math.round(Math.random()), // category
86-
Math.random() // value
90+
Math.random(), // value
8791
]);
8892

89-
const setNumPoint = newNumPoints => {
93+
const setNumPoint = (newNumPoints) => {
9094
numPoints = newNumPoints;
9195
numPointsEl.value = numPoints;
9296
numPointsValEl.innerHTML = numPoints;
9397
points = generatePoints(numPoints);
9498
scatterplot.draw(points);
9599
};
96100

97-
const numPointsInputHandler = event => {
101+
const numPointsInputHandler = (event) => {
98102
numPointsValEl.innerHTML = `${+event.target
99103
.value} <em>release to redraw</em>`;
100104
};
101105

102106
numPointsEl.addEventListener('input', numPointsInputHandler);
103107

104-
const numPointsChangeHandler = event => setNumPoint(+event.target.value);
108+
const numPointsChangeHandler = (event) => setNumPoint(+event.target.value);
105109

106110
numPointsEl.addEventListener('change', numPointsChangeHandler);
107111

108-
const setPointSize = newPointSize => {
112+
const setPointSize = (newPointSize) => {
109113
pointSize = newPointSize;
110114
pointSizeEl.value = pointSize;
111115
pointSizeValEl.innerHTML = pointSize;
112116
scatterplot.set({ pointSize });
113117
};
114118

115-
const pointSizeInputHandler = event => setPointSize(+event.target.value);
119+
const pointSizeInputHandler = (event) => setPointSize(+event.target.value);
116120

117121
pointSizeEl.addEventListener('input', pointSizeInputHandler);
118122

119-
const setOpacity = newOpacity => {
123+
const setOpacity = (newOpacity) => {
120124
opacity = newOpacity;
121125
opacityEl.value = opacity;
122126
opacityValEl.innerHTML = opacity;
123127
scatterplot.set({ opacity });
124128
};
125129

126-
const opacityInputHandler = event => setOpacity(+event.target.value);
130+
const opacityInputHandler = (event) => setOpacity(+event.target.value);
127131

128132
opacityEl.addEventListener('input', opacityInputHandler);
129133

@@ -156,7 +160,7 @@ const colorsScale = [
156160
'#b8e0d7',
157161
'#c8ecdc',
158162
'#ddf7df',
159-
'#ffffe0' // bright yellow
163+
'#ffffe0', // bright yellow
160164
];
161165
scatterplot.set({ colorBy: 'value', pointColor: colorsScale });
162166

example/texture-background.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const pointSizeValEl = document.querySelector('#point-size-value');
1010
const opacityEl = document.querySelector('#opacity');
1111
const opacityValEl = document.querySelector('#opacity-value');
1212
const resetEl = document.querySelector('#reset');
13+
const exampleEl = document.querySelector('#example-background');
14+
15+
exampleEl.setAttribute('class', 'active');
16+
exampleEl.removeAttribute('href');
1317

1418
let { width, height } = canvas.getBoundingClientRect();
1519

0 commit comments

Comments
 (0)