-
-
Save min50250/488301b5e2a818d4ba8e9d408a5bff5d to your computer and use it in GitHub Desktop.
Step3. Callout
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
> [!WordCloud] | |
> ```dataviewjs | |
> | |
> let html = "" | |
> let table = [ | |
> ['[[사과]]', 12], | |
> ['[[바나나]]', 50], | |
> ['[[체리]]', 60], | |
> ['[[딸기]]', 80], | |
> ['[[포도]]', 40], | |
> ['[[멜론]]', 25], | |
> ['[[키위]]', 65], | |
> ['[[복숭아]]', 55], | |
> ['[[자두]]', 5], | |
> ['[[레몬]]', 24], | |
> ]; | |
> | |
> table = valueToLevel(table); | |
> | |
> html = "" | |
> | |
> for(let j = 0 ; j < table.length ; j++){ | |
> html = html + "<span class=\"" + table[j][2] + " cloud\" >" + table[j][0] + "</span>" | |
> } | |
> | |
> dv.paragraph(html) | |
> | |
> | |
> // 주어진 배열(arr)의 요소들을 레벨로 분류하는 함수 | |
> // 각 요소는 [이름, 값] 형태를 가짐 | |
> function valueToLevel(arr) { | |
> arr = shuffleArray(arr) | |
> const values = arr.map((item) => item[1]); | |
> const minValue = Math.min(...values); | |
> const maxValue = Math.max(...values); | |
> const totalLevels = 7; | |
> const levelSize = (maxValue - minValue) / totalLevels; | |
> | |
> return arr.map((item) => { | |
> const name = item[0]; | |
> const value = item[1]; | |
> const level = Math.ceil((value - minValue) / levelSize); | |
> const adjustedLevel = Math.min(totalLevels, Math.max(1, level)); | |
> return [name, value, `cloud${adjustedLevel}`]; | |
> }); | |
> } | |
> | |
> // 주어진 배열(array)을 랜덤하게 섞는 함수 | |
> function shuffleArray(array) { | |
> for (let i = array.length - 1; i > 0; i--) { | |
> const j = Math.floor(Math.random() * (i + 1)); | |
> [array[i], array[j]] = [array[j], array[i]]; | |
> } | |
> return array; | |
> } | |
> | |
> ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment