The column factory and the immutable builder
{
"c.rank(\"srs_rank\")": {
"kind": "rank",
"key": "srs_rank",
"superscript": true,
"suffixSize": "0.7em"
},
"c.delta(\"pa\", \"pf\")": {
"kind": "delta",
"key": "pa",
"to": "pf",
"label": "Change",
"percent": false,
"decimals": 1,
"arrows": false,
"color": true,
"colorPositive": "#1B7837",
"colorNegative": "#B2182B",
"forceSign": true
},
"c.colorRanks(\"pf\").palette is RANK_PALETTE": true,
"RANK_PALETTE": [
"#3D8B6E",
"#9DC5A7",
"#EDE0CC",
"#DB9070",
"#BE4D3A"
],
"c.fmtRank is c.rank (the gtUtils name)": true,
"defineTable() is a TableBuilder": true,
"every method returns a new builder": true
}import type { Standing } from "@sportsdataverse/examples/data";
import { RANK_PALETTE, TableBuilder, columnFactory, defineTable } from "@sportsdataverse/sdvtables";
// .columns((c) => [...]) hands you this factory; each c.* call returns a column spec with the sdvplotR defaults.
const c = columnFactory<Standing>();
const base = defineTable<Standing>();
const titled = base.title("AFC, 2024");
{
'c.rank("srs_rank")': c.rank("srs_rank"),
'c.delta("pa", "pf")': c.delta("pa", "pf"),
'c.colorRanks("pf").palette is RANK_PALETTE': c.colorRanks("pf").palette === RANK_PALETTE,
RANK_PALETTE,
"c.fmtRank is c.rank (the gtUtils name)": c.fmtRank === c.rank,
"defineTable() is a TableBuilder": base instanceof TableBuilder,
"every method returns a new builder": titled !== base,
};
Tags: table · columnFactory · TableBuilder · RANK_PALETTE. All sdvtables examples.