Skip to content

Commit 0cedd8f

Browse files
committed
adjust color stops
1 parent b04651b commit 0cedd8f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/components/Similar.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<span class="title">Similar: </span>
55
<ul class="list" v-if="story.similar && story.similar.length !== 0">
66
<li v-for="sim in story.similar" :key="sim.id">
7-
<span class="box" v-bind:style="{ background: `rgba(255, 165, 0, ${sim.score})`}" v-bind:title="sim.score"></span>
7+
<span class="box" v-bind:style="{ background: getColor(sim.score)}" v-bind:title="sim.score"></span>
88
<router-link :to="'/item/' + sim.id">{{ sim.text }}</router-link>
99
</li>
1010
</ul>
@@ -19,7 +19,22 @@
1919
2020
export default {
2121
name: 'similar-posts',
22-
props: ['story']
22+
props: ['story'],
23+
data: () => {
24+
return {
25+
colorStops: [
26+
{ start: 0, stop: 0.7, color: 'rgba(250, 157, 18, 0.5)' },
27+
{ start: 0.7, stop: 0.8, color: 'rgba(250, 157, 18, 0.75)' },
28+
{ start: 0.8, stop: 2, color: 'rgba(250, 157, 18, 1)' }
29+
]
30+
};
31+
},
32+
methods: {
33+
getColor: function(score) {
34+
const found = this.colorStops.find(cs => score.toFixed(2) >= cs.start && score.toFixed(2) < cs.stop);
35+
return found.color;
36+
}
37+
}
2338
}
2439
</script>
2540

0 commit comments

Comments
 (0)