1<!-- Copyright (C) 2017 The Android Open Source Project
2
3     Licensed under the Apache License, Version 2.0 (the "License");
4     you may not use this file except in compliance with the License.
5     You may obtain a copy of the License at
6
7          http://www.apache.org/licenses/LICENSE-2.0
8
9     Unless required by applicable law or agreed to in writing, software
10     distributed under the License is distributed on an "AS IS" BASIS,
11     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12     See the License for the specific language governing permissions and
13     limitations under the License.
14-->
15<template>
16  <svg width="2000" height="20" viewBox="-5,0,2010,20">
17    <circle :cx="position(item)" cy="10" r="5" v-for="(item, idx) in items" @click="onItemClick(idx)" />
18    <circle v-if="items.length" :cx="position(selected)" cy="10" r="5" class="selected" />
19  </svg>
20</template>
21<script>
22export default {
23  name: 'timeline',
24  props: ['items', 'selectedIndex', 'scale'],
25  data() {
26    return {};
27  },
28  methods: {
29    position(item) {
30      return this.translate(item);
31    },
32    translate(cx) {
33      var scale = [...this.scale];
34      if (scale[0] >= scale[1]) {
35        return cx;
36      }
37      return (cx - scale[0]) / (scale[1] - scale[0]) * 2000;
38    },
39    onItemClick(index) {
40      this.$emit('item-selected', index);
41    },
42  },
43  computed: {
44    timestamps() {
45      if (this.items.length == 1) {
46        return [0];
47      }
48      return this.items;
49    },
50    selected() {
51      return this.items[this.selectedIndex];
52    }
53  },
54}
55
56</script>
57<style scoped>
58.selected {
59  fill: red;
60}
61
62</style>
63