승패 스파크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.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<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>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));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.',
});
}<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>승패 스파크</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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') }
: {}),
},
},
];
const options = { columns: columns('sign'), rows, rowKey: 'id' };
const actions = {
rule: (api, value) => api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
function setup(_api, log) {
log({
ko: '"기준"을 바꿔 같은 값이 다른 승패로 바뀌는지 보세요.',
en: 'Change "Rule" to see the same values turn into different outcomes.',
});
}
options.ariaLabel = "승패 스파크";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('rule').addEventListener('change', (event) => actions.rule(api, event.target.value));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="기준"
disabled={!api}
onChange={(event) => api && actions.rule(api, event.target.value)}
>
<option value="sign">부호</option>
<option value="five">5점 넘으면 승</option>
</select>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
margin: number[];
}
const rows: Row[] = [
{ 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: 'sign' | 'five'): ColumnDef<Row>[] => [
{ id: 'team', title: '팀', width: 110 },
{
id: 'margin',
title: '점수 차',
width: 200,
cellRenderer: 'sparkwinloss',
cellRendererParams: {
height: 22,
gap: 2,
...(rule === 'five'
? { when: (v: number) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
: {}),
},
},
];
export const options: GridOptions<Row> = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
rule: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"기준"을 바꿔 같은 값이 다른 승패로 바뀌는지 보세요.',
en: 'Change "Rule" to see the same values turn into different outcomes.',
});
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="기준"
:disabled="!api"
@change="api && actions.rule(api, ($event.target as HTMLSelectElement).value)"
>
<option value="sign" selected>부호</option>
<option value="five">5점 넘으면 승</option>
</select>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
margin: number[];
}
const rows: Row[] = [
{ 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: 'sign' | 'five'): ColumnDef<Row>[] => [
{ id: 'team', title: '팀', width: 110 },
{
id: 'margin',
title: '점수 차',
width: 200,
cellRenderer: 'sparkwinloss',
cellRendererParams: {
height: 22,
gap: 2,
...(rule === 'five'
? { when: (v: number) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
: {}),
},
},
];
export const options: GridOptions<Row> = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
rule: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"기준"을 바꿔 같은 값이 다른 승패로 바뀌는지 보세요.',
en: 'Change "Rule" to see the same values turn into different outcomes.',
});
}버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="기준"
[disabled]="!api"
(change)="api && actions.rule(api, $any($event.target).value)"
>
<option value="sign" selected>부호</option>
<option value="five">5점 넘으면 승</option>
</select>
</div>
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
margin: number[];
}
const rows: Row[] = [
{ 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: 'sign' | 'five'): ColumnDef<Row>[] => [
{ id: 'team', title: '팀', width: 110 },
{
id: 'margin',
title: '점수 차',
width: 200,
cellRenderer: 'sparkwinloss',
cellRendererParams: {
height: 22,
gap: 2,
...(rule === 'five'
? { when: (v: number) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
: {}),
},
},
];
export const options: GridOptions<Row> = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
rule: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '"기준"을 바꿔 같은 값이 다른 승패로 바뀌는지 보세요.',
en: 'Change "Rule" to see the same values turn into different outcomes.',
});
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<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>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));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.');
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Win/loss sparkline</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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') }
: {}),
},
},
];
const options = { columns: columns('sign'), rows, rowKey: 'id' };
const actions = {
rule: (api, value) => api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
function setup(_api, log) {
log('Change "Rule" to see the same values turn into different outcomes.');
}
options.ariaLabel = "Win/loss sparkline";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('rule').addEventListener('change', (event) => actions.rule(api, event.target.value));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Rule"
disabled={!api}
onChange={(event) => api && actions.rule(api, event.target.value)}
>
<option value="sign">Sign</option>
<option value="five">Over 5 wins</option>
</select>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
margin: number[];
}
const rows: Row[] = [
{ 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: 'sign' | 'five'): ColumnDef<Row>[] => [
{ id: 'team', title: 'Team', width: 110 },
{
id: 'margin',
title: 'Score margin',
width: 200,
cellRenderer: 'sparkwinloss',
cellRendererParams: {
height: 22,
gap: 2,
...(rule === 'five'
? { when: (v: number) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
: {}),
},
},
];
export const options: GridOptions<Row> = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
rule: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log('Change "Rule" to see the same values turn into different outcomes.');
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Rule"
:disabled="!api"
@change="api && actions.rule(api, ($event.target as HTMLSelectElement).value)"
>
<option value="sign" selected>Sign</option>
<option value="five">Over 5 wins</option>
</select>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
margin: number[];
}
const rows: Row[] = [
{ 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: 'sign' | 'five'): ColumnDef<Row>[] => [
{ id: 'team', title: 'Team', width: 110 },
{
id: 'margin',
title: 'Score margin',
width: 200,
cellRenderer: 'sparkwinloss',
cellRendererParams: {
height: 22,
gap: 2,
...(rule === 'five'
? { when: (v: number) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
: {}),
},
},
];
export const options: GridOptions<Row> = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
rule: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log('Change "Rule" to see the same values turn into different outcomes.');
}When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Rule"
[disabled]="!api"
(change)="api && actions.rule(api, $any($event.target).value)"
>
<option value="sign" selected>Sign</option>
<option value="five">Over 5 wins</option>
</select>
</div>
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
margin: number[];
}
const rows: Row[] = [
{ 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: 'sign' | 'five'): ColumnDef<Row>[] => [
{ id: 'team', title: 'Team', width: 110 },
{
id: 'margin',
title: 'Score margin',
width: 200,
cellRenderer: 'sparkwinloss',
cellRendererParams: {
height: 22,
gap: 2,
...(rule === 'five'
? { when: (v: number) => (v > 5 ? 'win' : v < 0 ? 'loss' : 'draw') }
: {}),
},
},
];
export const options: GridOptions<Row> = { columns: columns('sign'), rows, rowKey: 'id' };
export const actions = {
rule: (api: GridApi<Row>, value?: string) =>
api.setColumns(columns(value === 'five' ? 'five' : 'sign')),
};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
log('Change "Rule" to see the same values turn into different outcomes.');
}