# CSS Radial Grid Layout (Center-Outward Diagrams) > **⚠️ Before writing any code, read [`_rules.md`](references/_rules.md) — three non-negotiable rules on overlap, hierarchy, and color.** **For: SWOT analysis, Balanced Scorecard (BSC), Porter's Five Forces, PEST analysis, and any "center + 4-6 surrounding dimensions" diagram.** **Core principle: Use flex rows to lock positions — model never calculates coordinates. Connectors are drawn by script reading bounding boxes.** --- ## When to Use This Template | Diagram Type | Dimensions | Use This? | |-------------|-----------|-----------| | SWOT (Strengths/Weaknesses/Opportunities/Threats) | 4 quadrants | ✅ Layout B (2×2 Grid) | | Balanced Scorecard (Financial/Customer/Internal/Learning) | 4 dimensions | ✅ Layout A (Cross) | | Porter's Five Forces | 5 forces | ✅ Layout A (Cross + extra row) | | PEST (Political/Economic/Social/Technological) | 4 dimensions | ✅ Layout B (2×2 Grid) | | Competency wheel / capability map | 5-8 dimensions | ✅ Layout A with extra rows | | Anything with center + surrounding elements | 3-8 | ✅ | --- ## Layout A: Cross Layout (4-6 Dimensions) Best for: BSC, Porter's Five Forces, any "center with surrounding dimensions" structure. ### 🚫 FORBIDDEN: 3×3 CSS Grid Cross **Do NOT use `grid-template-columns: Xpx Ypx Xpx` to place cards in a cross pattern.** The top/bottom cards in the center column will overflow into the side columns and overlap with left/right cards when content is longer than expected. ### ✅ REQUIRED: Three-Row Flex Layout **Each row is an independent flex container. Rows cannot overlap each other — physically impossible.** ``` Row 1 (top): [top dimension card] ← independent flex row, centered Row 2 (middle): [left card] [center] [right card] ← independent flex row, horizontal Row 3 (bottom): [bottom dimension card] ← independent flex row, centered ``` ### HTML + CSS ```html
平衡计分卡四维评价体系
基于战略目标的绩效管理框架
F
财务维度
  • 营收增长率
  • 利润率
  • ROI
I
内部流程
  • 流程效率
  • 质量管控
  • 创新能力
战略目标
C
客户维度
  • 客户满意度
  • 市场份额
  • 客户留存率
L
学习与成长
  • 员工能力提升
  • 信息系统建设
  • 组织文化
``` **Key design decisions:** - **Three-row flex** instead of 3×3 Grid — rows physically cannot overlap - **Fixed card width (260px)** — prevents content-driven overflow - **`gap: 24px`** between rows, **`gap: 40px`** within middle row — generous spacing - **Center node uses `flex-shrink: 0`** — never collapses under pressure ### Adapting for 5+ Dimensions For Porter's Five Forces (5 dimensions) or more: ```html
...
...
...
...
...
...
``` For the connector script, add cases for `bottom-left` and `bottom-right`: ```javascript // 🚫 FORBIDDEN: using cR.left/cR.right as x1 — that draws from center CORNER, angle is ugly // ✅ CORRECT: always use cx (center bottom midpoint) as x1 case 'bottom-left': x1 = cx; y1 = cR.bottom - gRect.top; // center BOTTOM MIDPOINT x2 = cardCx; y2 = r.top - gRect.top; // card TOP MIDPOINT break; case 'bottom-right': x1 = cx; y1 = cR.bottom - gRect.top; // center BOTTOM MIDPOINT x2 = cardCx; y2 = r.top - gRect.top; // card TOP MIDPOINT break; ``` ### Adapting for 3 Dimensions Simply remove one side card from the middle row: ```html
...
...
...
...
``` --- ## Layout B: 2×2 Quadrant Grid (SWOT / PEST) Best for: exactly 4 dimensions arranged as equal quadrants (no center node needed). **This layout has NO center node — the four quadrants themselves tell the story.** ### HTML + CSS ```html
SWOT 分析
企业战略定位评估
S
优势 Strengths
  • 核心技术领先
  • 品牌知名度高
  • 供应链成熟
W
劣势 Weaknesses
  • 国际化经验不足
  • 产品线单一
  • 人才储备有限
O
机会 Opportunities
  • 新兴市场需求增长
  • 政策利好
  • 技术融合趋势
T
威胁 Threats
  • 竞争加剧
  • 原材料价格波动
  • 法规变化风险
``` **No connectors needed** — the 2×2 grid itself communicates the four-quadrant relationship. Adding arrows would be visual noise. --- ## Connector Rules 1. **Connectors are ALWAYS drawn by script reading bounding boxes** — never hardcode x/y values in HTML/CSS 2. **Straight lines only** (horizontal or vertical) — no diagonal lines unless top/bottom cards are offset from center 3. **Dashed lines** (`stroke-dasharray: 6,4`) for conceptual relationships 4. **Solid lines** for causal/sequential relationships 5. **Arrow direction**: model chooses based on diagram semantics — pick ONE style per diagram, don't mix: - **Outward** (`marker-end` only): center influences/drives dimensions (e.g. BSC: strategy → dimensions) - **Inward** (`marker-start` only): dimensions report/pressure center (e.g. Porter: forces → competition) - **Bidirectional** (`marker-start` + `marker-end`): mutual influence (e.g. feedback loops) 6. **🚫 All lines MUST originate from center EDGE MIDPOINTS** (cx or cy) — never from center corners 7. **Line color**: `#94A3B8` (gray-blue) — never use dimension-specific colors for connectors (visual chaos) ### SVG Arrow Markers (copy-paste into defs) ```javascript // Include both markers; use only what the diagram needs const defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs'); defs.innerHTML = ` `; svg.appendChild(defs); // Outward (center → card): line.setAttribute('marker-end', 'url(#arrowEnd)'); // Inward (card → center): line.setAttribute('marker-start', 'url(#arrowStart)'); // Bidirectional: line.setAttribute('marker-start', 'url(#arrowStart)'); line.setAttribute('marker-end', 'url(#arrowEnd)'); ``` --- ## Content Rules 1. **Each dimension card: max 6 bullet items** — more than 6 → group into sub-categories or use a separate detail table 2. **Bullet text: max 15 Chinese characters per line** — longer text wraps naturally (word-break: break-word) 3. **Center node text: max 8 Chinese characters** — keep it a short label, not a sentence 4. **Dimension title: max 10 Chinese characters** — concise category name --- ## Font Size Rules | Element | Size | Weight | |---------|------|--------| | Diagram title | 22px | 700 | | Center node | 18px | 700 | | Dimension title | 15-16px | 700 | | Bullet items | 13px | 400 | | Subtitle/footnote | 14px | 400 | --- ## Quality Checklist 1. **No overlap** — all dimension cards fully visible, none clipped or covering another 2. **Connectors point to card edges** — not to random points in space 3. **Center node visually dominant** — largest, darkest, or most contrast 4. **Dimension cards visually equal** — similar size, similar padding, no one card 3× larger 5. **Colors follow scheme** — each dimension has its own color (border + title), backgrounds stay pale (white or near-white) 6. **Layout is centered** — equal margins on all sides 7. **Canvas large enough** — min 900px wide for cross layout, min 800px for 2×2 quadrant