Skip to content

Commit

Permalink
feat: support expr in projections
Browse files Browse the repository at this point in the history
fixes #7056
  • Loading branch information
domoritz committed Nov 19, 2020
1 parent 2c81034 commit 78552fd
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 60 deletions.
241 changes: 204 additions & 37 deletions build/vega-lite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20265,105 +20265,272 @@
"additionalProperties": false,
"properties": {
"center": {
"$ref": "#/definitions/Vector2<number>",
"description": "The projection's center, a two-element array of longitude and latitude in degrees.\n\n__Default value:__ `[0, 0]`"
"anyOf": [
{
"$ref": "#/definitions/Vector2<number>",
"description": "The projection's center, a two-element array of longitude and latitude in degrees.\n\n__Default value:__ `[0, 0]`"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"clipAngle": {
"description": "The projection's clipping circle radius to the specified angle in degrees. If `null`, switches to [antimeridian](http://bl.ocks.org/mbostock/3788999) cutting rather than small-circle clipping.",
"type": "number"
"anyOf": [
{
"description": "The projection's clipping circle radius to the specified angle in degrees. If `null`, switches to [antimeridian](http://bl.ocks.org/mbostock/3788999) cutting rather than small-circle clipping.",
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"clipExtent": {
"$ref": "#/definitions/Vector2<Vector2<number>>",
"description": "The projection's viewport clip extent to the specified bounds in pixels. The extent bounds are specified as an array `[[x0, y0], [x1, y1]]`, where `x0` is the left-side of the viewport, `y0` is the top, `x1` is the right and `y1` is the bottom. If `null`, no viewport clipping is performed."
"anyOf": [
{
"$ref": "#/definitions/Vector2<Vector2<number>>",
"description": "The projection's viewport clip extent to the specified bounds in pixels. The extent bounds are specified as an array `[[x0, y0], [x1, y1]]`, where `x0` is the left-side of the viewport, `y0` is the top, `x1` is the right and `y1` is the bottom. If `null`, no viewport clipping is performed."
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"coefficient": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"distance": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"extent": {
"$ref": "#/definitions/Vector2<Vector2<number>>"
"anyOf": [
{
"$ref": "#/definitions/Vector2<Vector2<number>>"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"fit": {
"anyOf": [
{
"$ref": "#/definitions/Fit"
"items": {
"$ref": "#/definitions/GeoJsonFeature"
},
"type": "array"
},
{
"items": {
"$ref": "#/definitions/Fit"
},
"type": "array"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"fraction": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"lobes": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"parallel": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"parallels": {
"description": "For conic projections, the [two standard parallels](https://en.wikipedia.org/wiki/Map_projection#Conic) that define the map layout. The default depends on the specific conic projection used.",
"items": {
"type": "number"
},
"type": "array"
"anyOf": [
{
"description": "For conic projections, the [two standard parallels](https://en.wikipedia.org/wiki/Map_projection#Conic) that define the map layout. The default depends on the specific conic projection used.",
"items": {
"type": "number"
},
"type": "array"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"pointRadius": {
"description": "The default radius (in pixels) to use when drawing GeoJSON `Point` and `MultiPoint` geometries. This parameter sets a constant default value. To modify the point radius in response to data, see the corresponding parameter of the GeoPath and GeoShape transforms.\n\n__Default value:__ `4.5`",
"type": "number"
"anyOf": [
{
"description": "The default radius (in pixels) to use when drawing GeoJSON `Point` and `MultiPoint` geometries. This parameter sets a constant default value. To modify the point radius in response to data, see the corresponding parameter of the GeoPath and GeoShape transforms.\n\n__Default value:__ `4.5`",
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"precision": {
"description": "The threshold for the projection's [adaptive resampling](http://bl.ocks.org/mbostock/3795544) to the specified value in pixels. This value corresponds to the [Douglas–Peucker distance](http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm). If precision is not specified, returns the projection's current resampling precision which defaults to `√0.5 ≅ 0.70710…`.",
"type": "number"
"anyOf": [
{
"description": "The threshold for the projection's [adaptive resampling](http://bl.ocks.org/mbostock/3795544) to the specified value in pixels. This value corresponds to the [Douglas–Peucker distance](http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm). If precision is not specified, returns the projection's current resampling precision which defaults to `√0.5 ≅ 0.70710…`.",
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"radius": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"ratio": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"reflectX": {
"type": "boolean"
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"reflectY": {
"type": "boolean"
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"rotate": {
"anyOf": [
{
"$ref": "#/definitions/Vector2<number>"
"anyOf": [
{
"$ref": "#/definitions/Vector2<number>"
},
{
"$ref": "#/definitions/Vector3<number>"
}
],
"description": "The projection's three-axis rotation to the specified angles, which must be a two- or three-element array of numbers [`lambda`, `phi`, `gamma`] specifying the rotation angles in degrees about each spherical axis. (These correspond to yaw, pitch and roll.)\n\n__Default value:__ `[0, 0, 0]`"
},
{
"$ref": "#/definitions/Vector3<number>"
"$ref": "#/definitions/ExprRef"
}
],
"description": "The projection's three-axis rotation to the specified angles, which must be a two- or three-element array of numbers [`lambda`, `phi`, `gamma`] specifying the rotation angles in degrees about each spherical axis. (These correspond to yaw, pitch and roll.)\n\n__Default value:__ `[0, 0, 0]`"
]
},
"scale": {
"description": "The projection’s scale (zoom) factor, overriding automatic fitting. The default scale is projection-specific. The scale factor corresponds linearly to the distance between projected points; however, scale factor values are not equivalent across projections.",
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
],
"description": "The projection’s scale (zoom) factor, overriding automatic fitting. The default scale is projection-specific. The scale factor corresponds linearly to the distance between projected points; however, scale factor values are not equivalent across projections."
},
"size": {
"$ref": "#/definitions/Vector2<number>"
"anyOf": [
{
"$ref": "#/definitions/Vector2<number>"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"spacing": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"tilt": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{
"$ref": "#/definitions/ExprRef"
}
]
},
"translate": {
"$ref": "#/definitions/Vector2<number>",
"anyOf": [
{
"$ref": "#/definitions/Vector2<number>"
},
{
"$ref": "#/definitions/ExprRef"
}
],
"description": "The projection’s translation offset as a two-element array `[tx, ty]`."
},
"type": {
"$ref": "#/definitions/ProjectionType",
"anyOf": [
{
"$ref": "#/definitions/ProjectionType"
},
{
"$ref": "#/definitions/ExprRef"
}
],
"description": "The cartographic projection to use. This value is case-insensitive, for example `\"albers\"` and `\"Albers\"` indicate the same projection type. You can find all valid projection types [in the documentation](https://vega.github.io/vega-lite/docs/projection.html#projection-types).\n\n__Default value:__ `equalEarth`"
}
},
Expand Down
37 changes: 37 additions & 0 deletions examples/specs/geo_params_projections.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width": 500,
"height": 300,
"params": [
{
"name": "projection",
"value": "equalEarth",
"bind": {
"input": "select",
"options": [
"albers",
"albersUsa",
"azimuthalEqualArea",
"azimuthalEquidistant",
"conicConformal",
"conicEqualArea",
"conicEquidistant",
"equalEarth",
"equirectangular",
"gnomonic",
"mercator",
"naturalEarth1",
"orthographic",
"stereographic",
"transverseMercator"
]
}
}
],
"data": {
"url": "data/world-110m.json",
"format": {"type": "topojson", "feature": "countries"}
},
"projection": {"type": {"expr": "projection"}},
"mark": {"type": "geoshape", "fill": "lightgray", "stroke": "gray"}
}
6 changes: 6 additions & 0 deletions site/_data/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,12 @@
"title": "London Tube Lines",
"description": "This example was created by @jwoLondon.",
"png": true
},
{
"name": "geo_params_projections",
"title": "Projection explorer",
"description": "Compare different projections.",
"png": true
}
]
},
Expand Down
5 changes: 2 additions & 3 deletions src/compile/projection/component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {SignalRef} from 'vega';
import {Projection as VgProjection, SignalRef} from 'vega';
import {Projection} from '../../projection';
import {Projection as VgProjection} from 'vega';
import {Split} from '../split';

export class ProjectionComponent extends Split<VgProjection> {
public merged = false;

constructor(
name: string,
public specifiedProjection: Projection,
public specifiedProjection: Projection<SignalRef>,
public size: SignalRef[],
public data: (string | SignalRef)[]
) {
Expand Down
Loading

0 comments on commit 78552fd

Please sign in to comment.