From dc10b26c9b2331a683d43b9c31cb72dd06c34ad6 Mon Sep 17 00:00:00 2001 From: Paul Bui-Quang Date: Tue, 27 Aug 2024 11:33:21 +0200 Subject: [PATCH] refactor: remove WordCloud --- .../Dashboard/Preview/Charts/WordCloud.jsx | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/components/Dashboard/Preview/Charts/WordCloud.jsx diff --git a/src/components/Dashboard/Preview/Charts/WordCloud.jsx b/src/components/Dashboard/Preview/Charts/WordCloud.jsx deleted file mode 100644 index aac12fe95..000000000 --- a/src/components/Dashboard/Preview/Charts/WordCloud.jsx +++ /dev/null @@ -1,71 +0,0 @@ -import React, { memo, useState } from 'react' - -import PropTypes from 'prop-types' -import * as d3 from 'd3' -import * as cloud from 'd3-cloud' - -const WordCloud = memo(({ wordcloudData }) => { - const [node, setNode] = useState() - - const height = 250 - const width = 1000 - - const svg = d3.select(node) - svg.selectAll('*').remove() - svg.attr('height', height).attr('width', width) - svg.attr('viewBox', [50, 0, width, height]) - - const data = wordcloudData - if (!data) return <> - - if (data[0]) { - // Calcul de la frequence - const xMax = data[0].extension[0].valueDecimal - - for (const word of data) { - const freq = (word.extension[0].valueDecimal * 100) / xMax - word.extension[0].valueDecimal = Math.round(freq * 10) / 10 // <- pour arrondir les décimales - } - } - - // DEBUT CODE WORDCLOUD - // var wordColors = d3.scaleSequential(d3.interpolateWarm) <- pour colorer les mots de manière aléatoire - const wordColors = d3 - .scaleOrdinal() - .domain(data.map((d) => d.extension[0].url)) - .range( - d3.quantize((t) => d3.interpolateCool(t * 0.8 + 0.1), data.length) - // .reverse() <- pour inverser l'ordre des couleurs - ) - - const fontFamily = 'sans-serif' - const fontScale = 4.5 - - const rotate = 0 - const padding = 0 - - const layout = cloud() - .size([width, height]) - .words(data.map((d) => Object.create(d))) - .padding(padding) - .rotate(rotate) - .font(fontFamily) - .fontSize((d) => Math.sqrt(d.extension[0].valueDecimal) * fontScale) - .on('word', ({ size, x, y, rotate, extension }) => { - svg - .append('text') - .attr('font-size', size) - .attr('transform', `translate(${x},${y}) rotate(${rotate})`) - .style('fill', wordColors(Math.random())) - .text(extension[0].url) - }) - - layout.start() - - return setNode(node)}> -}) -WordCloud.propTypes = { - wordcloudData: PropTypes.array -} -WordCloud.displayName = 'WordCloud' -export default WordCloud