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
|
<template>
<div :style="styles" class="relative flex flex-col justify-between">
<close-icon @click.stop="onClose"
class="absolute top-2 right-2 w-8 h-8 hover:cursor-pointer"/>
<h1 class="text-center text-lg font-bold pt-3 pb-2">
{{stage == 0 ? 'Welcome' : `Tutorial (Step ${stage} of ${lastStage})`}}
</h1>
<transition name="fade" mode="out-in">
<div v-if="stage == 0" :style="contentStyles">
This is a visualiser for exploring the biological Tree of Life.
</div>
<div v-else-if="stage == 1" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} a tile to expand it, showing it's children
</div>
<div v-else-if="stage == 2" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} an expanded tile's title to shrink it
</div>
<div v-else-if="stage == 3" :style="contentStyles">
{{touchDevice ? 'Double tap' : 'Click and hold'}} a tile to hide it's ancestors
<span class="block text-sm brightness-50">
For an expanded tile, {{touchDevice ? 'double tap' : 'click and hold'}} it's title
</span>
</div>
<div v-else-if="stage == 4" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} a tile in the sidebar to unhide it
</div>
<div v-else-if="stage == 5" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} the icon on a tile's bottom-right to
bring up more information
<span class="block text-sm brightness-50">
For an expanded tile, it's to the right of the title
</span>
</div>
<div v-else-if="stage == 6" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} the icon at the top-right to search
<span class="block text-sm brightness-50">
Or press Ctrl-F
</span>
</div>
<div v-else-if="stage == 7" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} the play icon to traverse the tree automatically
</div>
<div v-else-if="stage == 8" :style="contentStyles">
{{touchDevice ? 'Tap' : 'Click'}} the settings icon
</div>
<div v-else-if="stage == 9" :style="contentStyles">
And finally, {{touchDevice ? 'tap' : 'click'}} the help icon for more information
</div>
</transition>
<!-- Buttons -->
<div class="w-full my-2 flex justify-evenly">
<template v-if="stage == 0">
<s-button :style="buttonStyles" @click="onStartTutorial">Start Tutorial</s-button>
<s-button :style="buttonStyles" @click="onSkipTutorial">Skip</s-button>
</template>
<template v-else>
<s-button :class="{invisible: !hidNextPrevOnce && stage == 1}" :disabled="stage == 1"
@click="onPrevClick" :style="buttonStyles">
Prev
</s-button>
<s-button :class="{invisible: !hidNextPrevOnce && stage == 1}"
@click="stage != lastStage ? onNextClick() : onClose()" :style="buttonStyles">
{{stage != lastStage ? 'Next' : 'Finish'}}
</s-button>
</template>
</div>
</div>
</template>
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import SButton from './SButton.vue';
import CloseIcon from './icon/CloseIcon.vue';
import {Action, UiOptions} from '../lib';
export default defineComponent({
props: {
actionsDone: {type: Object as PropType<Set<Action>>, required: true}, // Used to avoid disabling actions already seen
triggerFlag: {type: Boolean, required: true},
// Used to indicate that a tutorial-requested 'trigger' action has been done
skipWelcome: {type: Boolean, default: false},
uiOpts: {type: Object as PropType<UiOptions>, required: true},
},
data(){
return {
stage: 0, // Indicates the current step of the tutorial (stage 0 is the welcome message)
lastStage: 9,
disabledOnce: false, // Set to true after disabling features at stage 1
stageActions: [
// Specifies, for stages 1+, what action to enable (can repeat an action to enable nothing new)
'expand', 'collapse', 'expandToView', 'unhideAncestor',
'tileInfo', 'search', 'autoMode', 'settings', 'help',
] as Action[],
hidNextPrevOnce: false, // Used to hide prev/next buttons when initially at stage 1
};
},
computed: {
styles(): Record<string,string> {
return {
backgroundColor: this.uiOpts.bgColorDark,
color: this.uiOpts.textColor,
};
},
contentStyles(): Record<string,string> {
return {
padding: '0 0.5cm',
overflow: 'auto',
textAlign: 'center',
};
},
buttonStyles(): Record<string,string> {
return {
color: this.uiOpts.textColor,
backgroundColor: this.uiOpts.bgColor,
};
},
touchDevice(): boolean {
return this.uiOpts.touchDevice;
},
},
methods: {
onStartTutorial(){
this.stage = 1;
},
onSkipTutorial(){
this.$emit('skip');
this.$emit('close');
},
onPrevClick(){
this.stage = Math.max(1, this.stage - 1);
},
onNextClick(){
this.stage = Math.min(this.stage + 1, this.lastStage);
},
onClose(){
this.$emit('close');
},
},
watch: {
stage(newVal, oldVal){
// If starting tutorial, disable 'all' actions
if (newVal == 1 && !this.disabledOnce){
for (let action of this.stageActions){
if (action != null && !this.actionsDone.has(action)){
this.uiOpts.disabledActions.add(action);
}
}
this.disabledOnce = true;
}
// Enable action for this stage
this.uiOpts.disabledActions.delete(this.stageActions[this.stage - 1]);
// Notify of new trigger-action
this.$emit('stage-chg', this.stageActions[this.stage - 1]);
// After stage 1, show prev/next buttons
if (newVal == 2){
this.hidNextPrevOnce = true;
}
},
// Called when a trigger-action is done, and advances to the next stage
triggerFlag(){
if (this.stage < this.lastStage){
this.onNextClick();
} else {
this.onClose();
}
},
},
created(){
if (this.skipWelcome){
this.stage += 1;
}
},
components: {CloseIcon, SButton, },
emits: ['close', 'stage-chg', 'skip', ],
});
</script>
|