-
Notifications
You must be signed in to change notification settings - Fork 99
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
Destructured visMetaData and dataConfig Objects in all visualizations #1106
Changes from all commits
412c48c
662b3b9
95fef81
00f88cf
50fbaed
a706333
9541963
e3318cf
e07a83e
55844c4
676675e
0ebc010
e71e35f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
font-size: 20px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ import { find, isEmpty, last, some } from 'lodash'; | |
import React, { useMemo } from 'react'; | ||
import { | ||
AGGREGATIONS, | ||
DEFAULT_BAR_CHART_STYLES, | ||
BREAKDOWNS, | ||
DEFAULT_BAR_CHART_STYLES, | ||
GROUPBY, | ||
} from '../../../../../common/constants/explorer'; | ||
import { | ||
|
@@ -37,36 +37,61 @@ export const Bar = ({ visualizations, layout, config }: any) => { | |
data: queriedVizData, | ||
metadata: { fields }, | ||
}, | ||
userConfigs, | ||
userConfigs: { | ||
dataConfig: { | ||
colorTheme = [], | ||
chartStyles = {}, | ||
span = {}, | ||
legend = {}, | ||
panelOptions = {}, | ||
[GROUPBY]: dimensions = [], | ||
[AGGREGATIONS]: series = [], | ||
[BREAKDOWNS]: breakdowns = [], | ||
} = {}, | ||
layoutConfig = {}, | ||
availabilityConfig = {}, | ||
}, | ||
}, | ||
vis: { | ||
type, | ||
icontype, | ||
fillopacity, | ||
orientation, | ||
labelangle, | ||
linewidth, | ||
barwidth, | ||
groupwidth, | ||
showlegend, | ||
legendposition, | ||
}, | ||
vis: visMetaData, | ||
}: IVisualizationContainerProps = visualizations; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could destruct visMetaData at line 30 directly without renaming. Please apply this code review to all other charts that have this similar problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @mengweieric, this is already taken care, can you please check once https://github.com/opensearch-project/observability/pull/1106/files (commit id: 95fef81) |
||
const lastIndex = fields.length - 1; | ||
const { dataConfig = {}, layoutConfig = {}, availabilityConfig = {} } = userConfigs; | ||
|
||
/** | ||
* determine stylings | ||
*/ | ||
const barOrientation = dataConfig.chartStyles?.orientation || visMetaData.orientation; | ||
const barOrientation = chartStyles.orientation || orientation; | ||
const isVertical = barOrientation === BarOrientation.vertical; | ||
|
||
const tickAngle = dataConfig?.chartStyles?.rotateBarLabels || visMetaData.labelangle; | ||
const lineWidth = dataConfig?.chartStyles?.lineWidth || visMetaData.linewidth; | ||
const tickAngle = chartStyles.rotateBarLabels || labelangle; | ||
const lineWidth = chartStyles.lineWidth || linewidth; | ||
const fillOpacity = | ||
dataConfig?.chartStyles?.fillOpacity !== undefined | ||
? dataConfig?.chartStyles?.fillOpacity / FILLOPACITY_DIV_FACTOR | ||
: visMetaData.fillopacity / FILLOPACITY_DIV_FACTOR; | ||
const barWidth = 1 - (dataConfig?.chartStyles?.barWidth || visMetaData.barwidth); | ||
const groupWidth = 1 - (dataConfig?.chartStyles?.groupWidth || visMetaData.groupwidth); | ||
const showLegend = !( | ||
dataConfig?.legend?.showLegend && dataConfig.legend.showLegend !== visMetaData.showlegend | ||
); | ||
const legendPosition = dataConfig?.legend?.position || visMetaData.legendposition; | ||
const labelSize = dataConfig?.chartStyles?.labelSize || DEFAULT_BAR_CHART_STYLES.LabelSize; | ||
const legendSize = dataConfig?.legend?.legendSize; | ||
chartStyles.fillOpacity !== undefined | ||
? chartStyles.fillOpacity / FILLOPACITY_DIV_FACTOR | ||
: fillopacity / FILLOPACITY_DIV_FACTOR; | ||
const barWidth = 1 - (chartStyles.barWidth || barwidth); | ||
const groupWidth = 1 - (chartStyles.groupWidth || groupwidth); | ||
const showLegend = !(legend.showLegend && legend.showLegend !== showlegend); | ||
const legendPosition = legend.position || legendposition; | ||
|
||
visualizations.data?.rawVizData?.dataConfig?.metrics | ||
? visualizations.data.rawVizData.dataConfig.metrics | ||
: []; | ||
const labelSize = chartStyles.labelSize || DEFAULT_BAR_CHART_STYLES.LabelSize; | ||
const legendSize = legend.legendSize; | ||
const getSelectedColorTheme = (field: any, index: number) => | ||
(dataConfig?.colorTheme?.length > 0 && | ||
dataConfig.colorTheme.find((colorSelected) => colorSelected.name.name === field)?.color) || | ||
(colorTheme.length > 0 && | ||
colorTheme.find((colorSelected) => colorSelected.name.name === field.label)?.color) || | ||
PLOTLY_COLOR[index % PLOTLY_COLOR.length]; | ||
|
||
let bars; | ||
|
@@ -76,30 +101,29 @@ export const Bar = ({ visualizations, layout, config }: any) => { | |
*/ | ||
const xaxes = useMemo(() => { | ||
// breakdown selections | ||
if (dataConfig[BREAKDOWNS]) { | ||
if (breakdowns) { | ||
return [ | ||
...dataConfig[GROUPBY].filter( | ||
(dimension) => | ||
!some(dataConfig[BREAKDOWNS], (breakdown) => breakdown.label === dimension.label) | ||
...dimensions.filter( | ||
(dimension) => !some(breakdowns, (breakdown) => breakdown.label === dimension.label) | ||
), | ||
]; | ||
} | ||
|
||
// span selection | ||
const timestampField = find(fields, (field) => field.type === 'timestamp'); | ||
if (dataConfig.span && dataConfig.span.time_field && timestampField) { | ||
return [timestampField, ...dataConfig[GROUPBY]]; | ||
if (span && span.time_field && timestampField) { | ||
return [timestampField, ...dimensions]; | ||
} | ||
|
||
return dataConfig[GROUPBY]; | ||
}, [dataConfig[GROUPBY], dataConfig[BREAKDOWNS]]); | ||
return [...dimensions]; | ||
}, [dimensions, breakdowns]); | ||
|
||
/** | ||
* determine y axis | ||
*/ | ||
const yaxes = useMemo(() => { | ||
return Array.isArray(dataConfig[AGGREGATIONS]) ? [...dataConfig[AGGREGATIONS]] : []; | ||
}, [dataConfig[AGGREGATIONS]]); | ||
return Array.isArray(series) ? [...series] : []; | ||
}, [series]); | ||
|
||
/** | ||
* prepare data for visualization, map x-xais to y-xais | ||
|
@@ -124,7 +148,7 @@ export const Bar = ({ visualizations, layout, config }: any) => { | |
return { | ||
y: isVertical ? queriedVizData[getPropName(yMetric)] : chartAxis, | ||
x: isVertical ? chartAxis : queriedVizData[getPropName(yMetric)], | ||
type: visMetaData.type, | ||
type: type, | ||
marker: { | ||
color: fillColor, | ||
line: { | ||
|
@@ -139,12 +163,12 @@ export const Bar = ({ visualizations, layout, config }: any) => { | |
|
||
if ( | ||
isEmpty(queriedVizData) || | ||
!Array.isArray(dataConfig[GROUPBY]) || | ||
!Array.isArray(dataConfig[AGGREGATIONS]) || | ||
(dataConfig[BREAKDOWNS] && !Array.isArray(dataConfig[BREAKDOWNS])) || | ||
!Array.isArray(dimensions) || | ||
!Array.isArray(series) || | ||
(breakdowns && !Array.isArray(breakdowns)) || | ||
yaxes.length === 0 | ||
) | ||
return <EmptyPlaceholder icon={visMetaData?.icontype} />; | ||
return <EmptyPlaceholder icon={icontype} />; | ||
|
||
// If chart has length of result buckets < 16 | ||
// then use the LONG_CHART_COLOR for all the bars in the chart | ||
|
@@ -155,8 +179,8 @@ export const Bar = ({ visualizations, layout, config }: any) => { | |
colorway: plotlyColorway, | ||
...layout, | ||
...(layoutConfig.layout && layoutConfig.layout), | ||
title: dataConfig?.panelOptions?.title || layoutConfig.layout?.title || '', | ||
barmode: dataConfig?.chartStyles?.mode || visualizations.vis.mode, | ||
title: panelOptions.title || layoutConfig.layout?.title || '', | ||
barmode: chartStyles.mode || visualizations.vis.mode, | ||
xaxis: { | ||
...(isVertical && { tickangle: tickAngle }), | ||
automargin: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take look at reviews from previous PRs and having one more reviewer internally to review to avoid spending effort reviewing the same issues? Previously we've reviewed some similar code already like this, below code piece can be further simplified as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mengweieric Sure, will ensure in next PRs that such small issues can be addressed internally.