Skip to content

Commit

Permalink
Camera shifting (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneElkin authored and ignatvilesov committed Oct 25, 2018
1 parent 0c05c19 commit c023a44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.5.1
* FIX: shifting for camera position was repaired

## 2.5.0
* UPD: using of easeInOutQuint algorithm to animate point selection
* UPD: animation is disabled for the initial load
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "powerbi-visuals-globemap",
"description": "GlobeMap",
"version": "2.5.0",
"version": "2.5.1",
"author": {
"name": "Microsoft",
"email": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion pbiviz.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "GlobeMap",
"guid": "GlobeMap1447669447625",
"visualClassName": "GlobeMap",
"version": "2.5.0",
"version": "2.5.1",
"description": "A 3D visual using WebGL for plotting locations, with category values displayed as bar heights and heat maps.\n\nShift+Click on bar to change center point. \nSlicing data points will animate to average location.\n\nAttributions:\nthree.js - https://github.com/mrdoob/three.js/\nwebgl-heatmap - https://github.com/pyalot/webgl-heatmap",
"supportUrl": "https://aka.ms/customvisualscommunity",
"gitHubUrl": "https://github.com/Microsoft/powerbi-visuals-globemap"
Expand Down
28 changes: 25 additions & 3 deletions src/globemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,28 @@ module powerbi.extensibility.visual {
this.averageBarVector.multiplyScalar(1 / this.barsGroup.children.length);
if (this.locationsLoaded === this.locationsToLoad) {
this.initialLocationsLength = this.barsGroup.children.length;

const maxDistance: number = this.GlobeSettings.cameraRadius - this.GlobeSettings.earthRadius;
const distance: number = (this.camera.position.length() - this.GlobeSettings.earthRadius) / maxDistance;

let angleRate: number = 12;

if (distance < 0.5) {
angleRate = 36;
} else if (distance < 0.25) {
angleRate = 60;
} else if (distance < 0.15) {
angleRate = 0;
}

if (angleRate > 0) {
const axisY = new THREE.Vector3(0, 1, 0);
const axisZ = new THREE.Vector3(0, 0, 1);
const angle = Math.PI / angleRate;
this.averageBarVector.applyAxisAngle(axisY, angle);
this.averageBarVector.applyAxisAngle(axisZ, angle);
}

this.isFirstLoad ? this.setCameraPosition(this.averageBarVector) : this.animateCamera(this.averageBarVector);
}
}
Expand Down Expand Up @@ -1183,9 +1205,9 @@ module powerbi.extensibility.visual {
const endPos: THREE.Vector3 = to.clone().normalize();
const length: number = this.camera.position.length();
const pos: THREE.Vector3 = new THREE.Vector3()
.add(endPos.clone().multiplyScalar(2))
.normalize()
.multiplyScalar(length);
.add(endPos.clone().multiplyScalar(2))
.normalize()
.multiplyScalar(length);

this.camera.position.set(pos.x, pos.y, pos.z);
}
Expand Down

0 comments on commit c023a44

Please sign in to comment.