Skip to content

Commit f69921d

Browse files
committed
feat: add keyboard shortcuts
1 parent eca0a06 commit f69921d

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/components/TopMenu.svelte

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@
4141
function closeDialog() {
4242
doDialog = null;
4343
}
44+
45+
function keyPress(e: KeyboardEvent) {
46+
switch (e.key) {
47+
case 'f':
48+
if (chart) {
49+
chart.fitData(true);
50+
}
51+
break;
52+
case 'p':
53+
$navMode = NavMode.pan;
54+
break;
55+
case 'z':
56+
$navMode = NavMode.zoom;
57+
break;
58+
case 'c':
59+
$navMode = NavMode.crop;
60+
break;
61+
case 'r':
62+
randomizeColors();
63+
break;
64+
case 's':
65+
$isShowingPoints = !$isShowingPoints;
66+
break;
67+
}
68+
}
4469
</script>
4570

4671
<div class="menu" {style} data-tour="top">
@@ -49,7 +74,7 @@
4974
type="button"
5075
class="uk-button uk-button-default uk-button-small"
5176
on:click|preventDefault={randomizeColors}
52-
title="Randomize Colors"
77+
title="Randomize Colors<br/>(Keyboard Shortcut: r)"
5378
data-tour="random"
5479
uk-tooltip><Fa icon={faPaintBrush} /></button
5580
>
@@ -58,7 +83,7 @@
5883
class="uk-button uk-button-default uk-button-small"
5984
disabled={!chart}
6085
on:click|preventDefault={() => (chart ? chart.fitData(true) : null)}
61-
title="Fit data to screen"
86+
title="Fit Data to Screen<br/>(Keyboard Shortcut: f)"
6287
data-tour="fit"
6388
uk-tooltip><Fa icon={faExpand} /></button
6489
>
@@ -67,7 +92,7 @@
6792
class="uk-button uk-button-default uk-button-small"
6893
class:uk-active={$isShowingPoints}
6994
on:click|preventDefault={() => ($isShowingPoints = !$isShowingPoints)}
70-
title="Show or Hide points"
95+
title="Show or Hide points<br/>(Keyboard Shortcut: s)"
7196
data-tour="points"
7297
uk-tooltip><Fa icon={faEllipsisH} /></button
7398
>
@@ -119,23 +144,23 @@
119144
type="button"
120145
class="uk-button uk-button-default uk-button-small"
121146
class:uk-active={$navMode === NavMode.pan}
122-
title="Pan Mode"
147+
title="Pan Mode<br/>(Keyboard Shortcut: p)"
123148
uk-tooltip
124149
on:click|preventDefault={() => ($navMode = NavMode.pan)}><Fa icon={faArrowsAlt} /></button
125150
>
126151
<button
127152
type="button"
128153
class="uk-button uk-button-default uk-button-small"
129154
class:uk-active={$navMode === NavMode.crop}
130-
title="Crop Mode"
155+
title="Crop Mode<br/>(Keyboard Shortcut: c)"
131156
uk-tooltip
132157
on:click|preventDefault={() => ($navMode = NavMode.crop)}><Fa icon={faCrop} /></button
133158
>
134159
<button
135160
type="button"
136161
class="uk-button uk-button-default uk-button-small"
137162
class:uk-active={$navMode === NavMode.zoom}
138-
title="Zoom Mode"
163+
title="Zoom Mode<br/>(Keyboard Shortcut: z)"
139164
uk-tooltip
140165
on:click|preventDefault={() => ($navMode = NavMode.zoom)}><Fa icon={faSearchPlus} /></button
141166
>
@@ -148,6 +173,8 @@
148173
<DirectLinkDialog {chart} on:close={closeDialog} />
149174
{/if}
150175

176+
<svelte:window on:keypress={keyPress} />
177+
151178
<style>
152179
.menu {
153180
display: flex;

src/tour.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ tour.addStep({
118118
on: 'auto',
119119
},
120120
title: 'Randomize Colors',
121-
text: `This action will recolor all visible datasets`,
121+
text: `This action will recolor all visible datasets. Keyboard Shortcut: r`,
122122
buttons: nextCancel,
123123
});
124124
tour.addStep({
@@ -127,7 +127,7 @@ tour.addStep({
127127
on: 'auto',
128128
},
129129
title: 'Fit Data to Screen',
130-
text: `This action will changes the chart view such that all selected datasets are fully shown`,
130+
text: `This action will changes the chart view such that all selected datasets are fully shown. Keyboard Shortcut: f`,
131131
buttons: nextCancel,
132132
});
133133
tour.addStep({
@@ -136,7 +136,7 @@ tour.addStep({
136136
on: 'auto',
137137
},
138138
title: 'Toggle Point Rendering',
139-
text: `This action will change whether points should be rendered representing individual data points of the time series`,
139+
text: `This action will change whether points should be rendered representing individual data points of the time series. Keyboard Shortcut: s`,
140140
buttons: nextCancel,
141141
});
142142

0 commit comments

Comments
 (0)