-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9950d11
commit bad2555
Showing
8 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
graylog2-web-interface/src/views/components/visualizations/utils/dataConvertor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* 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 | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import type { ConvertValueToUnit, ConversionParams } from 'hooks/useFieldUnitTypes'; | ||
import type SeriesUnit from 'views/logic/aggregationbuilder/SeriesUnit'; | ||
import type { MetricUnitType } from 'views/types'; | ||
|
||
const chartLayoutBaseUnitTypes: Record<MetricUnitType, string> = { | ||
size: 'b', | ||
percent: '%', | ||
time: 'ms', | ||
}; | ||
|
||
const dataConvertor = (values: Array<number>, convertValueToUnit: ConvertValueToUnit, unit: SeriesUnit) => { | ||
if (!unit.isDefined) return values; | ||
const from: ConversionParams = { abbrev: unit.abbrev, unitType: unit.unitType }; | ||
const to: ConversionParams = { abbrev: chartLayoutBaseUnitTypes[unit.unitType], unitType: unit.unitType }; | ||
|
||
const res = values.map((v) => { | ||
const converted = convertValueToUnit(v, from, to); | ||
console.log({ converted, v, from, to }); | ||
|
||
if (unit.unitType === 'time') return new Date(converted.value); | ||
|
||
return converted.value; | ||
}); | ||
|
||
console.log({ from, to, res }); | ||
|
||
return res; | ||
}; | ||
|
||
export default dataConvertor; |
21 changes: 21 additions & 0 deletions
21
graylog2-web-interface/src/views/components/visualizations/utils/getSeriesUnit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* 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 | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import type Series from 'views/logic/aggregationbuilder/Series'; | ||
|
||
const getSeriesUnit = (series: Array<Series>, seriesName: string) => series.find((s) => s.config.name === seriesName || s.function === seriesName).unit; | ||
|
||
export default getSeriesUnit; |