Update Aspect Ratio on Map card (#2126)

* Update Aspect Ratio

* Update Card Size
This commit is contained in:
Zack Arnett 2018-11-27 11:48:41 -05:00 committed by GitHub
parent 4487c3dc1a
commit ffc7f9706d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import processConfigEntities from "../common/process-config-entities";
import computeStateDomain from "../../../common/entity/compute_state_domain";
import computeStateName from "../../../common/entity/compute_state_name";
import debounce from "../../../common/util/debounce";
import parseAspectRatio from "../../../common/util/parse-aspect-ratio";
Leaflet.Icon.Default.imagePath = "/static/images/leaflet";
@ -97,7 +98,15 @@ class HuiMapCard extends PolymerElement {
return;
}
this.$.root.style.paddingTop = this._config.aspect_ratio || "100%";
const ratio = parseAspectRatio(this._config.aspect_ratio);
if (ratio && ratio.w > 0 && ratio.h > 0) {
this.$.root.style.paddingBottom = `${((100 * ratio.h) / ratio.w).toFixed(
2
)}%`;
} else {
this.$.root.style.paddingBottom = "100%";
}
}
setConfig(config) {
@ -110,8 +119,13 @@ class HuiMapCard extends PolymerElement {
}
getCardSize() {
let ar = this._config.aspect_ratio || "100%";
ar = ar.substr(0, ar.length - 1);
const ratio = parseAspectRatio(this._config.aspect_ratio);
let ar;
if (ratio && ratio.w > 0 && ratio.h > 0) {
ar = `${((100 * ratio.h) / ratio.w).toFixed(2)}`;
} else {
ar = "100";
}
return 1 + Math.floor(ar / 25) || 3;
}