Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix data formatter of metric data table #3691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions apps/web/src/common/composables/amcharts5/tree-map-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type * as am5 from '@amcharts/amcharts5';
import { Percent } from '@amcharts/amcharts5';
import * as am5hierarchy from '@amcharts/amcharts5/hierarchy';

import { numberFormatter } from '@cloudforet/utils';


export const createTreeMapSeries = (
root: am5.Root,
Expand All @@ -15,7 +13,7 @@ export const createTreeMapSeries = (
...settings,
}));

export const setTreemapTooltipText = (series: am5hierarchy.Treemap, tooltip: am5.Tooltip): void => {
export const setTreemapTooltipText = (series: am5hierarchy.Treemap, tooltip: am5.Tooltip, valueFormatter?: (value: any, data?: any) => string): void => {
tooltip.label.setAll({
fontSize: 14,
});
Expand All @@ -24,8 +22,8 @@ export const setTreemapTooltipText = (series: am5hierarchy.Treemap, tooltip: am5

tooltip.label.adapters.add('text', (_, target) => {
const colorValue = target.dataItem?.dataContext?.[colorFieldName] || 'black';
const value = target.dataItem?.dataContext?.[valueFieldName] || '-';
const formatted = numberFormatter(value, { minimumFractionDigits: 2 });
const value = target.dataItem?.dataContext?.[valueFieldName] || '--';
const formatted = valueFormatter ? valueFormatter(value, target.dataItem?.dataContext) : value;
return `[${colorValue}; fontSize: 10px]●[/] {category}: [bold]${formatted}[/] ({valuePercentTotal.formatNumber("0.00")}%)`;
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
import type * as am5xy from '@amcharts/amcharts5/xy';
import { cloneDeep } from 'lodash';

import { numberFormatter } from '@cloudforet/utils';

import { useAmcharts5 } from '@/common/composables/amcharts5';
import {
setXYSharedTooltipText,
Expand Down Expand Up @@ -60,8 +58,7 @@ const drawChart = () => {

// set tooltip if showPassFindings is true
const tooltip = chartHelper.createTooltip();
const _tooltipValueFormatter = (value?: number): string => numberFormatter(value, { minimumFractionDigits: 2 }) ?? '';
setXYSharedTooltipText(chart, tooltip, _tooltipValueFormatter);
setXYSharedTooltipText(chart, tooltip);
series.set('tooltip', tooltip);

// add series to chart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ export const getRefinedMetricExplorerTableData = (results: MetricDataAnalyzeResu
const refinedTableData: MetricDataAnalyzeResult[] = [];

if (realtimeDate) {
_results.forEach((d) => {
refinedTableData.push({
...d,
count: [
{
date: realtimeDate,
value: d.count,
},
],
_results
.filter((d) => d.date === realtimeDate)
.forEach((d) => {
refinedTableData.push({
...d,
count: [
{
date: realtimeDate,
value: d.count,
},
],
});
});
});
return refinedTableData;
}
const today = dayjs.utc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PDataLoader } from '@spaceone/design-system';
import { SpaceConnector } from '@cloudforet/core-lib/space-connector';
import { getCancellableFetcher } from '@cloudforet/core-lib/space-connector/cancallable-fetcher';
import { ApiQueryHelper } from '@cloudforet/core-lib/space-connector/helper';
import { numberFormatter } from '@cloudforet/utils';

import { WIDGET_SIZE } from '@/schema/dashboard/_constants/widget-constant';
import type { CostDataField } from '@/schema/dashboard/_types/widget-type';
Expand Down Expand Up @@ -102,7 +103,8 @@ const drawChart = (chartData: TreemapChartData[]) => {

const tooltip = chartHelper.createTooltip();
series.set('tooltip', tooltip);
chartHelper.setTreemapTooltipText(series, tooltip);
const valueFormatter = (val) => numberFormatter(val, { minimumFractionDigits: 2 }) as string;
chartHelper.setTreemapTooltipText(series, tooltip, valueFormatter);
chartHelper.setTreemapLabelText(series, {
oversizedBehavior: 'truncate',
});
Expand Down
Loading