-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from SpiritFour/add_emoji_cloud
Add emoji cloud
- Loading branch information
Showing
5 changed files
with
123 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<template> | ||
<div ref="chartdiv"></div> | ||
</template> | ||
|
||
<script> | ||
import { Chat } from "~/utils/transformChatData"; | ||
import { onlyEmoji } from "emoji-aware"; | ||
export default { | ||
name: "EmojiCloud", | ||
props: { | ||
chartdata: new Chat(), | ||
minWordLength: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
minFontSize: { | ||
type: Number, | ||
default: 6, | ||
}, | ||
randomness: { | ||
type: Number, | ||
default: 0.1, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
chart: null, | ||
series: null, | ||
}; | ||
}, | ||
watch: { | ||
chartdata: { | ||
handler() { | ||
this.updateGraph(); | ||
}, | ||
deep: true, | ||
}, | ||
}, | ||
mounted() { | ||
let { am4core, am4themes_animated, am4plugins_wordCloud } = this.$am4core(); | ||
am4core.useTheme(am4themes_animated); | ||
am4core.options.onlyShowOnViewport = true; | ||
this.chart = am4core.create( | ||
this.$refs.chartdiv, | ||
am4plugins_wordCloud.WordCloud | ||
); | ||
this.series = this.chart.series.push( | ||
new am4plugins_wordCloud.WordCloudSeries() | ||
); | ||
this.series.dataFields.word = "word"; | ||
this.series.dataFields.value = "freq"; | ||
this.series.labels.template.tooltipText = "[bold]{freq}[/] x {word}"; | ||
this.series.accuracy = 5; | ||
// Dynamic font scaling based on frequency | ||
this.series.minFontSize = 12; | ||
this.series.maxFontSize = 36; | ||
this.series.minWordLength = 0; | ||
this.updateGraph(); | ||
}, | ||
beforeDestroy: function () { | ||
this.chart.dispose(); | ||
}, | ||
methods: { | ||
updateGraph() { | ||
this.chartdata.getEmojiCloudData().then((words) => { | ||
// Regex pattern to match currency like '24,95€' | ||
const filterPattern = /(?:€|\$|R\$|₹)?\d+[,.]?\d*(?:€|\$|R\$|₹)?|[!?]|^\.$/; | ||
const wordData = words.filter((wordObj) => { | ||
// Check if the word matches the currency pattern | ||
const isCurrency = filterPattern.test(wordObj.word); | ||
// Remove words that are currencies or entirely emojis | ||
return !isCurrency && onlyEmoji(wordObj.word).length > 0; | ||
}); | ||
// Assign the filtered data | ||
this.series.data = wordData; | ||
}); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters