Skip to content

Commit

Permalink
Prefer user input over defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Apr 1, 2024
1 parent bbd868b commit b41c3a0
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 137 deletions.
1 change: 0 additions & 1 deletion src/column-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type _GeoArrowColumnLayerProps = {

/**
* Method called to retrieve the position of each column.
* @default object => object.position
*/
getPosition?: ga.vector.PointVector;

Expand Down
26 changes: 16 additions & 10 deletions src/heatmap-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,23 @@ export class GeoArrowHeatmapLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
if (this.props.getPosition !== undefined) {
const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
}

const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
throw new Error(
"getPosition should pass in an arrow Vector of Point type",
);
} else {
const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
}

throw new Error("getPosition not GeoArrow point");
Expand Down
58 changes: 32 additions & 26 deletions src/path-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,35 +105,41 @@ export class GeoArrowPathLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const lineStringVector = getGeometryVector(
table,
EXTENSION_NAME.LINESTRING,
);
if (lineStringVector !== null) {
return this._renderLayersLineString(lineStringVector);
}
if (this.props.getPath !== undefined) {
const geometryColumn = this.props.getPath;
if (
geometryColumn !== undefined &&
ga.vector.isLineStringVector(geometryColumn)
) {
return this._renderLayersLineString(geometryColumn);
}

const multiLineStringVector = getGeometryVector(
table,
EXTENSION_NAME.MULTILINESTRING,
);
if (multiLineStringVector !== null) {
return this._renderLayersMultiLineString(multiLineStringVector);
}
if (
geometryColumn !== undefined &&
ga.vector.isMultiLineStringVector(geometryColumn)
) {
return this._renderLayersMultiLineString(geometryColumn);
}

const geometryColumn = this.props.getPath;
if (
geometryColumn !== undefined &&
ga.vector.isLineStringVector(geometryColumn)
) {
return this._renderLayersLineString(geometryColumn);
}
throw new Error(
"getPath should be an arrow Vector of LineString or MultiLineString type",
);
} else {
const lineStringVector = getGeometryVector(
table,
EXTENSION_NAME.LINESTRING,
);
if (lineStringVector !== null) {
return this._renderLayersLineString(lineStringVector);
}

if (
geometryColumn !== undefined &&
ga.vector.isMultiLineStringVector(geometryColumn)
) {
return this._renderLayersMultiLineString(geometryColumn);
const multiLineStringVector = getGeometryVector(
table,
EXTENSION_NAME.MULTILINESTRING,
);
if (multiLineStringVector !== null) {
return this._renderLayersMultiLineString(multiLineStringVector);
}
}

throw new Error("getPath not GeoArrow LineString or MultiLineString");
Expand Down
28 changes: 17 additions & 11 deletions src/point-cloud-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,26 @@ export class GeoArrowPointCloudLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
if (this.props.getPosition !== undefined) {
const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
}

const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
throw new Error(
"getPosition should pass in an arrow Vector of Point type",
);
} else {
const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
}

throw new Error("geometryColumn not GeoArrow point");
throw new Error("getPosition not GeoArrow point");
}

_renderLayersPoint(
Expand Down
46 changes: 26 additions & 20 deletions src/polygon-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,32 @@ export class GeoArrowPolygonLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const polygonVector = getGeometryVector(table, EXTENSION_NAME.POLYGON);
if (polygonVector !== null) {
return this._renderLayers(polygonVector);
}

const multiPolygonVector = getGeometryVector(
table,
EXTENSION_NAME.MULTIPOLYGON,
);
if (multiPolygonVector !== null) {
return this._renderLayers(multiPolygonVector);
}

const geometryColumn = this.props.getPolygon;
if (ga.vector.isPolygonVector(geometryColumn)) {
return this._renderLayers(geometryColumn);
}

if (ga.vector.isMultiPolygonVector(geometryColumn)) {
return this._renderLayers(geometryColumn);
if (this.props.getPolygon !== undefined) {
const geometryColumn = this.props.getPolygon;
if (ga.vector.isPolygonVector(geometryColumn)) {
return this._renderLayers(geometryColumn);
}

if (ga.vector.isMultiPolygonVector(geometryColumn)) {
return this._renderLayers(geometryColumn);
}

throw new Error(
"getPolygon should be an arrow Vector of Polygon or MultiPolygon type",
);
} else {
const polygonVector = getGeometryVector(table, EXTENSION_NAME.POLYGON);
if (polygonVector !== null) {
return this._renderLayers(polygonVector);
}

const multiPolygonVector = getGeometryVector(
table,
EXTENSION_NAME.MULTIPOLYGON,
);
if (multiPolygonVector !== null) {
return this._renderLayers(multiPolygonVector);
}
}

throw new Error("geometryColumn not Polygon or MultiPolygon");
Expand Down
52 changes: 29 additions & 23 deletions src/scatterplot-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,38 @@ export class GeoArrowScatterplotLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
if (this.props.getPosition !== undefined) {
const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
}

const multiPointVector = getGeometryVector(
table,
EXTENSION_NAME.MULTIPOINT,
);
if (multiPointVector !== null) {
return this._renderLayersMultiPoint(multiPointVector);
}
if (
geometryColumn !== undefined &&
ga.vector.isMultiPointVector(geometryColumn)
) {
return this._renderLayersMultiPoint(geometryColumn);
}

const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
}
throw new Error(
"getPosition should pass in an arrow Vector of Point or MultiPoint type",
);
} else {
const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}

if (
geometryColumn !== undefined &&
ga.vector.isMultiPointVector(geometryColumn)
) {
return this._renderLayersMultiPoint(geometryColumn);
const multiPointVector = getGeometryVector(
table,
EXTENSION_NAME.MULTIPOINT,
);
if (multiPointVector !== null) {
return this._renderLayersMultiPoint(multiPointVector);
}
}

throw new Error("getPosition not GeoArrow point or multipoint");
Expand Down
52 changes: 29 additions & 23 deletions src/solid-polygon-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,32 +354,38 @@ export class GeoArrowSolidPolygonLayer<
const { table } = this.state;
if (!table) return null;

const polygonVector = getGeometryVector(table, EXTENSION_NAME.POLYGON);
if (polygonVector !== null) {
return this._renderLayersPolygon(polygonVector);
}
if (this.props.getPolygon !== undefined) {
const geometryColumn = this.props.getPolygon;
if (
geometryColumn !== undefined &&
ga.vector.isPolygonVector(geometryColumn)
) {
return this._renderLayersPolygon(geometryColumn);
}

const MultiPolygonVector = getGeometryVector(
table,
EXTENSION_NAME.MULTIPOLYGON,
);
if (MultiPolygonVector !== null) {
return this._renderLayersMultiPolygon(MultiPolygonVector);
}
if (
geometryColumn !== undefined &&
ga.vector.isMultiPolygonVector(geometryColumn)
) {
return this._renderLayersMultiPolygon(geometryColumn);
}

const geometryColumn = this.props.getPolygon;
if (
geometryColumn !== undefined &&
ga.vector.isPolygonVector(geometryColumn)
) {
return this._renderLayersPolygon(geometryColumn);
}
throw new Error(
"getPolygon should be an arrow Vector of Polygon or MultiPolygon type",
);
} else {
const polygonVector = getGeometryVector(table, EXTENSION_NAME.POLYGON);
if (polygonVector !== null) {
return this._renderLayersPolygon(polygonVector);
}

if (
geometryColumn !== undefined &&
ga.vector.isMultiPolygonVector(geometryColumn)
) {
return this._renderLayersMultiPolygon(geometryColumn);
const MultiPolygonVector = getGeometryVector(
table,
EXTENSION_NAME.MULTIPOLYGON,
);
if (MultiPolygonVector !== null) {
return this._renderLayersMultiPolygon(MultiPolygonVector);
}
}

throw new Error("getPolygon not GeoArrow Polygon or MultiPolygon");
Expand Down
26 changes: 16 additions & 10 deletions src/text-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,23 @@ export class GeoArrowTextLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
if (this.props.getPosition !== undefined) {
const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
}

const geometryColumn = this.props.getPosition;
if (
geometryColumn !== undefined &&
ga.vector.isPointVector(geometryColumn)
) {
return this._renderLayersPoint(geometryColumn);
throw new Error(
"getPosition should pass in an arrow Vector of Point type",
);
} else {
const pointVector = getGeometryVector(table, EXTENSION_NAME.POINT);
if (pointVector !== null) {
return this._renderLayersPoint(pointVector);
}
}

throw new Error("getPosition not GeoArrow point");
Expand Down
30 changes: 17 additions & 13 deletions src/trips-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,24 @@ export class GeoArrowTripsLayer<
renderLayers(): Layer<{}> | LayersList | null {
const { data: table } = this.props;

const lineStringVector = getGeometryVector(
table,
EXTENSION_NAME.LINESTRING,
);
if (lineStringVector !== null) {
return this._renderLayersLineString(lineStringVector);
}
if (this.props.getPath !== undefined) {
const geometryColumn = this.props.getPath;
if (
geometryColumn !== undefined &&
ga.vector.isLineStringVector(geometryColumn)
) {
return this._renderLayersLineString(geometryColumn);
}

const geometryColumn = this.props.getPath;
if (
geometryColumn !== undefined &&
ga.vector.isLineStringVector(geometryColumn)
) {
return this._renderLayersLineString(geometryColumn);
throw new Error("getPath should be an arrow Vector of LineString type");
} else {
const lineStringVector = getGeometryVector(
table,
EXTENSION_NAME.LINESTRING,
);
if (lineStringVector !== null) {
return this._renderLayersLineString(lineStringVector);
}
}

throw new Error("getPath not GeoArrow LineString");
Expand Down

0 comments on commit b41c3a0

Please sign in to comment.