-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from acaprojects/feature/refactor
Feature/refactor
- Loading branch information
Showing
63 changed files
with
2,130 additions
and
1,727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// import { MapRenderFeature } from './map-render-feature'; | ||
|
||
// describe('MapFeature', () => { | ||
// it('should create an instance', () => { | ||
// expect(new MapRenderFeature(null, null)).toBeTruthy(); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { TemplateRef, Type } from '@angular/core'; | ||
|
||
import { Point, RenderFeature } from '../helpers/type.helpers'; | ||
import { RenderableMap } from './renderable-map'; | ||
import { log } from '../settings'; | ||
|
||
export class MapRenderFeature { | ||
/** ID of an element to render */ | ||
public readonly id: string; | ||
/** Coordinates with the map */ | ||
public readonly coordinates: Point; | ||
/** Content to render on the map */ | ||
public readonly content: RenderFeature; | ||
/** Data to pass to the content */ | ||
public readonly data: any; | ||
/** Data to pass to the content */ | ||
public readonly show_after_zoom: number; | ||
|
||
/** Type of content being rendered by this feature */ | ||
public get content_type(): 'component' | 'template' | 'html' { | ||
return this.content instanceof Type | ||
? 'component' | ||
: this.content instanceof TemplateRef | ||
? 'template' | ||
: 'html'; | ||
} | ||
|
||
constructor(data: { [name: string]: any }, map: RenderableMap) { | ||
const coordinates = this.processCoordinates(data.id || data.coordinates, map); | ||
this.id = data.id || JSON.stringify(coordinates); | ||
this.coordinates = coordinates; | ||
this.content = data.content; | ||
this.data = data.data || data.styles; | ||
this.show_after_zoom = data.show_after_zoom; | ||
} | ||
|
||
private processCoordinates(data: string | Point, map: RenderableMap): Point { | ||
if (!map) { return; } | ||
if (typeof data === 'string') { | ||
const element = map.element_map[data]; | ||
if (element) { | ||
return element.coordinates; | ||
} else { | ||
log('MAP', `No element for id "${data}"`, undefined, 'warn'); | ||
} | ||
} else { | ||
if (data.x <= 1 && data.x >= 0 && data.y <= 1 && data.y >= 0) { | ||
return data; | ||
} else { | ||
return { | ||
x: data.x / 10000, | ||
y: data.y / (10000 * map.dimensions.y) | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// import { MapStyles } from './map-styles'; | ||
|
||
// describe('MapStyles', () => { | ||
// it('should create an instance', () => { | ||
// expect(new MapStyles({}, null)).toBeTruthy(); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { HashMap } from '../helpers/type.helpers'; | ||
import { cleanCssSelector } from '../helpers/map.helpers'; | ||
import { RenderableMap } from './renderable-map'; | ||
|
||
export class MapStyles { | ||
/** Mapping of CSS selectors to override CSS properties */ | ||
public readonly styles: HashMap<HashMap<string>>; | ||
/** CSS string that can be injected into the DOM */ | ||
private _css: string; | ||
/** Element rendering the map styles */ | ||
private _element: HTMLStyleElement; | ||
/** CSS string that can be injected into the DOM */ | ||
public get css(): string { | ||
return this._css; | ||
} | ||
|
||
constructor(styles: HashMap<HashMap<string>>, private map: RenderableMap) { | ||
this.styles = styles; | ||
this._css = this._processStyles(styles); | ||
this._renderStyleElement(this.css); | ||
} | ||
|
||
/** Cleanup map styles */ | ||
public destroy() { | ||
if (this._element) { | ||
this._element.parentElement.removeChild(this._element); | ||
delete this._element; | ||
this._element = null; | ||
} | ||
} | ||
|
||
/** | ||
* Convert style map into CSS string | ||
* @param styles Mapping of CSS selectors to override CSS properties | ||
*/ | ||
private _processStyles(styles: HashMap<HashMap<string>>): string { | ||
let css = ''; | ||
for (const selector in this.styles) { | ||
if (this.styles.hasOwnProperty(selector)) { | ||
let style = `.map[id="${this.map ? this.map.id : 'map-0'}"] ${cleanCssSelector(selector)} { `; | ||
for (const property in this.styles[selector]) { | ||
if (this.styles[selector][property]) { | ||
style += `${property}: ${this.styles[selector][property]}; `; | ||
} | ||
} | ||
style += '} '; | ||
css += style; | ||
} | ||
} | ||
return css; | ||
} | ||
|
||
/** Render Style Element on the DOM */ | ||
private _renderStyleElement(css: string) { | ||
if (this.map) { | ||
const element = document.createElement('style'); | ||
element.id = `placeos-${this.map.id}`; | ||
element.innerHTML = css; | ||
document.head.appendChild(element); | ||
this._element = element; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// import { RenderableMap } from './renderable-map'; | ||
|
||
// describe('RenderableMap', () => { | ||
// it('should create an instance', () => { | ||
// expect(new RenderableMap('', '')).toBeTruthy(); | ||
// }); | ||
// }); |
Oops, something went wrong.