@neo4j-ndl/react-charts
Version:
React implementation of charts from Neo4j Design System
106 lines • 3.93 kB
JavaScript
/**
*
* 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/>.
*/
import { defaultThresholdLineSeriesOption } from './defaults';
export const isThresholdLine = (name) => name === null || name === void 0 ? void 0 : name.startsWith('thresholdLine');
export const getThresholdLineDisplayName = (name) => name.replace('thresholdLine-', '');
/**
* Extracts threshold-line series and resolves defaults needed by tooltips.
*/
export 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 : defaultThresholdLineSeriesOption.condition, value: currentThresholdLineSeriesOption.yAxis });
});
}
/**
* Evaluates a threshold condition and returns the short label used by
* chart tooltip notifications.
*/
export 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.
*/
export 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