mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 19:17:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { format } from 'd3-format';
|
|
import { mean } from 'd3-array';
|
|
|
|
// COLOR THEME:
|
|
export const LIGHT_AND_DARK_BLUE = ['#BFD4FF', '#1563FF'];
|
|
export const UPGRADE_WARNING = '#FDEEBA';
|
|
export const BAR_COLOR_HOVER = ['#1563FF', '#0F4FD1'];
|
|
export const GREY = '#EBEEF2';
|
|
|
|
// TRANSLATIONS:
|
|
export const TRANSLATE = { left: -11 };
|
|
export const SVG_DIMENSIONS = { height: 190, width: 500 };
|
|
|
|
// Reference for tickFormat https://www.youtube.com/watch?v=c3MCROTNN8g
|
|
export function formatNumbers(number) {
|
|
if (number < 1000) return number;
|
|
if (number < 10000) return format('.1s')(number);
|
|
// replace SI prefix of 'G' for billions to 'B'
|
|
return format('.2s')(number).replace('G', 'B');
|
|
}
|
|
|
|
export function formatTooltipNumber(value) {
|
|
if (typeof value !== 'number') {
|
|
return value;
|
|
}
|
|
// formats a number according to the locale
|
|
return new Intl.NumberFormat().format(value);
|
|
}
|
|
|
|
export function calculateAverage(dataset, objectKey) {
|
|
// before mapping for values, check that the objectKey exists at least once in the dataset because
|
|
// map returns 0 when dataset[objectKey] is undefined in order to calculate average
|
|
if (!Array.isArray(dataset) || !objectKey || !dataset.some((d) => Object.keys(d).includes(objectKey))) {
|
|
return null;
|
|
}
|
|
|
|
const integers = dataset.map((d) => (d[objectKey] ? d[objectKey] : 0));
|
|
const checkIntegers = integers.every((n) => Number.isInteger(n)); // decimals will be false
|
|
return checkIntegers ? Math.round(mean(integers)) : null;
|
|
}
|