Skip to content

Commit

Permalink
Merge pull request #1202 from AndyFong/dev-0.3
Browse files Browse the repository at this point in the history
fix(Widget): Bar&Line Label format error when exists Color items
#1017 
#848
  • Loading branch information
scottsut authored Sep 10, 2019
2 parents 1870f00 + ecdc868 commit cffc436
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions webapp/app/containers/Widget/render/chart/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

import { IChartProps } from '../../components/Chart'
import { DEFAULT_SPLITER } from 'app/globalConstants'
import {
IFieldFormatConfig,
getFormattedValue,
Expand Down Expand Up @@ -81,8 +82,8 @@ export default function (chartProps: IChartProps, drillOptions) {
label: {
...getLabelOption('bar', label, metrics, false, {
formatter: (params) => {
const { value, seriesName } = params
const m = metrics.find((m) => decodeMetricName(m.name) === seriesName)
const { value, seriesId } = params
const m = metrics.find((m) => m.name === seriesId.split(`${DEFAULT_SPLITER}${DEFAULT_SPLITER}`)[0])
let format: IFieldFormatConfig = m.format
let formattedValue = value
if (percentage) {
Expand Down Expand Up @@ -148,6 +149,7 @@ export default function (chartProps: IChartProps, drillOptions) {

Object.entries(grouped).forEach(([k, v]: [string, any[]]) => {
const serieObj = {
id: `${m.name}${DEFAULT_SPLITER}${DEFAULT_SPLITER}${k}`,
name: `${k} ${localeMetricName}`,
type: 'bar',
...stackOption,
Expand Down Expand Up @@ -207,6 +209,7 @@ export default function (chartProps: IChartProps, drillOptions) {
})
} else {
const serieObj = {
id: m.name,
name: decodedMetricName,
type: 'bar',
...stackOption,
Expand Down
3 changes: 3 additions & 0 deletions webapp/app/containers/Widget/render/chart/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

import { IChartProps } from '../../components/Chart'
import { DEFAULT_SPLITER } from 'app/globalConstants'
import {
decodeMetricName,
getChartTooltipLabel,
Expand Down Expand Up @@ -86,6 +87,7 @@ export default function (chartProps: IChartProps, drillOptions?: any) {
if (color.items.length) {
Object.entries(grouped).forEach(([k, v]: [string, any[]]) => {
const serieObj = {
id: `${m.name}${DEFAULT_SPLITER}${DEFAULT_SPLITER}${k}`,
name: `${k} ${localeMetricName}`,
type: 'line',
sampling: 'average',
Expand Down Expand Up @@ -136,6 +138,7 @@ export default function (chartProps: IChartProps, drillOptions?: any) {
})
} else {
const serieObj = {
id: m.name,
name: decodedMetricName,
type: 'line',
sampling: 'average',
Expand Down
6 changes: 3 additions & 3 deletions webapp/app/containers/Widget/render/chart/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ILabelConfig } from '../../components/Workbench/ConfigSections/LabelSec
import { ILegendConfig } from '../../components/Workbench/ConfigSections/LegendSection'
import { metricAxisLabelFormatter, decodeMetricName, getTextWidth } from '../../components/util'
import { getFormattedValue } from '../../components/Config/Format'
import { CHART_LEGEND_POSITIONS } from 'app/globalConstants'
import { CHART_LEGEND_POSITIONS, DEFAULT_SPLITER } from 'app/globalConstants'
import { EChartOption } from 'echarts'

interface ISplitLineConfig {
Expand Down Expand Up @@ -216,8 +216,8 @@ export function getLabelOption (type: string, labelConfig: ILabelConfig, metrics
switch (type) {
case 'line':
formatter = (params) => {
const { value, seriesName } = params
const m = metrics.find((m) => decodeMetricName(m.name) === seriesName)
const { value, seriesId } = params
const m = metrics.find((m) => m.name === seriesId.split(`${DEFAULT_SPLITER}${DEFAULT_SPLITER}`)[0])
const formattedValue = getFormattedValue(value, m.format)
return formattedValue
}
Expand Down

0 comments on commit cffc436

Please sign in to comment.