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: 🐛 修复globalFilters与数据类型不匹配 #2215

Open
wants to merge 5 commits into
base: dev-0.3
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions webapp/app/containers/Dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ export interface IQueryVariableMap {
[key: string]: string | number
}

export interface IGlobalFiltersItem {
name: string,
value: string,
operator: string,
sqlType: string,
type: string
}

export interface IQueryConditions {
tempFilters: string[] // @TODO combine widget static filters with local filters
linkageFilters: string[]
globalFilters: string[]
globalFilters: IGlobalFiltersItem[]
variables: QueryVariable
linkageVariables: QueryVariable
globalVariables: QueryVariable
Expand All @@ -104,7 +112,7 @@ export interface IDataRequestParams {
filters: string[]
tempFilters: string[]
linkageFilters: string[]
globalFilters: string[]
globalFilters: IGlobalFiltersItem[]
variables: QueryVariable
linkageVariables: QueryVariable
globalVariables: QueryVariable
Expand Down
8 changes: 7 additions & 1 deletion webapp/app/containers/Widget/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class Chart extends React.PureComponent<IChartProps, IChartStates> {
renderType,
getDataDrillDetail,
isDrilling,
onError
onError,
queryVariables
} = props

if (renderType === 'loading') {
Expand Down Expand Up @@ -65,6 +66,7 @@ export class Chart extends React.PureComponent<IChartProps, IChartStates> {
instance: this.instance,
isDrilling,
getDataDrillDetail,
queryVariables,
selectedItems: this.props.selectedItems,
callback: (seriesData) => {
this.instance.off('click')
Expand Down Expand Up @@ -144,6 +146,10 @@ export class Chart extends React.PureComponent<IChartProps, IChartStates> {
const seriesIndex = series[index] ? series[index].split('&')[0] : null
return seriesData[seriesIndex] ? seriesData[seriesIndex][item] : []
}
// 当是地图的时候,获取正确的数据用来关联其他widget
if (selectedChart === 7 && params?.data.originIndex != undefined) {
return data[params.data.originIndex]
}
return data[item]
})
const brushed = [{ 0: Object.values(resultData) }]
Expand Down
17 changes: 15 additions & 2 deletions webapp/app/containers/Widget/components/Pivot/ColumnTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { getPivotCellWidth, getPivot, getStyleConfig } from '../util'

const styles = require('./Pivot.less')

interface IColProps {
name: string,
alias: string
}

interface IColumnTitleProps {
cols: string[]
cols: IColProps[]
colKeys: string[][]
colTree: object
chartStyles: IChartStyles
Expand All @@ -19,6 +24,14 @@ export function ColumnTitle (props: IColumnTitleProps) {
const { elementSize, unitMetricWidth } = drawingData
const { color: fontColor } = getStyleConfig(chartStyles).pivot

const content = cols.map(col => {
if (col.alias) {
return col.alias
} else {
return col.name
}
})

let tableWidth = 0

if (dimetionAxis) {
Expand All @@ -37,7 +50,7 @@ export function ColumnTitle (props: IColumnTitleProps) {
color: fontColor
}}
>
{cols.join(` / `)}
{content.join(` / `)}
</div>
)
}
Expand Down
6 changes: 4 additions & 2 deletions webapp/app/containers/Widget/components/Pivot/Pivot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ export class Pivot extends React.PureComponent<IPivotProps, IPivotStates> {
const { legendSelected, renderType } = this.state
const rowNames = rows.map((r) => r.name)
const colNames = cols.map((c) => c.name)
const colNamesWithAlias = cols.map((c) => ({ name: c.name, alias: c.field.alias }))
const rowNamesWithAlias = rows.map(r => ({ name: r.name, alias: r.field.alias }))
const hasMetricNameDimension = [rows, cols].some((items) => items.findIndex((item) => item.name === '指标名称') >= 0)

return (
Expand All @@ -603,7 +605,7 @@ export class Pivot extends React.PureComponent<IPivotProps, IPivotStates> {
/>
<div className={styles.rowHeader}>
<RowTitle
rows={rowNames}
rows={rowNamesWithAlias}
rowKeys={this.rowKeys}
chartStyles={chartStyles}
drawingData={this.drawingData}
Expand All @@ -630,7 +632,7 @@ export class Pivot extends React.PureComponent<IPivotProps, IPivotStates> {
</div>
<div className={styles.rightSide}>
<ColumnTitle
cols={colNames}
cols={colNamesWithAlias}
colKeys={this.colKeys}
colTree={this.colTree}
chartStyles={chartStyles}
Expand Down
17 changes: 15 additions & 2 deletions webapp/app/containers/Widget/components/Pivot/RowTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { getPivotContentTextWidth, getPivotCellHeight, getPivot, getStyleConfig

const styles = require('./Pivot.less')

interface IRowProps {
name: string,
alias: string
}

interface IRowTitleProps {
rows: string[]
rows: IRowProps[]
rowKeys: string[][]
chartStyles: IChartStyles
drawingData: IDrawingData
Expand All @@ -27,7 +32,15 @@ export function RowTitle (props: IRowTitleProps) {
tableHeight = rowKeys.length * getPivotCellHeight()
}

const content = rows.join(` / `)
const content = rows
.map(row => {
if (row.alias) {
return row.alias
} else {
return row.name
}
})
.join(` / `)
const contentLength = getPivotContentTextWidth(content)

return (
Expand Down
6 changes: 3 additions & 3 deletions webapp/app/containers/Widget/components/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ export function getPivotTooltipLabel(
}

export function getChartTooltipLabel(type, seriesData, options) {
const { cols, metrics, color, size, scatterXAxis, tip } = options
const { cols, metrics, color, size, scatterXAxis, tip, queryVariables = {} } = options
let dimentionColumns: any[] = cols
let metricColumns = [...metrics]
if (color) {
Expand Down Expand Up @@ -777,7 +777,7 @@ export function getChartTooltipLabel(type, seriesData, options) {
: record[dc.name]
: ''
value = getFormattedValue(value, dc.format)
return `${getFieldAlias(dc.field, {}) || dc.name}: ${value}` // @FIXME dynamic field alias by queryVariable in dashboard
return `${getFieldAlias(dc.field, queryVariables) || dc.name}: ${value}` // @FIXME dynamic field alias by queryVariable in dashboard
})
)

Expand All @@ -793,7 +793,7 @@ export function getChartTooltipLabel(type, seriesData, options) {
: record[`${mc.agg}(${decodedName})`]
: 0
value = getFormattedValue(value, mc.format)
return `${getFieldAlias(mc.field, {}) || decodedName}: ${value}`
return `${getFieldAlias(mc.field, queryVariables) || decodedName}: ${value}`
})
)

Expand Down
5 changes: 3 additions & 2 deletions webapp/app/containers/Widget/render/chart/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const defaultTheme = require('assets/json/echartsThemes/default.project.json')
const defaultThemeColors = defaultTheme.theme.color

export default function (chartProps: IChartProps, drillOptions?: any) {
const { data, cols, chartStyles, color, tip, references } = chartProps
const { data, cols, chartStyles, color, tip, references, queryVariables } = chartProps
const metrics = getCartesianChartMetrics(chartProps.metrics)
const { spec, xAxis, yAxis, splitLine, label, legend } = chartStyles

Expand Down Expand Up @@ -255,7 +255,8 @@ export default function (chartProps: IChartProps, drillOptions?: any) {
cols,
metrics,
color,
tip
tip,
queryVariables
})
},
legend: getLegendOption(legend, seriesNames),
Expand Down
14 changes: 10 additions & 4 deletions webapp/app/containers/Widget/render/chart/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function (chartProps: IChartProps) {
const agg = metrics[0].agg
const metricName = decodeMetricName(metrics[0].name)

data.forEach((record) => {
data.forEach((record, index) => {
let areaVal
const group = []

Expand All @@ -135,6 +135,7 @@ export default function (chartProps: IChartProps) {
dataTree[provinceName] = {
lon: area.lon,
lat: area.lat,
originIndex: index,
value,
children: {}
}
Expand All @@ -151,6 +152,7 @@ export default function (chartProps: IChartProps) {
dataTree[parentName] = {
lon: area.lon,
lat: area.lat,
originIndex: index,
value: 0,
children: {}
}
Expand All @@ -161,6 +163,7 @@ export default function (chartProps: IChartProps) {
dataTree[areaVal] = {
lon: area.lon,
lat: area.lat,
originIndex: index,
value,
children: {}
}
Expand Down Expand Up @@ -200,9 +203,10 @@ export default function (chartProps: IChartProps) {
mapType: 'china',
roam,
data: Object.keys(dataTree).map((key, index) => {
const { lon, lat, value } = dataTree[key]
const { lon, lat, value, originIndex } = dataTree[key]
return {
name: key,
originIndex,
value: [lon, lat, value]
}
}),
Expand All @@ -215,9 +219,10 @@ export default function (chartProps: IChartProps) {
type: 'scatter',
coordinateSystem: 'geo',
data: Object.keys(dataTree).map((key, index) => {
const { lon, lat, value } = dataTree[key]
const { lon, lat, value, originIndex } = dataTree[key]
return {
name: key,
originIndex,
value: [lon, lat, value],
symbolSize: getSymbolSize(sizeRate, value) / 2
}
Expand All @@ -232,9 +237,10 @@ export default function (chartProps: IChartProps) {
type: 'heatmap',
coordinateSystem: 'geo',
data: Object.keys(dataTree).map((key, index) => {
const { lon, lat, value } = dataTree[key]
const { lon, lat, value, originIndex } = dataTree[key]
return {
name: key,
originIndex,
value: [lon, lat, value],
symbolSize: getSymbolSize(sizeRate, value) / 2
}
Expand Down