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/594/label height adjustment #662

Merged
merged 6 commits into from
Aug 2, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
### Removed

### Fixed
- Label hight adjustment now matches scaling of map #594

- SCMLogParser now guesses the input file encoding #614

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ describe("CodeMapLabelService", () => {
const scaleAfterA: Vector3 = codeMapLabelService["labels"][0].sprite.position
const scaleAfterB: Vector3 = codeMapLabelService["labels"][1].sprite.position

expect(scaleAfterA.x).toBe(scaleBeforeA.x * SX)
expect(scaleAfterA.y).toBe(scaleBeforeA.y * SY)
expect(scaleAfterA.z).toBe(scaleBeforeA.z * SZ)
expect(scaleAfterA.x).toBe((scaleBeforeA.x / 1) * SX)
expect(scaleAfterA.y).toBe(((scaleBeforeA.y - 60) / 1) * SY + 60)
expect(scaleAfterA.z).toBe((scaleBeforeA.z / 1) * SZ)

expect(scaleAfterB.x).toBe(scaleBeforeB.x * SX)
expect(scaleAfterB.y).toBe(scaleBeforeB.y * SY)
expect(scaleAfterB.z).toBe(scaleBeforeB.z * SZ)
expect(scaleAfterB.x).toBe((scaleBeforeA.x / 1) * SX)
expect(scaleAfterB.y).toBe(((scaleBeforeA.y - 60) / 1) * SY + 60)
expect(scaleAfterB.z).toBe((scaleBeforeA.z / 1) * SZ)
})
})
28 changes: 19 additions & 9 deletions visualization/app/codeCharta/ui/codeMap/codeMap.label.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class CodeMapLabelService implements CameraChangeSubscriber {
private LABEL_WIDTH_DIVISOR: number = 2600 // empirically gathered
private LABEL_HEIGHT_DIVISOR: number = 50 // empirically gathered

private currentScale: Vector3 = new THREE.Vector3(1, 1, 1)
private resetScale: boolean = false

constructor(
private $rootScope: IRootScopeService,
private settingsService: SettingsService,
Expand Down Expand Up @@ -48,6 +51,7 @@ export class CodeMapLabelService implements CameraChangeSubscriber {

this.labels.push(label)
}
this.resetScale = true
}

public clearLabels() {
Expand All @@ -58,20 +62,26 @@ export class CodeMapLabelService implements CameraChangeSubscriber {
}

public scale(scale: Vector3) {
if (this.resetScale) {
this.resetScale = false
this.currentScale = new THREE.Vector3(1, 1, 1)
}

for (let label of this.labels) {
label.sprite.position.x *= scale.x
label.sprite.position.y *= scale.y
label.sprite.position.z *= scale.z
const labelHeightDifference = new Vector3(0, 60, 0)
label.sprite.position
.sub(labelHeightDifference.clone())
.divide(this.currentScale.clone())
.multiply(scale.clone())
.add(labelHeightDifference.clone())

//cast is a workaround for the compiler. Attribute vertices does exist on geometry
//but it is missing in the mapping file for TypeScript.
;(<any>label.line!.geometry).vertices[0].x *= scale.x
;(<any>label.line!.geometry).vertices[0].y *= scale.y
;(<any>label.line!.geometry).vertices[0].z *= scale.z
;(<any>label.line!.geometry).vertices[1].x = label.sprite.position.x
;(<any>label.line!.geometry).vertices[1].y = label.sprite.position.y
;(<any>label.line!.geometry).vertices[1].z = label.sprite.position.z
;(<any>label.line.geometry).vertices[0].divide(this.currentScale.clone()).multiply(scale.clone())
;(<any>label.line.geometry).vertices[1].copy(label.sprite.position)
label.line.geometry.translate(0, 0, 0)
}
this.currentScale.copy(scale)
}

public onCameraChanged(camera: PerspectiveCamera, event: angular.IAngularEvent) {
Expand Down