Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix hexagon layer projection #4173

Merged
merged 12 commits into from
Jan 24, 2020
Merged

Conversation

heshan0131
Copy link
Collaborator

@heshan0131 heshan0131 commented Jan 20, 2020

  • use center of data to calculate radius in common space. for projection
  • save radiusCommon in aggregation result
  • recalculate meter radius based on saved radiusCommon when viewport updated

#4051

[Infinity, -Infinity] // pt[1]
];

for (let i = 0; i < size * data.length; i += size) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will recalculate every iteration. Assign to a variable.

];

for (let i = 0; i < size * data.length; i += size) {
const arrayIsFinite = Number.isFinite(positions[i]) && Number.isFinite(positions[i + 1]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create variables x & y

const positions = attributes.positions.value;
const {size} = attributes.positions.getAccessor();

const bounds = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf: I’d just use four variables minX, minY, etc.

let angle = 90;
let radius;
const {viewport} = this.context;
const {unitsPerMeter} = viewport.getDistanceScales();

if (Array.isArray(vertices)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the branch used for? Kepler’s h3 aggregation?

You shouldn’t have to reproject the vertices every time the viewport changes. Radius in common units is a constant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it WAS used when kepler.gl has its own aggregator and aggregate points to h3 hexagons. However, we don't need to use this anymore, since we are not aggregate points into h3. For future development, when we want to create a h3 aggregation layer, we can revisit this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A H3 aggregation layer should use the H3HexagonLayer. If this is no longer used by kepler we should mark it as deprecated.

@Pessimistress
Copy link
Collaborator

You need to rebase master and update the render test golden images.

@coveralls
Copy link

coveralls commented Jan 21, 2020

Coverage Status

Coverage decreased (-2.6%) to 80.877% when pulling 90199dc on fix-hexagon-layer-projection into ff55172 on master.

Copy link
Collaborator

@Pessimistress Pessimistress left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would the colors change in the golden images? I don't think color values are affected by this change.

@heshan0131
Copy link
Collaborator Author

Why would the colors change in the golden images? I don't think color values are affected by this change.

Projection shifted, changed number of points in bin, which changes color scale

const radius = dxy / 2 / unitsPerMeter[0];
// offset all points by centroid to meter offset
const vertices = hexagonVertices.map(vt => [
(vt[0] - centroid[0]) * unitsPerMeter,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unitsPerMeter is an array

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LngLat coordinates must first be projected to the common space.

this.updateRadiusAngle(hexagonVertices);
// if user provided custom aggregator and returns hexagonVertices,
// Need to recalculate radius and angle based on vertices
const {hexagonVertices} = cpuAggregator.state.layerData || {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const {hexagonVertices} = cpuAggregator.state.layerData || {};
const {hexagonVertices, radiusCommon} = cpuAggregator.state.layerData || {};

}
} else {
// update radius angle by viewport
this.updateRadiusAngle();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.updateRadiusAngle();
this.updateRadiusAngle(radiusCommon);

}

updateState(opts) {
super.updateState(opts);
const {cpuAggregator} = this.state;
const oldLayerData = cpuAggregator.state.layerData;
const {cpuAggregator, hexagonVertices: oldVertices} = this.state;
this.setState({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf:

if (opts.changeFlags.propsOrDataChanged) {
  // update aggregation
}

@heshan0131 heshan0131 merged commit b513df6 into master Jan 24, 2020
Pessimistress pushed a commit that referenced this pull request Jan 24, 2020
* use center of data to calculate radius in common space. for projection
* save radiusCommon in aggregation result
* recalculate meter radius based on saved radiusCommon when viewport updated
* if hexagonVertices is provided, convert them to meter offset
tgorkin added a commit that referenced this pull request Jan 28, 2020
* master: (82 commits)
  fix typo in performance.md
  pydeck: ArcLayer, BitmapLayer, ColumnLayer examples (#4189)
  [React] fix missing key error (#4193)
  [Bug] Fix hexagon layer projection (#4173)
  Remove HtmlWebpackPlugin from examples/playground (#4178)
  @deck.gl/json: Fix bug dropping props with falsy values (#4185)
  Fix buffer size check in Attribute.updateBuffer (#4190)
  Bump luma dependency (#4191)
  data-filter: support double precision (#4163)
  Use int type for enum uniforms (#4171)
  [TileLayer] fix tile indices generation in edge cases (#4170)
  v8.1.0-alpha.1
  Voodoo fix for Mac+NVIDIA bug (#4166)
  Remove unnecessary code from project glsl (#4162)
  Fix H3HexagonLayer update when viewport jumps (#4158)
  Refactor render tests; use stricter pass criteria (#4157)
  [Extension] Add source_target to brushing mode (#4150)
  Add offset feature to PathStyleExtension (#4126)
  Project module: support pre-projected positions (#4140)
  Repeat maps at low zoom levels (#4105)
  ...
chrisgervang pushed a commit that referenced this pull request Jan 31, 2020
* use center of data to calculate radius in common space. for projection
* save radiusCommon in aggregation result
* recalculate meter radius based on saved radiusCommon when viewport updated
* if hexagonVertices is provided, convert them to meter offset
@Pessimistress Pessimistress deleted the fix-hexagon-layer-projection branch February 13, 2020 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants