---
code: "INT-19"
id: "c-splom"
tab: "dynamic-2"
kind: "interactive"
title: "SPLoM · 산점도 행렬"
library: "ECharts"
deps: ["echarts@5"]
load: "low"
pasteKind: "echarts-mount"
family: "multivariate-analysis"
dataShape: "pairwise scatter matrix"
tasks: ["explore data", "filter subsets", "monitor change", "compare profiles", "inspect correlation"]
tags: ["interactive", "exploration", "linked view", "multivariate", "splom", "산점도", "행렬"]
gallery: "https://graph.heal7.com/#INT-19"
js: "/sku/INT-19.js"
---

# [INT-19] SPLoM · 산점도 행렬

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

## 언제 가져가나
변수 쌍을 행렬로 펼쳐 브러시 선택을 모든 패널에 동시 연결 — 상관·군집·이상치를 한 화면에서 본다.

**응용** 고객 세그먼트 탐색, 품질지표 상관 분석, 모델 피처 관계 점검.

## 데이터 모양
- family: `multivariate-analysis`
- dataShape: pairwise scatter matrix
- tasks: explore data, filter subsets, monitor change, compare profiles, inspect correlation
- tags: interactive, exploration, linked view, multivariate, splom, 산점도, 행렬


## 의존
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 dom = document.getElementById('c-splom'); if(!dom) return;
  const c = echarts.init(dom);
  const dims = [
    {label:'리텐션', min:52, max:98},
    {label:'CTR', min:1.5, max:10.5},
    {label:'객단가', min:28, max:118},
    {label:'NPS', min:8, max:88}
  ];
  const segments = [
    {name:'Starter', color:T.royal, base:[62, 3.2, 42, 24]},
    {name:'Growth',  color:T.gold,  base:[76, 5.9, 74, 51]},
    {name:'Prime',   color:T.teal,  base:[88, 7.6, 101, 73]}
  ];
  const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
  const jitter = (amp) => (Math.random() - 0.5) * amp;
  const points = [];
  segments.forEach((seg, segIdx) => {
    for(let i=0;i<12;i++){
      points.push({
        name:`${seg.name}-${String(i + 1).padStart(2, '0')}`,
        seg:seg.name,
        color:seg.color,
        values:[
          +clamp(seg.base[0] + jitter(18), dims[0].min, dims[0].max).toFixed(1),
          +clamp(seg.base[1] + jitter(2.4), dims[1].min, dims[1].max).toFixed(1),
          +clamp(seg.base[2] + jitter(28), dims[2].min, dims[2].max).toFixed(1),
          +clamp(seg.base[3] + jitter(20), dims[3].min, dims[3].max).toFixed(1)
        ],
        cohort:`군집 ${segIdx + 1}`
      });
    }
  });

  const n = dims.length;
  const cellW = 18;
  const cellH = 15.5;
  const gapX = 4;
  const gapY = 5;
  const left0 = 8;
  const top0 = 12;
  const grids = [];
  const xAxis = [];
  const yAxis = [];
  const series = [];
  const graphic = [
    {type:'text', left:'center', top:2, silent:true,
      style:{text:'drag to brush across all panels', fill:T.sub, fontSize:10, textAlign:'center'}}
  ];

  segments.forEach((seg, i) => {
    graphic.push(
      {type:'circle', left:`${12 + i * 16}%`, top:2, shape:{cx:0, cy:0, r:4}, silent:true, style:{fill:seg.color}},
      {type:'text', left:`${13 + i * 16}%`, top:-2, silent:true,
        style:{text:seg.name, fill:T.sub, fontSize:10}}
    );
  });

  for(let row=0; row<n; row++){
    for(let col=0; col<n; col++){
      const gridIndex = row * n + col;
      const left = left0 + col * (cellW + gapX);
      const top = top0 + row * (cellH + gapY);
      grids.push({left:`${left}%`, top:`${top}%`, width:`${cellW}%`, height:`${cellH}%`});
      xAxis.push({
        type:'value',
        gridIndex,
        min:dims[col].min,
        max:dims[col].max,
        scale:true,
        axisLabel:{show:row === n - 1, color:T.sub, fontSize:9},
        axisLine:{show:row === n - 1, lineStyle:{color:T.grid}},
        axisTick:{show:false},
        splitLine:{show:false}
      });
      yAxis.push({
        type:'value',
        gridIndex,
        min:dims[row].min,
        max:dims[row].max,
        scale:true,
        axisLabel:{show:col === 0, color:T.sub, fontSize:9},
        axisLine:{show:col === 0, lineStyle:{color:T.grid}},
        axisTick:{show:false},
        splitLine:{show:false}
      });

      if(row === col){
        graphic.push({
          type:'text',
          left:`${left + cellW / 2}%`,
          top:`${top + cellH / 2 - 1}%`,
          silent:true,
          style:{text:dims[row].label, fill:T.fg, fontSize:13, fontWeight:700, textAlign:'center', textVerticalAlign:'middle'}
        });
        continue;
      }

      series.push({
        type:'scatter',
        xAxisIndex:gridIndex,
        yAxisIndex:gridIndex,
        symbolSize:7,
        data:points.map(point => ({
          value:[point.values[col], point.values[row]],
          name:point.name,
          rawVals:point.values,
          seg:point.seg,
          cohort:point.cohort,
          itemStyle:{color:point.color, opacity:0.82}
        })),
        emphasis:{itemStyle:{borderColor:'#fff', borderWidth:1.4, opacity:1}},
        animation:false
      });
    }
  }

  reg('c-splom', {
    backgroundColor:T.bg,
    tooltip:{
      formatter: params => {
        const raw = params.data.rawVals || [];
        return `<b>${params.data.name}</b><br>${params.data.seg} · ${params.data.cohort}<br>` +
          dims.map((dim, idx) => `${dim.label}: ${raw[idx]}`).join('<br>');
      }
    },
    toolbox:{show:true, top:0, right:8, iconStyle:{borderColor:T.gold}, feature:{brush:{type:['rect','polygon','clear']}}},
    brush:{
      toolbox:['rect','polygon','clear'],
      brushLink:'all',
      xAxisIndex:xAxis.map((_, idx) => idx),
      yAxisIndex:yAxis.map((_, idx) => idx),
      brushStyle:{borderColor:T.gold, borderWidth:1, color:'rgba(232,192,105,.10)'},
      inBrush:{opacity:1},
      outOfBrush:{colorAlpha:0.08}
    },
    grid:grids,
    xAxis,
    yAxis,
    graphic,
    series
  });
};
factory();
```

## 원본 factory (갤러리 정본 발췌)
- file: `frontend/js/graph-gallery/main.js`
- lines: 1947-2089
- gallery: https://graph.heal7.com/#INT-19
- raw js: https://graph.heal7.com/sku/INT-19.js

```js
function(){
  const dom = document.getElementById('c-splom'); if(!dom) return;
  const c = echarts.init(dom);
  const dims = [
    {label:'리텐션', min:52, max:98},
    {label:'CTR', min:1.5, max:10.5},
    {label:'객단가', min:28, max:118},
    {label:'NPS', min:8, max:88}
  ];
  const segments = [
    {name:'Starter', color:T.royal, base:[62, 3.2, 42, 24]},
    {name:'Growth',  color:T.gold,  base:[76, 5.9, 74, 51]},
    {name:'Prime',   color:T.teal,  base:[88, 7.6, 101, 73]}
  ];
  const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
  const jitter = (amp) => (Math.random() - 0.5) * amp;
  const points = [];
  segments.forEach((seg, segIdx) => {
    for(let i=0;i<12;i++){
      points.push({
        name:`${seg.name}-${String(i + 1).padStart(2, '0')}`,
        seg:seg.name,
        color:seg.color,
        values:[
          +clamp(seg.base[0] + jitter(18), dims[0].min, dims[0].max).toFixed(1),
          +clamp(seg.base[1] + jitter(2.4), dims[1].min, dims[1].max).toFixed(1),
          +clamp(seg.base[2] + jitter(28), dims[2].min, dims[2].max).toFixed(1),
          +clamp(seg.base[3] + jitter(20), dims[3].min, dims[3].max).toFixed(1)
        ],
        cohort:`군집 ${segIdx + 1}`
      });
    }
  });

  const n = dims.length;
  const cellW = 18;
  const cellH = 15.5;
  const gapX = 4;
  const gapY = 5;
  const left0 = 8;
  const top0 = 12;
  const grids = [];
  const xAxis = [];
  const yAxis = [];
  const series = [];
  const graphic = [
    {type:'text', left:'center', top:2, silent:true,
      style:{text:'drag to brush across all panels', fill:T.sub, fontSize:10, textAlign:'center'}}
  ];

  segments.forEach((seg, i) => {
    graphic.push(
      {type:'circle', left:`${12 + i * 16}%`, top:2, shape:{cx:0, cy:0, r:4}, silent:true, style:{fill:seg.color}},
      {type:'text', left:`${13 + i * 16}%`, top:-2, silent:true,
        style:{text:seg.name, fill:T.sub, fontSize:10}}
    );
  });

  for(let row=0; row<n; row++){
    for(let col=0; col<n; col++){
      const gridIndex = row * n + col;
      const left = left0 + col * (cellW + gapX);
      const top = top0 + row * (cellH + gapY);
      grids.push({left:`${left}%`, top:`${top}%`, width:`${cellW}%`, height:`${cellH}%`});
      xAxis.push({
        type:'value',
        gridIndex,
        min:dims[col].min,
        max:dims[col].max,
        scale:true,
        axisLabel:{show:row === n - 1, color:T.sub, fontSize:9},
        axisLine:{show:row === n - 1, lineStyle:{color:T.grid}},
        axisTick:{show:false},
        splitLine:{show:false}
      });
      yAxis.push({
        type:'value',
        gridIndex,
        min:dims[row].min,
        max:dims[row].max,
        scale:true,
        axisLabel:{show:col === 0, color:T.sub, fontSize:9},
        axisLine:{show:col === 0, lineStyle:{color:T.grid}},
        axisTick:{show:false},
        splitLine:{show:false}
      });

      if(row === col){
        graphic.push({
          type:'text',
          left:`${left + cellW / 2}%`,
          top:`${top + cellH / 2 - 1}%`,
          silent:true,
          style:{text:dims[row].label, fill:T.fg, fontSize:13, fontWeight:700, textAlign:'center', textVerticalAlign:'middle'}
        });
        continue;
      }

      series.push({
        type:'scatter',
        xAxisIndex:gridIndex,
        yAxisIndex:gridIndex,
        symbolSize:7,
        data:points.map(point => ({
          value:[point.values[col], point.values[row]],
          name:point.name,
          rawVals:point.values,
          seg:point.seg,
          cohort:point.cohort,
          itemStyle:{color:point.color, opacity:0.82}
        })),
        emphasis:{itemStyle:{borderColor:'#fff', borderWidth:1.4, opacity:1}},
        animation:false
      });
    }
  }

  reg('c-splom', {
    backgroundColor:T.bg,
    tooltip:{
      formatter: params => {
        const raw = params.data.rawVals || [];
        return `<b>${params.data.name}</b><br>${params.data.seg} · ${params.data.cohort}<br>` +
          dims.map((dim, idx) => `${dim.label}: ${raw[idx]}`).join('<br>');
      }
    },
    toolbox:{show:true, top:0, right:8, iconStyle:{borderColor:T.gold}, feature:{brush:{type:['rect','polygon','clear']}}},
    brush:{
      toolbox:['rect','polygon','clear'],
      brushLink:'all',
      xAxisIndex:xAxis.map((_, idx) => idx),
      yAxisIndex:yAxis.map((_, idx) => idx),
      brushStyle:{borderColor:T.gold, borderWidth:1, color:'rgba(232,192,105,.10)'},
      inBrush:{opacity:1},
      outOfBrush:{colorAlpha:0.08}
    },
    grid:grids,
    xAxis,
    yAxis,
    graphic,
    series
  });
}
```

