Skip to content

Commit

Permalink
[front]getFormattedValue(#7921)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelineSebe committed Sep 18, 2024
1 parent 67f73c8 commit 3f0773a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ApexOptions } from 'apexcharts';
import { horizontalBarsChartOptions } from '../../utils/Charts';
import { simpleNumberFormat } from '../../utils/Number';
import type { Theme } from '../Theme';
import { dateFormat, timestamp } from '../../utils/Time';

interface WidgetHorizontalBarsProps {
series: ApexAxisChartSeries
Expand Down Expand Up @@ -36,13 +37,27 @@ const WidgetHorizontalBars = ({
const theme = useTheme<Theme>();
const navigate = useNavigate();

const getFormattedValue = (value: any) => {
if (typeof value === 'number') {
simpleNumberFormat(value);
}
const timestampInMs = parseInt(value, 10);

if (!Number.isNaN(timestampInMs)) {
const convertedDate = timestamp(timestampInMs);
const date = dateFormat(convertedDate, 'DD-MM-YYYY');
if (date) return date;
}
return value;
};

return (
<Chart
options={horizontalBarsChartOptions(
theme,
true,
simpleNumberFormat,
simpleNumberFormat,
getFormattedValue,
distributed,
navigate,
redirectionUtils,
Expand Down
13 changes: 1 addition & 12 deletions opencti-platform/opencti-front/src/utils/Charts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as C from '@mui/material/colors';
import { resolveLink } from './Entity';
import { truncate } from './String';
import { dateFormat, timestamp } from './Time';

const colors = (temp) => [
C.red[temp],
Expand Down Expand Up @@ -526,17 +525,7 @@ export const horizontalBarsChartOptions = (
show: stackType !== '100%',
labels: {
show: stackType !== '100%',
formatter: (value) => {
if (yFormatter && typeof value === 'number') {
return yFormatter(value);
}
if (typeof value === 'string' && value.length === 15) {
const timestampInMs = parseInt(value, 10);
const convertedDate = timestamp(timestampInMs);
return dateFormat(convertedDate, 'DD-MM-YYYY');
}
return value;
},
formatter: (value) => (yFormatter ? yFormatter(value) : value),
style: {
fontFamily: '"IBM Plex Sans", sans-serif',
},
Expand Down

0 comments on commit 3f0773a

Please sign in to comment.