From c2a048aa58d41ee4611c25e77792d7cccc00b3ca Mon Sep 17 00:00:00 2001 From: RoxaneBurri Date: Thu, 23 Mar 2023 14:03:56 +0100 Subject: [PATCH] feat: set constante for number of intervals --- src/Wordcloud.tsx | 12 +++++++++--- src/constants.ts | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Wordcloud.tsx b/src/Wordcloud.tsx index 4b87b51..a25525d 100644 --- a/src/Wordcloud.tsx +++ b/src/Wordcloud.tsx @@ -8,8 +8,12 @@ import { } from "./utils"; import * as React from "react"; -import { CONTAINER_HEIGHT, CONTAINER_WIDTH, DEFAULT_RECT } from "./constants"; -import { defaultWords1 } from "./data"; +import { + CONTAINER_HEIGHT, + CONTAINER_WIDTH, + DEFAULT_RECT, + NUMBER_OF_INTERVALS, +} from "./constants"; const CUT_OFF = 0.5; @@ -46,7 +50,9 @@ const Wordcloud = ({ y: centerY, }; - const weight = [1, 1, 1, 1]; + // Initialize the weights with the value 1, of the size of the number of intervals + const weight = new Array(NUMBER_OF_INTERVALS).fill(1); + const newPositions = rectsToPlace.slice(1).reduce( (placedElements, rect) => { const futureWord = futurPosition(rect, placedElements, 3, weight); diff --git a/src/constants.ts b/src/constants.ts index 27654b5..8a10977 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -17,3 +17,5 @@ export const INTERVAL = { c: { x: 180, y: 269 }, d: { x: 270, y: 360 }, }; + +export const NUMBER_OF_INTERVALS = 6;