|
|
|
@ -1,5 +1,11 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<svg :width="width" :height="height"> |
|
|
|
<svg |
|
|
|
|
|
|
|
:width="width" |
|
|
|
|
|
|
|
:height="height" |
|
|
|
|
|
|
|
@mousemove="onMousemove" |
|
|
|
|
|
|
|
@mouseover="(e) => (this.hover = true)" |
|
|
|
|
|
|
|
@mouseout="this.hover = false" |
|
|
|
|
|
|
|
> |
|
|
|
<g :transform="`translate(${width / 2}, ${height / 2})`"> |
|
|
|
<g :transform="`translate(${width / 2}, ${height / 2})`"> |
|
|
|
<text |
|
|
|
<text |
|
|
|
v-for="word in words" |
|
|
|
v-for="word in words" |
|
|
|
@ -7,10 +13,12 @@ |
|
|
|
:style="{ |
|
|
|
:style="{ |
|
|
|
fontSize: word.size + 'px', |
|
|
|
fontSize: word.size + 'px', |
|
|
|
fontFamily: word.font, |
|
|
|
fontFamily: word.font, |
|
|
|
|
|
|
|
cursor: 'pointer', |
|
|
|
}" |
|
|
|
}" |
|
|
|
:transform="`translate(${word.x}, ${word.y})rotate(${word.rotate})`" |
|
|
|
:transform="`translate(${word.x}, ${word.y})rotate(${word.rotate})`" |
|
|
|
text-anchor="middle" |
|
|
|
text-anchor="middle" |
|
|
|
@click="highlightText(word.text)" |
|
|
|
@click="highlightText(word.text)" |
|
|
|
|
|
|
|
class="word" |
|
|
|
> |
|
|
|
> |
|
|
|
{{ word.text }} |
|
|
|
{{ word.text }} |
|
|
|
</text> |
|
|
|
</text> |
|
|
|
@ -18,6 +26,12 @@ |
|
|
|
</svg> |
|
|
|
</svg> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
|
|
|
|
.word { |
|
|
|
|
|
|
|
transition: 1s transform ease-in-out; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
</style> |
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts"> |
|
|
|
<script lang="ts"> |
|
|
|
import cloud from "d3-cloud"; |
|
|
|
import cloud from "d3-cloud"; |
|
|
|
import * as skills from "@/data/skills"; |
|
|
|
import * as skills from "@/data/skills"; |
|
|
|
@ -30,24 +44,37 @@ export default defineComponent({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
loading: false, |
|
|
|
animate: true, |
|
|
|
|
|
|
|
hover: false, |
|
|
|
words: [] as cloud.Word[], |
|
|
|
words: [] as cloud.Word[], |
|
|
|
minFontSize: 8, |
|
|
|
minFontSize: 8, |
|
|
|
maxFontSize: 40, |
|
|
|
maxFontSize: 40, |
|
|
|
|
|
|
|
mouseX: undefined, |
|
|
|
|
|
|
|
mouseY: undefined, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
created() { |
|
|
|
created() { |
|
|
|
this.computeWords(); |
|
|
|
this.computeWords(); |
|
|
|
|
|
|
|
// setInterval(() => { |
|
|
|
|
|
|
|
// if (!this.animate || this.hover) { |
|
|
|
|
|
|
|
// return; |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// this.computeWords(); |
|
|
|
|
|
|
|
// }, 1500); |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
|
|
|
|
onMousemove(e: any) { |
|
|
|
|
|
|
|
this.mouseX = e.clientX; |
|
|
|
|
|
|
|
this.mouseY = e.clientY; |
|
|
|
|
|
|
|
}, |
|
|
|
highlightText(text: string) { |
|
|
|
highlightText(text: string) { |
|
|
|
console.log(text); |
|
|
|
console.log(text); |
|
|
|
}, |
|
|
|
}, |
|
|
|
computeWords() { |
|
|
|
computeWords() { |
|
|
|
this.loading = true; |
|
|
|
let words: (cloud.Word & { size: number; fixed?: boolean })[] = |
|
|
|
let words: (cloud.Word & { size: number })[] = Object.keys(skills) |
|
|
|
Object.keys(skills) |
|
|
|
.map((p) => skills[p]) |
|
|
|
.map((p) => skills[p]) |
|
|
|
.map((s) => ({ text: s.name, size: s.score })); |
|
|
|
.map((s) => ({ text: s.name, size: s.score })); |
|
|
|
|
|
|
|
|
|
|
|
const min = words |
|
|
|
const min = words |
|
|
|
.map((s) => s.size) |
|
|
|
.map((s) => s.size) |
|
|
|
@ -55,11 +82,18 @@ export default defineComponent({ |
|
|
|
const max = words |
|
|
|
const max = words |
|
|
|
.map((s) => s.size) |
|
|
|
.map((s) => s.size) |
|
|
|
.reduce((prev, current) => Math.max(prev, current)); |
|
|
|
.reduce((prev, current) => Math.max(prev, current)); |
|
|
|
const scaleFontSize = (size: number) => { |
|
|
|
const scaleFontSize = ({ |
|
|
|
const number = |
|
|
|
size, |
|
|
|
((size - min) / (max - min)) * (this.maxFontSize - this.minFontSize) + |
|
|
|
fixed, |
|
|
|
this.minFontSize; |
|
|
|
}: { |
|
|
|
return number; |
|
|
|
size: number; |
|
|
|
|
|
|
|
fixed: boolean; |
|
|
|
|
|
|
|
}) => { |
|
|
|
|
|
|
|
return fixed |
|
|
|
|
|
|
|
? size |
|
|
|
|
|
|
|
: ((size - min) / (max - min)) * |
|
|
|
|
|
|
|
(this.maxFontSize - this.minFontSize) + |
|
|
|
|
|
|
|
this.minFontSize; |
|
|
|
}; |
|
|
|
}; |
|
|
|
const randomRotate = (s: number) => { |
|
|
|
const randomRotate = (s: number) => { |
|
|
|
const range = 120 * (1 - ((s - min) / (max - min)) * 0.7); |
|
|
|
const range = 120 * (1 - ((s - min) / (max - min)) * 0.7); |
|
|
|
@ -67,7 +101,8 @@ export default defineComponent({ |
|
|
|
}; |
|
|
|
}; |
|
|
|
words = [ |
|
|
|
words = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
size: max * 1.6, |
|
|
|
size: 30, |
|
|
|
|
|
|
|
fixed: true, |
|
|
|
text: "Nicolas Marsal", |
|
|
|
text: "Nicolas Marsal", |
|
|
|
rotate: -30, |
|
|
|
rotate: -30, |
|
|
|
padding: 6, |
|
|
|
padding: 6, |
|
|
|
@ -81,19 +116,22 @@ export default defineComponent({ |
|
|
|
.words(words) |
|
|
|
.words(words) |
|
|
|
.padding((w) => w.padding ?? 1) |
|
|
|
.padding((w) => w.padding ?? 1) |
|
|
|
.rotate((w) => w.rotate ?? randomRotate(w.size)) |
|
|
|
.rotate((w) => w.rotate ?? randomRotate(w.size)) |
|
|
|
.spiral("archimedean") |
|
|
|
.spiral("rectangular") |
|
|
|
.fontSize((d) => scaleFontSize(d.size)) |
|
|
|
.fontSize((d) => scaleFontSize(d)) |
|
|
|
.on("end", (d: cloud.Word[]) => { |
|
|
|
.on("end", (d: cloud.Word[]) => { |
|
|
|
console.log( |
|
|
|
console.log( |
|
|
|
`d: ${d.length} - w: ${words.length} - f: ${this.maxFontSize}` |
|
|
|
`d: ${d.length} - w: ${words.length} - f: ${this.maxFontSize}` |
|
|
|
); |
|
|
|
); |
|
|
|
if (d.length < words.length) { |
|
|
|
if (d.length < words.length) { |
|
|
|
console.log("On recommence !"); |
|
|
|
// console.log("On recommence !"); |
|
|
|
this.maxFontSize = this.maxFontSize - 2; |
|
|
|
this.maxFontSize = this.maxFontSize - 2; |
|
|
|
this.computeWords(); |
|
|
|
if (this.maxFontSize > 2 * this.minFontSize) { |
|
|
|
|
|
|
|
this.computeWords(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.words = d; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.words = d; |
|
|
|
this.words = d; |
|
|
|
this.loading = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.start(); |
|
|
|
.start(); |
|
|
|
|