UNPKG

@neo4j-ndl/react-charts

Version:

React implementation of charts from Neo4j Design System

114 lines 4.33 kB
"use strict"; /** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getThresholdLineDisplayName = exports.isThresholdLine = void 0; exports.normalizeThresholdLines = normalizeThresholdLines; exports.evaluateThresholdCondition = evaluateThresholdCondition; exports.thresholdConditionToText = thresholdConditionToText; const defaults_1 = require("./defaults"); const isThresholdLine = (name) => name === null || name === void 0 ? void 0 : name.startsWith('thresholdLine'); exports.isThresholdLine = isThresholdLine; const getThresholdLineDisplayName = (name) => name.replace('thresholdLine-', ''); exports.getThresholdLineDisplayName = getThresholdLineDisplayName; /** * Extracts threshold-line series and resolves defaults needed by tooltips. */ function normalizeThresholdLines(propsSeries) { const seriesArray = Array.isArray(propsSeries) ? propsSeries : [propsSeries]; const thresholdLineSeries = seriesArray.filter((currentSeries) => { return currentSeries.type === 'thresholdLine'; }); return thresholdLineSeries.map((currentThresholdLineSeriesOption) => { var _a; return Object.assign(Object.assign({}, currentThresholdLineSeriesOption), { condition: (_a = currentThresholdLineSeriesOption.condition) !== null && _a !== void 0 ? _a : defaults_1.defaultThresholdLineSeriesOption.condition, value: currentThresholdLineSeriesOption.yAxis }); }); } /** * Evaluates a threshold condition and returns the short label used by * chart tooltip notifications. */ function evaluateThresholdCondition(value, condition, threshold) { switch (condition) { case 'greater': return { conditionText: 'Above', isConditionMet: value > threshold, }; case 'greaterOrEqual': return { conditionText: value > threshold ? 'Above' : value === threshold ? 'Equal' : undefined, isConditionMet: value >= threshold, }; case 'less': return { conditionText: 'Below', isConditionMet: value < threshold, }; case 'lessOrEqual': return { conditionText: value < threshold ? 'Below' : value === threshold ? 'Equal' : undefined, isConditionMet: value <= threshold, }; case 'equal': return { conditionText: 'Equal', isConditionMet: value === threshold, }; case 'notEqual': return { conditionText: 'Not equal', isConditionMet: value !== threshold, }; default: return { conditionText: undefined, isConditionMet: false }; } } /** * Returns the longer condition phrase used in chart aria descriptions. */ function thresholdConditionToText(condition) { switch (condition) { case 'greater': return 'greater than'; case 'greaterOrEqual': return 'greater than or equal to'; case 'less': return 'less than'; case 'lessOrEqual': return 'less than or equal to'; case 'equal': return 'equal to'; case 'notEqual': return 'not equal to'; default: return 'compared to'; } } //# sourceMappingURL=threshold.js.map