Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/compiled/line_dynamic_axis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/line_dynamic_axis.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions examples/compiled/line_dynamic_axis.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "Vega-Lite computes the minimum and maximum axes values automatically but this can be made more dynamic by using params to produce axes which are +/- 20% of the minimum and maximum values in the dataset.",
"background": "white",
"padding": 5,
"width": 200,
"height": 200,
"style": "cell",
"data": [
{
"name": "source_0",
"values": [
{"x": 1, "y": 11},
{"x": 2, "y": 10},
{"x": 3, "y": 11.23},
{"x": 4, "y": 10},
{"x": 5, "y": 9.5},
{"x": 6, "y": 10},
{"x": 7, "y": 10}
]
},
{
"name": "data_0",
"source": "source_0",
"transform": [
{"type": "formula", "expr": "toNumber(datum[\"x\"])", "as": "x"}
]
},
{
"name": "data_1",
"source": "data_0",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"x\"]) && isFinite(+datum[\"x\"]) && isValid(datum[\"y\"]) && isFinite(+datum[\"y\"])"
}
]
}
],
"signals": [
{"name": "extents", "update": "extent(pluck(data('source_0'), 'y'))"},
{"name": "min", "update": "extents[0] * 0.8"},
{"name": "max", "update": "extents[1] * 1.2"}
],
"marks": [
{
"name": "layer_0_marks",
"type": "line",
"style": ["line"],
"sort": {"field": "datum[\"x\"]"},
"from": {"data": "data_0"},
"encode": {
"update": {
"stroke": {"value": "#4c78a8"},
"description": {
"signal": "\"x: \" + (format(datum[\"x\"], \"\")) + \"; y: \" + (format(datum[\"y\"], \"\"))"
},
"x": {"scale": "x", "field": "x"},
"y": {"scale": "y", "field": "y"},
"defined": {
"signal": "isValid(datum[\"x\"]) && isFinite(+datum[\"x\"]) && isValid(datum[\"y\"]) && isFinite(+datum[\"y\"])"
}
}
}
},
{
"name": "layer_1_marks",
"type": "symbol",
"style": ["point"],
"from": {"data": "data_1"},
"encode": {
"update": {
"opacity": {"value": 1},
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "point"},
"description": {
"signal": "\"x: \" + (format(datum[\"x\"], \"\")) + \"; y: \" + (format(datum[\"y\"], \"\"))"
},
"x": {"scale": "x", "field": "x"},
"y": {"scale": "y", "field": "y"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {
"fields": [
{"data": "data_0", "field": "x"},
{"data": "data_1", "field": "x"}
]
},
"range": [0, {"signal": "width"}],
"nice": true,
"zero": false
},
{
"name": "y",
"type": "linear",
"domain": {"signal": "[min,max]"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": false
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"gridScale": "x",
"grid": true,
"tickCount": {"signal": "ceil(height/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "x",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "y",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
]
}
29 changes: 29 additions & 0 deletions examples/specs/line_dynamic_axis.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Vega-Lite computes the minimum and maximum axes values automatically but this can be made more dynamic by using params to produce axes which are +/- 20% of the minimum and maximum values in the dataset.",
"data": {
"values": [
{"x": 1, "y": 11},
{"x": 2, "y": 10},
{"x": 3, "y": 11.23},
{"x": 4, "y": 10},
{"x": 5, "y": 9.5},
{"x": 6, "y": 10},
{"x": 7, "y": 10}
]
},
"params": [
{"name": "extents", "expr": "extent(pluck(data('source_0'), 'y'))"},
{"name": "min", "expr": "extents[0] * 0.8"},
{"name": "max", "expr": "extents[1] * 1.2"}
],
"mark": {"type": "line", "point": true},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domain": {"expr": "[min,max]"}}
}
}
}
44 changes: 44 additions & 0 deletions examples/specs/normalized/line_dynamic_axis_normalized.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Vega-Lite computes the minimum and maximum axes values automatically but this can be made more dynamic by using params to produce axes which are +/- 20% of the minimum and maximum values in the dataset.",
"data": {
"values": [
{"x": 1, "y": 11},
{"x": 2, "y": 10},
{"x": 3, "y": 11.23},
{"x": 4, "y": 10},
{"x": 5, "y": 9.5},
{"x": 6, "y": 10},
{"x": 7, "y": 10}
]
},
"params": [
{"name": "extents", "expr": "extent(pluck(data('source_0'), 'y'))"},
{"name": "min", "expr": "extents[0] * 0.8"},
{"name": "max", "expr": "extents[1] * 1.2"}
],
"layer": [
{
"mark": "line",
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domain": {"expr": "[min,max]"}}
}
}
},
{
"mark": {"type": "point", "opacity": 1, "filled": true},
"encoding": {
"x": {"field": "x", "type": "quantitative"},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domain": {"expr": "[min,max]"}}
}
}
}
]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/d3": "^7.4.3",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.12",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"cheerio": "^1.0.0-rc.12",
Expand All @@ -109,7 +109,7 @@
"jest-dev-server": "^9.0.2",
"mkdirp": "^3.0.1",
"pako": "^2.1.0",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"puppeteer": "^15.0.0",
"release-it": "^17.0.3",
"rollup": "^4.9.6",
Expand Down
3 changes: 1 addition & 2 deletions src/normalize/pathoverlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class PathOverlayNormalizer implements NonFacetUnitNormalizer<UnitSpecWit

public run(spec: UnitSpecWithPathOverlay, normParams: NormalizerParams, normalize: NormalizeLayerOrUnit) {
const {config} = normParams;
const {params, projection, mark, name, encoding: e, ...outerSpec} = spec;
const {projection, mark, name, encoding: e, ...outerSpec} = spec;

// Need to call normalizeEncoding because we need the inferred types to correctly determine stack
const encoding = normalizeEncoding(e, config);
Expand All @@ -116,7 +116,6 @@ export class PathOverlayNormalizer implements NonFacetUnitNormalizer<UnitSpecWit
const layer: NormalizedUnitSpec[] = [
{
name,
...(params ? {params} : {}),
mark: dropLineAndPoint({
// TODO: extract this 0.7 to be shared with default opacity for point/tick/...
...(markDef.type === 'area' && markDef.opacity === undefined && markDef.fillOpacity === undefined
Expand Down
Loading