vega-lite: Cannot format row/col
{
  "data": {"values": [{"a": 1.01,"b": 1.01,"m_teps": 859}]},
  "encoding": {
    "column": {"axis": {"format": "d"},"field": "b","type": "O"},
    "row": {"axis": {"format": "d"},"field": "a","type": "O"},
    "text": {"field": "m_teps","type": "Q", "format": "d"}
  },
  "mark": "text"
}
 
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (16 by maintainers)
Commits related to this issue
- Warns if you format ordinal guides Fixes #1763 — committed to vega/vega-lite by swojit 7 years ago
- Warns if you format ordinal guides Fixes #1763 — committed to vega/vega-lite by swojit 7 years ago
- Warns if you format ordinal guides Fixes #1763 — committed to vega/vega-lite by swojit 7 years ago
I’m working on it. Will probably be done with the PR tonight
Not pretty but here is one (note that this is vl 2)
@NeelMohapatra will add a warning to vega-lite when you try to format an ordinal guide label and link to an example like the one above.
@NeelMohapatra We can actually allow formatting for nominal and ordinal fields.
Add
formatType: 'number' | 'time' | 'utc'toAxis,Legend, andTextFieldDefFor text, tooltips and row/column headers, check if format is explicitly specified in
formatSignalRefincompile/common.ts. If so, apply the right format function (based onformatType) to the output signal. IfformatTypeis not specified, use'number'.For axis and legend, in
compile/axis/encode.tsandcompile/legend/encode.ts, check if fieldDef.type is ordinal / nominal and if format is explicitly specified. If so, apply the right format to labels’stext.Note: see links for specific lines.
Okay, the fact that axis labels cannot be formatted is by design (https://github.com/vega/vega/issues/745#issuecomment-283156390). Two ways forward are: format numbers before we group them, or file an issue with Vega to support. The problem with the first approach is that it doesn’t work well if the same field is used for different guides. However, I’m okay with not supporting that.
Good call, thanks @domoritz. This appears to be working fairly well (for posterity):