---
code: "DIS-13"
id: "c-mari"
tab: "distribution"
kind: "core"
title: "Marimekko · 모자이크 비율"
library: "ECharts"
deps: ["echarts@5"]
load: "low"
pasteKind: "echarts-mount"
family: "composition"
dataShape: "category shares or weighted blocks"
tasks: ["show composition", "show frequency", "compare magnitudes", "show part-to-whole"]
tags: ["distribution", "비율", "빈도", "composition", "share", "marimekko", "모자이크"]
gallery: "https://graph.heal7.com/#DIS-13"
js: "/sku/DIS-13.js"
---

# [DIS-13] Marimekko · 모자이크 비율

> AI 붙여넣기 카드. 갤러리 런타임(`main.js`)이 아니라 이 파일을 가져와라.

## 언제 가져가나
컬럼 폭 = 그룹 크기, 셀 높이 = 내부 비율 — 두 차원의 비중을 면적 하나로.

**응용** 시장×세그먼트 점유율, 채널×제품 매출 매트릭스.

## 데이터 모양
- family: `composition`
- dataShape: category shares or weighted blocks
- tasks: show composition, show frequency, compare magnitudes, show part-to-whole
- tags: distribution, 비율, 빈도, composition, share, marimekko, 모자이크


## 의존
echarts@5 · load `low` · library `ECharts`

## 붙여넣는 법
1. echarts 5.x 로드 (GL이면 echarts-gl도)
2. 컨테이너 id를 원본 id와 맞추거나 `document.getElementById` 한 줄만 바꾼다
3. `T`, `reg`, `cssv` 가 필요하면 갤러리 테마 스텁을 함께 가져간다

```js
const T = {
  "bg": "transparent",
  "fg": "#ece8f5",
  "sub": "#a59bbd",
  "grid": "rgba(255,255,255,.08)",
  "gold": "#e8c069",
  "royal": "#6b8cff",
  "rose": "#e07a9f",
  "teal": "#6dd2c4",
  "plum": "#b487e8"
};
const cssv = (n, fb) => (getComputedStyle(document.documentElement).getPropertyValue(n).trim() || fb);
const isDark = () => document.documentElement.getAttribute('data-theme') !== 'light';
const charts = [];
const reg = (id, opt) => {
  const dom = document.getElementById(id); if (!dom) return;
  const c = echarts.init(dom, null, {renderer:'canvas'});
  c.setOption(opt);
  charts.push(c);
  return c;
};
const factory = function(){
  const groups = [
    {name:'국내', total:42, seg:[['엔터프라이즈',45],['미드',35],['SMB',20]]},
    {name:'아시아', total:28, seg:[['엔터프라이즈',30],['미드',45],['SMB',25]]},
    {name:'북미', total:20, seg:[['엔터프라이즈',55],['미드',30],['SMB',15]]},
    {name:'EU', total:10, seg:[['엔터프라이즈',40],['미드',35],['SMB',25]]}
  ];
  const totalW = groups.reduce((a,g)=>a+g.total,0);
  const segs = ['엔터프라이즈','미드','SMB'];
  const colors = [T.gold, T.royal, T.teal];
  const series = segs.map((s,i)=>({
    type:'custom', name:s, stack:'mari',
    renderItem:(p, api)=>{
      const g = groups[api.value(0)];
      // x bands
      let xStart = 0;
      for(let k=0;k<api.value(0);k++) xStart += groups[k].total;
      const x0 = api.coord([xStart,0])[0];
      const x1 = api.coord([xStart + g.total,0])[0];
      // y stack within group
      let cum = 0;
      for(let k=0;k<i;k++) cum += g.seg[k][1];
      const y0 = api.coord([0, cum])[1];
      const y1 = api.coord([0, cum + g.seg[i][1]])[1];
      return {
        type:'rect',
        shape:{x:x0+2, y:y1, width:x1-x0-4, height:y0-y1},
        style:{fill:colors[i], opacity:.85, stroke:'rgba(0,0,0,.15)'},
        emphasis:{style:{opacity:1}}
      };
    },
    data: groups.map((g,gi)=>({value:[gi, g.seg[i][1], g.name, s]})),
    encode:{tooltip:[2,3]}
  }));
  const cMari = reg('c-mari', {
    backgroundColor:T.bg,
    tooltip:{formatter: p => `${p.value[2]} · ${p.value[3]}<br/>${p.value[1]}%`},
    legend:{data:segs, top:0, textStyle:{color:T.sub}, itemWidth:10, itemHeight:10},
    grid:{left:48, right:14, top:30, bottom:34},
    xAxis:{type:'value', max:totalW, axisLabel:{show:false}, splitLine:{show:false}, axisTick:{show:false}, axisLine:{lineStyle:{color:T.grid}}},
    yAxis:{type:'value', max:100, axisLabel:{color:T.sub, fontSize:10, formatter:'{value}%'}, splitLine:{lineStyle:{color:T.grid}}},
    series
  });
  if(cMari){
    const drawLabels = () => {
      let acc=0;
      const elements = groups.map(g => {
        const mid = acc + g.total/2; acc += g.total;
        const px = cMari.convertToPixel({xAxisIndex:0}, mid);
        const py = cMari.getHeight() - 14;
        return {type:'text', left:px, top:py, style:{text:g.name, fill:T.sub, font:'10px Pretendard,system-ui', textAlign:'center'}};
      });
      cMari.setOption({graphic:{elements}});
    };
    cMari.on('finished', drawLabels);
    window.addEventListener('resize', () => setTimeout(drawLabels, 50));
  }
};
factory();
```

## 원본 factory (갤러리 정본 발췌)
- file: `frontend/js/graph-gallery/main.js`
- lines: 2841-2898
- gallery: https://graph.heal7.com/#DIS-13
- raw js: https://graph.heal7.com/sku/DIS-13.js

```js
function(){
  const groups = [
    {name:'국내', total:42, seg:[['엔터프라이즈',45],['미드',35],['SMB',20]]},
    {name:'아시아', total:28, seg:[['엔터프라이즈',30],['미드',45],['SMB',25]]},
    {name:'북미', total:20, seg:[['엔터프라이즈',55],['미드',30],['SMB',15]]},
    {name:'EU', total:10, seg:[['엔터프라이즈',40],['미드',35],['SMB',25]]}
  ];
  const totalW = groups.reduce((a,g)=>a+g.total,0);
  const segs = ['엔터프라이즈','미드','SMB'];
  const colors = [T.gold, T.royal, T.teal];
  const series = segs.map((s,i)=>({
    type:'custom', name:s, stack:'mari',
    renderItem:(p, api)=>{
      const g = groups[api.value(0)];
      // x bands
      let xStart = 0;
      for(let k=0;k<api.value(0);k++) xStart += groups[k].total;
      const x0 = api.coord([xStart,0])[0];
      const x1 = api.coord([xStart + g.total,0])[0];
      // y stack within group
      let cum = 0;
      for(let k=0;k<i;k++) cum += g.seg[k][1];
      const y0 = api.coord([0, cum])[1];
      const y1 = api.coord([0, cum + g.seg[i][1]])[1];
      return {
        type:'rect',
        shape:{x:x0+2, y:y1, width:x1-x0-4, height:y0-y1},
        style:{fill:colors[i], opacity:.85, stroke:'rgba(0,0,0,.15)'},
        emphasis:{style:{opacity:1}}
      };
    },
    data: groups.map((g,gi)=>({value:[gi, g.seg[i][1], g.name, s]})),
    encode:{tooltip:[2,3]}
  }));
  const cMari = reg('c-mari', {
    backgroundColor:T.bg,
    tooltip:{formatter: p => `${p.value[2]} · ${p.value[3]}<br/>${p.value[1]}%`},
    legend:{data:segs, top:0, textStyle:{color:T.sub}, itemWidth:10, itemHeight:10},
    grid:{left:48, right:14, top:30, bottom:34},
    xAxis:{type:'value', max:totalW, axisLabel:{show:false}, splitLine:{show:false}, axisTick:{show:false}, axisLine:{lineStyle:{color:T.grid}}},
    yAxis:{type:'value', max:100, axisLabel:{color:T.sub, fontSize:10, formatter:'{value}%'}, splitLine:{lineStyle:{color:T.grid}}},
    series
  });
  if(cMari){
    const drawLabels = () => {
      let acc=0;
      const elements = groups.map(g => {
        const mid = acc + g.total/2; acc += g.total;
        const px = cMari.convertToPixel({xAxisIndex:0}, mid);
        const py = cMari.getHeight() - 14;
        return {type:'text', left:px, top:py, style:{text:g.name, fill:T.sub, font:'10px Pretendard,system-ui', textAlign:'center'}};
      });
      cMari.setOption({graphic:{elements}});
    };
    cMari.on('finished', drawLabels);
    window.addEventListener('resize', () => setTimeout(drawLabels, 50));
  }
}
```

