@nova-ui/dashboards
Version:
Nova Dashboards is a framework designed to provide feature developers with a common solution for presenting data coming from various sources within a single view, as well as a set of predefined widget visualizations that are 100% configuration-driven and
110 lines • 4.73 kB
JavaScript
;
// © 2022 SolarWinds Worldwide, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TilesComponent = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@angular/core");
const bits_1 = require("@nova-ui/bits");
const pizzagna_service_1 = require("../../../pizzagna/services/pizzagna.service");
const base_layout_1 = require("../base-layout");
let TilesComponent = class TilesComponent extends base_layout_1.BaseLayout {
static { this.lateLoadKey = "TilesComponent"; }
constructor(changeDetector, pizzagnaService, logger, ngZone) {
super(changeDetector, pizzagnaService, logger);
this.ngZone = ngZone;
this.nodes = [];
this.direction = "column";
this.prioritizeGridRows = false;
}
ngAfterViewInit() {
this.handleGridFlowOnResize();
}
ngOnDestroy() {
this.tilesResizeObserver?.disconnect();
// Ensures that any base class observables are unsubscribed.
super.ngOnDestroy();
}
getNodes() {
return this.nodes;
}
handleGridFlowOnResize() {
this.tilesResizeObserver = new ResizeObserver(() => this.onResize());
this.ngZone.runOutsideAngular(() => {
this.tilesResizeObserver.observe(this.gridItemsContainer.nativeElement);
});
}
onResize() {
if (this.nodes?.length < 2) {
return;
}
const cssAttributes = this.gridItemsContainer.nativeElement.getBoundingClientRect();
const { height, width } = cssAttributes;
const h2WRatio = height / width;
const allowedH2WRatio = getHeightToWidthRatioFor(this.nodes.length);
const gap = 0.05; // height/width gap used in transitions to avoid widget lagging
if (h2WRatio - gap > allowedH2WRatio && !this.prioritizeGridRows) {
this.prioritizeGridRows = true;
this.changeDetector.detectChanges();
return;
}
if (h2WRatio + gap < allowedH2WRatio && this.prioritizeGridRows) {
this.prioritizeGridRows = false;
this.changeDetector.detectChanges();
return;
}
}
};
exports.TilesComponent = TilesComponent;
tslib_1.__decorate([
(0, core_1.Input)(),
tslib_1.__metadata("design:type", Array)
], TilesComponent.prototype, "nodes", void 0);
tslib_1.__decorate([
(0, core_1.Input)(),
tslib_1.__metadata("design:type", Object)
], TilesComponent.prototype, "direction", void 0);
tslib_1.__decorate([
(0, core_1.HostBinding)("class"),
tslib_1.__metadata("design:type", String)
], TilesComponent.prototype, "elementClass", void 0);
tslib_1.__decorate([
(0, core_1.ViewChild)("gridItemsContainer", { static: true }),
tslib_1.__metadata("design:type", core_1.ElementRef)
], TilesComponent.prototype, "gridItemsContainer", void 0);
exports.TilesComponent = TilesComponent = tslib_1.__decorate([
(0, core_1.Component)({
selector: "nui-tiles",
styleUrls: ["./tiles.component.less"],
templateUrl: "./tiles.component.html",
standalone: false,
}),
tslib_1.__metadata("design:paramtypes", [core_1.ChangeDetectorRef,
pizzagna_service_1.PizzagnaService,
bits_1.LoggerService,
core_1.NgZone])
], TilesComponent);
/**
* Height to Width container ratio varies per tiles amount.
* Experimentally was determined valid h/w ratio for 2...8 tiles and
* This function represents the linear dependency (approximately).
*/
const getHeightToWidthRatioFor = (tilesAmount) => 0.25 * tilesAmount + 0.7;
//# sourceMappingURL=tiles.component.js.map