UNPKG

@itwin/presentation-hierarchies

Version:

A package for creating hierarchies based on data in iTwin.js iModels.

166 lines 8.53 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.HierarchyNodeKey = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const presentation_shared_1 = require("@itwin/presentation-shared"); /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare var HierarchyNodeKey; (function (HierarchyNodeKey) { /** Checks whether the given node key is a generic node key. */ function isGeneric(key) { return key.type === "generic"; } HierarchyNodeKey.isGeneric = isGeneric; /** Checks whether the given node key is a `StandardHierarchyNodeKey`. */ function isIModelNodeKey(key) { return !isGeneric(key); } HierarchyNodeKey.isIModelNodeKey = isIModelNodeKey; /** Checks whether the given node key is an `InstancesNodeKey`. */ function isInstances(key) { return key.type === "instances"; } HierarchyNodeKey.isInstances = isInstances; /** Checks whether the given node key is a `GroupingNodeKey`. */ function isGrouping(key) { return !isGeneric(key) && !isInstances(key); } HierarchyNodeKey.isGrouping = isGrouping; /** Checks whether the given node key is a `ClassGroupingNodeKey`. */ function isClassGrouping(key) { return key.type === "class-grouping"; } HierarchyNodeKey.isClassGrouping = isClassGrouping; /** Checks whether the given node key is a `LabelGroupingNodeKey`. */ function isLabelGrouping(key) { return key.type === "label-grouping"; } HierarchyNodeKey.isLabelGrouping = isLabelGrouping; /** Checks whether the given node key is a `PropertyOtherValuesGroupingNodeKey`. */ function isPropertyOtherValuesGrouping(key) { return key.type === "property-grouping:other"; } HierarchyNodeKey.isPropertyOtherValuesGrouping = isPropertyOtherValuesGrouping; /** Checks whether the given node key is a `PropertyValueRangeGroupingNodeKey`. */ function isPropertyValueRangeGrouping(key) { return key.type === "property-grouping:range"; } HierarchyNodeKey.isPropertyValueRangeGrouping = isPropertyValueRangeGrouping; /** Checks whether the given node key is a `PropertyValueGroupingNodeKey`. */ function isPropertyValueGrouping(key) { return key.type === "property-grouping:value"; } HierarchyNodeKey.isPropertyValueGrouping = isPropertyValueGrouping; /** Checks whether the given node key is a `PropertyGroupingNodeKey`. */ function isPropertyGrouping(key) { return isPropertyOtherValuesGrouping(key) || isPropertyValueRangeGrouping(key) || isPropertyValueGrouping(key); } HierarchyNodeKey.isPropertyGrouping = isPropertyGrouping; /** * Compares two given keys. Returns: * - `0` if they are equal, * - `negative value` if lhs key is less than rhs key, * - `positive value` if lhs key is more than rhs key. */ function compare(lhs, rhs) { const typeCompareResult = (0, core_bentley_1.compareStrings)(lhs.type, rhs.type); if (typeCompareResult !== 0) { return typeCompareResult; } switch (lhs.type) { case "generic": { (0, core_bentley_1.assert)(rhs.type === "generic"); const idCompareResult = (0, core_bentley_1.compareStrings)(lhs.id, rhs.id); if (idCompareResult !== 0) { return idCompareResult; } return (0, core_bentley_1.compareStringsOrUndefined)(lhs.source, rhs.source); } case "instances": { (0, core_bentley_1.assert)(rhs.type === "instances"); if (lhs.instanceKeys.length !== rhs.instanceKeys.length) { return lhs.instanceKeys.length > rhs.instanceKeys.length ? 1 : -1; } for (let i = 0; i < lhs.instanceKeys.length; ++i) { const instanceKeyCompareResult = presentation_shared_1.InstanceKey.compare(lhs.instanceKeys[i], rhs.instanceKeys[i]); if (instanceKeyCompareResult !== 0) { return instanceKeyCompareResult; } const imodelKeyCompareResult = (0, core_bentley_1.compareStringsOrUndefined)(lhs.instanceKeys[0].imodelKey, rhs.instanceKeys[0].imodelKey); if (imodelKeyCompareResult !== 0) { return imodelKeyCompareResult; } } return 0; } case "class-grouping": { (0, core_bentley_1.assert)(rhs.type === "class-grouping"); return (0, core_bentley_1.compareStrings)(lhs.className, rhs.className); } case "label-grouping": { (0, core_bentley_1.assert)(rhs.type === "label-grouping"); const labelCompareResult = (0, core_bentley_1.compareStrings)(lhs.label, rhs.label); if (labelCompareResult !== 0) { return labelCompareResult; } return (0, core_bentley_1.compareStringsOrUndefined)(lhs.groupId, rhs.groupId); } case "property-grouping:other": { (0, core_bentley_1.assert)(rhs.type === "property-grouping:other"); if (lhs.properties.length !== rhs.properties.length) { return lhs.properties.length - rhs.properties.length; } for (let i = 0; i < lhs.properties.length; ++i) { const classCompareResult = (0, core_bentley_1.compareStrings)(lhs.properties[i].className, rhs.properties[i].className); if (classCompareResult !== 0) { return classCompareResult; } const nameCompareResult = (0, core_bentley_1.compareStrings)(lhs.properties[i].propertyName, rhs.properties[i].propertyName); if (nameCompareResult !== 0) { return nameCompareResult; } } return 0; } case "property-grouping:value": { (0, core_bentley_1.assert)(rhs.type === "property-grouping:value"); const propertyClassNameCompareResult = (0, core_bentley_1.compareStrings)(lhs.propertyClassName, rhs.propertyClassName); if (propertyClassNameCompareResult !== 0) { return propertyClassNameCompareResult; } const propertyNameCompareResult = (0, core_bentley_1.compareStrings)(lhs.propertyName, rhs.propertyName); if (propertyNameCompareResult !== 0) { return propertyNameCompareResult; } return (0, core_bentley_1.compareStrings)(lhs.formattedPropertyValue, rhs.formattedPropertyValue); } case "property-grouping:range": { (0, core_bentley_1.assert)(rhs.type === "property-grouping:range"); const propertyClassNameCompareResult = (0, core_bentley_1.compareStrings)(lhs.propertyClassName, rhs.propertyClassName); if (propertyClassNameCompareResult !== 0) { return propertyClassNameCompareResult; } const propertyNameCompareResult = (0, core_bentley_1.compareStrings)(lhs.propertyName, rhs.propertyName); if (propertyNameCompareResult !== 0) { return propertyNameCompareResult; } if (lhs.fromValue !== rhs.fromValue) { return lhs.fromValue > rhs.fromValue ? 1 : -1; } return lhs.toValue > rhs.toValue ? 1 : lhs.toValue < rhs.toValue ? -1 : 0; } } } HierarchyNodeKey.compare = compare; /** Checks whether the two given keys are equal. */ function equals(lhs, rhs) { return compare(lhs, rhs) === 0; } HierarchyNodeKey.equals = equals; })(HierarchyNodeKey || (exports.HierarchyNodeKey = HierarchyNodeKey = {})); //# sourceMappingURL=HierarchyNodeKey.js.map