Skip to content

Commit 26de911

Browse files
docs: Enhance documentation for pie menu functions in piemenus.js (#5628)
* docs: Enhance documentation for pie menu functions in piemenus.js * Update JSDoc comments for pie menu functions
1 parent 03c528e commit 26de911

File tree

1 file changed

+134
-1
lines changed

1 file changed

+134
-1
lines changed

js/piemenus.js

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
piemenuDissectNumber
6262
*/
6363

64+
/**
65+
* Sets the pie menu container size based on the viewport width.
66+
* Uses the base diameter and scales down for smaller screens.
67+
* @param diameter Base diameter of the wheel in pixels
68+
* @returns void
69+
*/
6470
const setWheelSize = (i = 400) => {
6571
const wheelDiv = document.getElementById("wheelDiv");
6672
const screenWidth = window.innerWidth;
@@ -84,6 +90,12 @@ const setWheelSize = (i = 400) => {
8490
wheelDiv.style.height = wheelDiv.style.width;
8591
};
8692

93+
/**
94+
* Computes an appropriate pie menu size based on the turtle canvas bounds.
95+
*
96+
* @param block Block instance owning the pie menu
97+
* @returns Minimum of the canvas width and height
98+
*/
8799
const getPieMenuSize = block => {
88100
const canvas = block.blocks.turtles._canvas;
89101
return Math.min(canvas.width, canvas.height);
@@ -100,7 +112,14 @@ const debouncedSetWheelSize = () => {
100112
setWheelSize();
101113
window.addEventListener("resize", debouncedSetWheelSize);
102114

103-
// Helper function to enable scroll-to-rotate for pie menus
115+
/**
116+
* Enables mouse-wheel scrolling to rotate a wheelnav instance
117+
* without triggering sound previews.
118+
*
119+
* @param wheel Wheelnav instance to rotate
120+
* @param itemCount Total number of selectable items in the wheel
121+
* @returns void
122+
*/
104123
const enableWheelScroll = (wheel, itemCount) => {
105124
const wheelDiv = document.getElementById("wheelDiv");
106125
if (!wheelDiv || !wheel) return;
@@ -194,6 +213,19 @@ const configureExitWheel = exitWheel => {
194213
};
195214
};
196215

216+
/**
217+
* Builds the pitch selection pie menu with optional accidentals
218+
* and an optional octave wheel.
219+
*
220+
* @param {Object} block Block instance invoking the menu
221+
* @param {string[]} noteLabels Labels shown in the pitch wheel
222+
* @param {string[]} noteValues Values mapped to labels
223+
* @param {Array} accidentals Accidental labels/values for the inner wheel
224+
* @param {string} note Currently selected note value
225+
* @param {string} accidental Currently selected accidental
226+
* @param {boolean} [custom=false] Whether to use the custom-note layout
227+
* @returns {void}
228+
*/
197229
const piemenuPitches = (block, noteLabels, noteValues, accidentals, note, accidental, custom) => {
198230
let prevPitch = null;
199231
// wheelNav pie menu for pitch selection
@@ -879,6 +911,16 @@ const piemenuPitches = (block, noteLabels, noteValues, accidentals, note, accide
879911
};
880912
};
881913

914+
/**
915+
* Builds the custom temperament pie menu with an optional octave wheel.
916+
*
917+
* @param {Object} block Block instance invoking the menu
918+
* @param {Object} noteLabels Custom note label map keyed by temperament
919+
* @param {string[]} customLabels Identifiers for available custom sets
920+
* @param {string} selectedCustom Currently selected custom set key
921+
* @param {number|string} selectedNote Currently selected note within the set
922+
* @returns {void}
923+
*/
882924
const piemenuCustomNotes = (block, noteLabels, customLabels, selectedCustom, selectedNote) => {
883925
// pie menu for customNote selection
884926
if (block.blocks.stageClick) {
@@ -1209,6 +1251,14 @@ const piemenuCustomNotes = (block, noteLabels, customLabels, selectedCustom, sel
12091251
block._exitWheel.navItems[0].navigateFunction = __exitMenu;
12101252
};
12111253

1254+
/**
1255+
* Builds the scale-degree (nth modal pitch) pie menu.
1256+
*
1257+
* @param {Object} block Block instance invoking the menu
1258+
* @param {number[]} noteValues Scale degree values to display
1259+
* @param {number} note Currently selected degree (rounded if fractional)
1260+
* @returns {void}
1261+
*/
12121262
const piemenuNthModalPitch = (block, noteValues, note) => {
12131263
// wheelNav pie menu for scale degree pitch selection
12141264

@@ -1463,6 +1513,15 @@ const piemenuNthModalPitch = (block, noteValues, note) => {
14631513
};
14641514
};
14651515

1516+
/**
1517+
* Builds the accidental selection pie menu.
1518+
*
1519+
* @param {Object} block Block instance invoking the menu
1520+
* @param {string[]} accidentalLabels Display labels for accidentals
1521+
* @param {Array} accidentalValues Values mapped to labels
1522+
* @param {*} accidental Currently selected accidental
1523+
* @returns {void}
1524+
*/
14661525
const piemenuAccidentals = (block, accidentalLabels, accidentalValues, accidental) => {
14671526
// wheelNav pie menu for accidental selection
14681527

@@ -1598,6 +1657,13 @@ const piemenuAccidentals = (block, accidentalLabels, accidentalValues, accidenta
15981657
};
15991658
};
16001659

1660+
/**
1661+
* Builds the note duration pie menu and its sub-wheel options.
1662+
*
1663+
* @param {Object} block Block instance invoking the menu
1664+
* @param {number} noteValue Currently selected duration value
1665+
* @returns {void}
1666+
*/
16011667
const piemenuNoteValue = (block, noteValue) => {
16021668
// input form and wheelNav pie menu for note value selection
16031669

@@ -1840,6 +1906,14 @@ const piemenuNoteValue = (block, noteValue) => {
18401906
};
18411907
};
18421908

1909+
/**
1910+
* Builds the numeric value pie menu and synchronizes the selected value.
1911+
*
1912+
* @param {Object} block Block instance invoking the menu
1913+
* @param {number[]} wheelValues Values to show on the wheel
1914+
* @param {number} selectedValue Currently selected value
1915+
* @returns {void}
1916+
*/
18431917
const piemenuNumber = (block, wheelValues, selectedValue) => {
18441918
// input form and wheelNav pie menu for number selection
18451919
if (block.blocks.stageClick) {
@@ -2139,6 +2213,15 @@ const piemenuNumber = (block, wheelValues, selectedValue) => {
21392213
}
21402214
};
21412215

2216+
/**
2217+
* Builds the color-selection pie menu for turtle and paint blocks.
2218+
*
2219+
* @param {Object} block Block instance invoking the menu
2220+
* @param {number[]} wheelValues Numeric values mapped to colors
2221+
* @param {number} selectedValue Currently selected value
2222+
* @param {string} mode Color mode (e.g. setcolor, setturtlecolor, sethue)
2223+
* @returns {void}
2224+
*/
21422225
const piemenuColor = (block, wheelValues, selectedValue, mode) => {
21432226
// input form and wheelNav pie menu for setcolor selection
21442227

@@ -2312,6 +2395,16 @@ const piemenuColor = (block, wheelValues, selectedValue, mode) => {
23122395
};
23132396
};
23142397

2398+
/**
2399+
* Builds a generic pie menu with arbitrary labels and values.
2400+
*
2401+
* @param {Object} block Block instance invoking the menu
2402+
* @param {Array} menuLabels Labels rendered on the wheel
2403+
* @param {Array} menuValues Values corresponding to each label
2404+
* @param {*} selectedValue Currently selected value
2405+
* @param {Array} [colors] Optional override colors for the wheel
2406+
* @returns {void}
2407+
*/
23152408
const piemenuBasic = (block, menuLabels, menuValues, selectedValue, colors) => {
23162409
// basic wheelNav pie menu
23172410

@@ -2455,6 +2548,15 @@ const piemenuBasic = (block, menuLabels, menuValues, selectedValue, colors) => {
24552548
};
24562549
};
24572550

2551+
/**
2552+
* Builds the boolean selection pie menu.
2553+
*
2554+
* @param {Object} block Block instance invoking the menu
2555+
* @param {string[]} booleanLabels Display labels for each option
2556+
* @param {boolean[]} booleanValues Values mapped to each label
2557+
* @param {boolean} boolean Currently selected value
2558+
* @returns {void}
2559+
*/
24582560
const piemenuBoolean = (block, booleanLabels, booleanValues, boolean) => {
24592561
// wheelNav pie menu for boolean selection
24602562

@@ -2559,6 +2661,13 @@ const piemenuBoolean = (block, booleanLabels, booleanValues, boolean) => {
25592661
};
25602662
};
25612663

2664+
/**
2665+
* Builds the chord selection pie menu.
2666+
*
2667+
* @param {Object} block Block instance invoking the menu
2668+
* @param {string} selectedChord Currently selected chord label
2669+
* @returns {void}
2670+
*/
25622671
const piemenuChords = (block, selectedChord) => {
25632672
// wheelNav pie menu for chord selection
25642673

@@ -2691,6 +2800,17 @@ const piemenuChords = (block, selectedChord) => {
26912800
};
26922801
};
26932802

2803+
/**
2804+
* Builds the voice/instrument selection pie menu.
2805+
*
2806+
* @param {Object} block Block instance invoking the menu
2807+
* @param {string[]} voiceLabels Labels shown in the wheel
2808+
* @param {Array} voiceValues Values mapped to labels
2809+
* @param {number[]} categories Category indices for color grouping
2810+
* @param {*} voice Currently selected voice value
2811+
* @param {number} [rotate] Optional title rotation angle
2812+
* @returns {void}
2813+
*/
26942814
const piemenuVoices = (block, voiceLabels, voiceValues, categories, voice, rotate) => {
26952815
// wheelNav pie menu for voice selection
26962816

@@ -2870,6 +2990,12 @@ const piemenuVoices = (block, voiceLabels, voiceValues, categories, voice, rotat
28702990
};
28712991
};
28722992

2993+
/**
2994+
* Builds the interval selection pie menu.
2995+
* @param {Object} block Block instance invoking the menu
2996+
* @param {string} selectedInterval Currently selected interval value
2997+
* @returns {void}
2998+
*/
28732999
const piemenuIntervals = (block, selectedInterval) => {
28743000
// pie menu for interval selection
28753001

@@ -3096,6 +3222,13 @@ const piemenuIntervals = (block, selectedInterval) => {
30963222
block._exitWheel.navItems[0].navigateFunction = __exitMenu;
30973223
};
30983224

3225+
/**
3226+
* Builds the musical mode selection pie menu.
3227+
*
3228+
* @param {Object} block Block instance invoking the menu
3229+
* @param {string} selectedMode Currently selected mode value
3230+
* @returns {void}
3231+
*/
30993232
const piemenuModes = (block, selectedMode) => {
31003233
// pie menu for mode selection
31013234

0 commit comments

Comments
 (0)