Skip to content

Commit

Permalink
Merge pull request #8 from Dantaro/v1.3.0
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
Dantaro authored Feb 19, 2021
2 parents 8a4299e + a022449 commit 9c981dd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_CURRENT_VERSION=v1.2.0
REACT_APP_CURRENT_VERSION=v1.3.0
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "one-nice-thing",
"version": "1.1.2",
"version": "1.3.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.32",
Expand All @@ -20,7 +20,8 @@
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"redux-persist": "^6.0.0"
"redux-persist": "^6.0.0",
"wordcloud": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
10 changes: 10 additions & 0 deletions src/component/releasenotes/Releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ export const Releases = {
automated (and secure) automated cross-device sync process.
</Typography>
),
'v1.3.0': (
<Typography variant="body1">
With release 1.3.0 we've added a new statistic: a word cloud! Now you
can see a visualization what words you use and how frequently you make
use of them! Enjoy this fun feature, inspired by a suggestion email!
As a reminder, if you have any suggestions, bugs, or general thoughts
about One Nice Thing please feel free to send an email from the About
or Statistics page!
</Typography>
)
}
24 changes: 23 additions & 1 deletion src/page/statistics/Statistics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect, useRef } from 'react'
import Typography from '@material-ui/core/Typography'
import Paper from '@material-ui/core/Paper'
import { useSelector } from 'react-redux'
Expand All @@ -8,6 +8,8 @@ import {
findLongestNote,
} from 'util/notelist'
import { makeStyles } from '@material-ui/core/styles'
import WordCloud from 'wordcloud'
import { findWordCounts } from 'util/notelist/NoteListUtil'

const useStyles = makeStyles({
paper: {
Expand All @@ -21,6 +23,25 @@ const useStyles = makeStyles({
},
})

const NotelistWordMap = ({id, noteList}) => {
const canvasRef = useRef(null)
useEffect(() => {
WordCloud(document.getElementById(id), {
list: findWordCounts(noteList),
rotateRatio: 0,
weightFactor: 10,
color: () => '#1261A0'
})
}, [id, noteList]);

return (<>
<Typography variant="body1">
Your Word Cloud
</Typography>
<canvas ref={canvasRef} id={id} />
</>)
}

export const Statistics = () => {
const classes = useStyles()
const noteList = useSelector((state) => state.noteList)
Expand Down Expand Up @@ -55,6 +76,7 @@ export const Statistics = () => {
Longest Note:{' '}
{`${longestNote} ${longestNote === 1 ? 'word' : 'words'}`}
</Typography>
<NotelistWordMap id="notelistWordCount" noteList={noteList} />
<br/>
<Typography variant="body2">
Have an idea for other statistics? <a href="mailto:[email protected]">Shoot over an email</a> with your suggestions!
Expand Down
31 changes: 31 additions & 0 deletions src/util/notelist/NoteListUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,34 @@ export const findLongestNote = (noteList) => {
.map((it) => it.trim().split(/\s+/).length)
.reduce((acc, it) => (acc > it ? acc : it), 0)
}

export const findWordCounts = (noteList) => {
if (!noteList || noteList.length === 0) {
return []
}

const wordCounts = {}
noteList
.map(it => it.text)
.map(it => it.toLowerCase())
.forEach(it => {
it.split(' ')
.map(word => word.replace(/\W/g, ''))
.filter(word => word.length > 0)
.reduce((acc, cur) => {
const currentCount = acc[cur]
if (currentCount == null || currentCount == undefined) {
acc[cur] = 1
} else {
acc[cur] = currentCount + 1
}
return acc
}, wordCounts)
})

console.log(wordCounts)

return Object.keys(wordCounts)
.map(key => [key, wordCounts[key]])

}

0 comments on commit 9c981dd

Please sign in to comment.