본문으로 건너뛰기Skip to content
예제 첫화면Examples home

승패 스파크Win/loss sparkline

cellRenderer 'sparkwinloss'는 값의 크기와 상관없이 같은 높이로 승은 위, 패는 아래, 무는 얇은 막대를 그려요. 기본 판정은 부호이고 when으로 기준을 바꿀 수 있어요.cellRenderer 'sparkwinloss' draws equal-height marks, up for a win, down for a loss and a thin bar for a draw, whatever the size. The default rule is the sign, and when changes the rule.

입문Beginner
직접 써 보기Live preview승패 스파크Win/loss sparkline

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="기준" id="rule">
      <option value="sign" selected>부호</option>
      <option value="five">5점 넘으면 승</option>
    </select>
  </div>
  <div id="grid" style="height: 200px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('rule').addEventListener('change', (event) => actions.rule(api, event.target.value));
example.js
const rows = [
  { id: 1, team: '파랑', margin: [3, -2, 7, 0, 1, -5, 8, 2] },
  { id: 2, team: '초록', margin: [-4, -1, 2, 6, 6, -3, 0, 9] },
  { id: 3, team: '주황', margin: [1, 1, -1, -2, 0, 4, 5, -6] },
];
// sparkwinloss: 값의 크기와 상관없이 승(위)·패(아래)·무(얇은 막대). 기본 판정은 부호이고 when으로 바꿔요.
const columns = (rule) => [
  { id: 'team', title: '팀', width: 110 },
  {
    id: 'margin',
    title: '점수 차',
    width: 200,
    cellRenderer: 'sparkwinloss',
    cellRendererParams: {
      height: 22,
      gap: 2,
      ...(rule === 'five'
        ? { when: (v) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
        : {}),
    },
  },
];
export const options = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
  rule: (api, value) => api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api, log) {
  log({
    ko: '"기준"을 바꿔 같은 값이 다른 승패로 바뀌는지 보세요.',
    en: 'Change "Rule" to see the same values turn into different outcomes.',
  });
}

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="Rule" id="rule">
      <option value="sign" selected>Sign</option>
      <option value="five">Over 5 wins</option>
    </select>
  </div>
  <div id="grid" style="height: 200px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('rule').addEventListener('change', (event) => actions.rule(api, event.target.value));
example.js
const rows = [
  { id: 1, team: 'Blue', margin: [3, -2, 7, 0, 1, -5, 8, 2] },
  { id: 2, team: 'Green', margin: [-4, -1, 2, 6, 6, -3, 0, 9] },
  { id: 3, team: 'Orange', margin: [1, 1, -1, -2, 0, 4, 5, -6] },
];
// sparkwinloss: regardless of size, a win is up, a loss is down and a draw is a thin bar. The default rule is the sign; when changes it.
const columns = (rule) => [
  { id: 'team', title: 'Team', width: 110 },
  {
    id: 'margin',
    title: 'Score margin',
    width: 200,
    cellRenderer: 'sparkwinloss',
    cellRendererParams: {
      height: 22,
      gap: 2,
      ...(rule === 'five'
        ? { when: (v) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
        : {}),
    },
  },
];
export const options = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
  rule: (api, value) => api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api, log) {
  log('Change "Rule" to see the same values turn into different outcomes.');
}