|
| 1 | +--- |
| 2 | + |
| 3 | +title: "GSoC '25 Week 04 Update by Saumya Shahi" |
| 4 | +excerpt: "This week focused on implementing advanced tree rendering with nested, stacked, and argument brick support, dynamic sizing for the masonry module." |
| 5 | +category: "DEVELOPER NEWS" |
| 6 | +date: "2025-06-29" |
| 7 | +slug: "2025-06-29-gsoc-25-saumya-shahi-week04" |
| 8 | +author: "@/constants/MarkdownFiles/authors/saumya-shahi.md" |
| 9 | +tags: "gsoc25,sugarlabs,week04,saumya-shahi" |
| 10 | +image: "assets/Images/GSOC.png" |
| 11 | +--- |
| 12 | + |
| 13 | +<!-- markdownlint-disable --> |
| 14 | + |
| 15 | +# Week 04 Progress Report by Saumya Shahi |
| 16 | + |
| 17 | +**Project:** [Masonry Module - Music Blocks v4](https://github.com/sugarlabs/musicblocks-v4) |
| 18 | +**Mentors:** [Anindya Kundu](https://github.com/meganindya/) |
| 19 | +**Assisting Mentors:** [Walter Bender](https://github.com/walterbender), [Devin Ulibarri](https://github.com/pikurasa) |
| 20 | +**Reporting Period:** 2025-06-22 – 2025-06-29 |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Goals for This Week |
| 25 | + |
| 26 | +- Implement advanced tree rendering with nested, stacked, and argument brick support |
| 27 | +- Develop dynamic brick sizing based on content and children |
| 28 | +- Create comprehensive validation systems for brick connections |
| 29 | +- Establish robust rendering algorithms with proper traversal strategies |
| 30 | +- Integrate the complete tree rendering system into the storybook |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## This Week's Achievements |
| 35 | + |
| 36 | +### 1. **Advanced Tree Rendering System Implementation** |
| 37 | + |
| 38 | +Developed a brick tree rendering system that handles three distinct connection types: |
| 39 | + |
| 40 | +#### **Stacked Tree Rendering** |
| 41 | +- **Vertical Stacking**: Bricks can be connected vertically in sequence below their parent |
| 42 | +- **Cumulative Height Calculation**: Total height of stacked trees is calculated by summing individual brick heights |
| 43 | +- **Width Optimization**: Stacked trees maintain optimal width by taking the maximum width of all stacked bricks |
| 44 | + |
| 45 | + |
| 46 | +#### **Argument Brick Rendering** |
| 47 | +- **Expression-Only Validation**: Implemented validation ensuring only Expression bricks can be used as arguments |
| 48 | +- **Slot-Based Positioning**: Argument bricks are positioned at specific argument slots on their parent bricks |
| 49 | +- **Dynamic Slot Management**: Parent bricks automatically adjust their argument slots based on the number of arguments |
| 50 | + |
| 51 | + |
| 52 | +#### **Nested Tree Rendering** |
| 53 | +- **Multi-Level Nesting**: Implemented support for bricks nested inside compound bricks, which can themselves contain nested bricks |
| 54 | +- **Dynamic Sizing**: Parent bricks automatically resize based on their nested children's bounding boxes |
| 55 | +- **Proper Positioning**: Nested bricks are positioned at calculated connection points within their parent containers |
| 56 | + |
| 57 | + |
| 58 | +### 2. **Dynamic Brick Sizing and Layout System** |
| 59 | + |
| 60 | +#### **Label Width Adjustment** |
| 61 | +- **Dynamic Text Measurement**: Implemented canvas-based text measurement for accurate label width calculation |
| 62 | +- **Real-Time Updates**: Brick dimensions update automatically when labels change |
| 63 | +- **Fallback System**: Robust fallback for server-side rendering when canvas is unavailable |
| 64 | + |
| 65 | + |
| 66 | +#### **Child-Based Resizing** |
| 67 | +- **Bounding Box Calculation**: Parent bricks recalculate their bounding boxes based on their children's dimensions |
| 68 | +- **Compound Brick Layout**: Compound bricks expand their nested regions to accommodate all nested children |
| 69 | +- **Automatic Geometry Updates**: Brick geometry updates trigger re-rendering with new dimensions |
| 70 | + |
| 71 | + |
| 72 | +### 3. **Advanced Rendering Algorithms** |
| 73 | + |
| 74 | +#### **Two-Phase Rendering Strategy** |
| 75 | +- **Phase 1 - Preorder Traversal**: Calculate all bounding boxes and dimensions from root to leaves |
| 76 | +- **Phase 2 - Postorder Traversal**: Render from leaves to root, ensuring children appear on top of parents |
| 77 | +- **Z-Index Management**: Proper layering prevents visual conflicts between nested elements |
| 78 | + |
| 79 | +#### **Bounding Box Computation** |
| 80 | +```typescript |
| 81 | +function computeBoundingBoxes(allNodes: Map<string, ExtendedTreeNode>) { |
| 82 | + // Preorder traversal for dimension calculation |
| 83 | + // Handles nested, argument, and stacked children |
| 84 | + // Updates compound brick layouts with nested content |
| 85 | + // Returns comprehensive bounding box map |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### 4. **Comprehensive Validation Systems** |
| 90 | + |
| 91 | +#### **Brick Type Validation** |
| 92 | +- **Nesting Validation**: Only Compound and Simple bricks can be nested inside other bricks |
| 93 | +- **Argument Validation**: Only Expression bricks can be used as arguments |
| 94 | +- **Connection Validation**: Ensures compatible brick types for different connection types |
| 95 | + |
| 96 | +#### **Connection Point Validation** |
| 97 | +- **Notch Compatibility**: Validates that connecting bricks have compatible notch types |
| 98 | +- **Slot Availability**: Ensures argument slots are available before allowing connections |
| 99 | +- **Nested Space Validation**: Verifies sufficient space in compound bricks for nested children |
| 100 | + |
| 101 | +### 5. **Brick Model System** |
| 102 | + |
| 103 | +Refined the brick model architecture with advanced features: |
| 104 | +- **SimpleBrick**: Basic statement bricks with configurable notches and argument support |
| 105 | +- **ExpressionBrick**: Value-holding bricks with expression support and argument-only usage |
| 106 | +- **CompoundBrick**: Container bricks with nested children support and dynamic sizing |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Technical Implementation Details |
| 111 | + |
| 112 | +### Advanced Tree Structure |
| 113 | +```typescript |
| 114 | +interface ExtendedTreeNode extends TTreeNode { |
| 115 | + isNested?: boolean; // Indicates nested brick |
| 116 | + argIndex?: number; // Argument slot index |
| 117 | + children?: { |
| 118 | + nested: ExtendedTreeNode[]; |
| 119 | + args: ExtendedTreeNode[]; |
| 120 | + stacked: ExtendedTreeNode[]; |
| 121 | + }; |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +### Dynamic Sizing Algorithm |
| 126 | +```typescript |
| 127 | +function updateCompoundBrickLayouts(nodes: Map<string, ExtendedTreeNode>) { |
| 128 | + // Calculate total nested content dimensions |
| 129 | + // Update compound brick's bboxNest array |
| 130 | + // Trigger geometry recalculation |
| 131 | + // Update connection points |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +### Validation System |
| 136 | +```typescript |
| 137 | +function validateBrickConnection(parent: BrickModel, child: BrickModel, type: ConnectionType) { |
| 138 | + switch(type) { |
| 139 | + case 'nested': |
| 140 | + return parent.type === 'Compound' || parent.type === 'Simple'; |
| 141 | + case 'argument': |
| 142 | + return child.type === 'Expression'; |
| 143 | + case 'stacked': |
| 144 | + return child.type !== 'Expression'; // expression brick can't be stacked |
| 145 | + } |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Challenges & How I Overcame Them |
| 152 | + |
| 153 | + |
| 154 | +### Challenge 1: Compound Brick Layout with Multiple Nested Children |
| 155 | +**Problem**: Compound bricks needed to accommodate multiple nested children with varying sizes and positions. |
| 156 | +**Solution**: Implemented a two-phase approach: first calculate all child dimensions, then update parent bounding boxes and trigger geometry recalculation. Developed a recursive algorithm that calculates bounding boxes bottom-up, then renders top-down with proper z-indexing to ensure children appear above parents. |
| 157 | + |
| 158 | +### Challenge 2: Label Width Calculation and Dynamic Updates |
| 159 | +**Problem**: Bricks needed to resize based on their label text, requiring accurate text measurement and real-time updates. |
| 160 | +**Solution**: Implemented canvas-based text measurement with fallback for server-side rendering, and integrated it into the brick geometry update system. |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## Key Learnings |
| 167 | + |
| 168 | +- **Advanced Tree Algorithms**: Deep understanding of preorder/postorder traversal for different rendering phases |
| 169 | +- **Dynamic Layout Systems**: Learned how to implement responsive layouts that adapt to content changes |
| 170 | +- **Canvas Text Measurement**: Mastered techniques for accurate text measurement in web environments |
| 171 | +- **Z-Index Management**: Gained expertise in managing visual layering in complex nested structures |
| 172 | +- **Type-Safe Validation**: Enhanced skills in creating comprehensive validation systems with TypeScript |
| 173 | + |
| 174 | +--- |
| 175 | + |
| 176 | +## Resources & References |
| 177 | + |
| 178 | +- **Tree Traversal Algorithms**: [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) |
| 179 | +- **Canvas Text Measurement**: [MDN Canvas Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) |
| 180 | +- **TypeScript Validation Patterns**: [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/advanced-types.html) |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +## Acknowledgments |
| 185 | + |
| 186 | +Thank you to my mentors, the Sugar Labs community, and fellow GSoC contributors for their guidance and support. Special thanks to the community for providing valuable feedback on the tree model design and implementation. |
| 187 | + |
| 188 | +--- |
0 commit comments