Skip to content

Commit bce5424

Browse files
修复直方图offset模式下不展示问题 (#1165)
* type * 🐞 fix: 修复profiler trace页面 Co-authored-by: chenjian <chenjian26@baidu.com>
1 parent 56969d9 commit bce5424

File tree

4 files changed

+244
-251
lines changed

4 files changed

+244
-251
lines changed

frontend/packages/core/snowpack.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function isWorkspace() {
3737
const iconsPath = path.dirname(resolve.sync(cwd, '@visualdl/icons'));
3838
const netronPath = path.dirname(resolve.sync(cwd, '@visualdl/netron'));
3939
const netronPath2 = path.dirname(resolve.sync(cwd, '@visualdl/netron2'));
40-
40+
const TracePath = path.dirname(resolve.sync(cwd, './public/static'));
4141
const wasmPath = path.dirname(resolve.sync(cwd, '@visualdl/wasm'));
4242
const dest = path.resolve(cwd, './dist/__snowpack__/link/packages');
4343

@@ -102,6 +102,10 @@ export default {
102102
source: [path.join(netronPath2, '**/*')],
103103
destination: path.join(dest, 'netron2/dist')
104104
},
105+
{
106+
source: [path.join(TracePath, '**/*')],
107+
destination: path.join(dest, 'trace/dist')
108+
},
105109
{
106110
source: [path.join(wasmPath, '*.{js,wasm}')],
107111
destination: path.join(dest, 'wasm/dist')

frontend/packages/core/src/components/StackChart.tsx

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@
1818

1919
import * as chart from '~/utils/chart';
2020

21-
import type {
22-
EChartsOption,
23-
ECharts,
24-
CustomSeriesOption,
25-
CustomSeriesRenderItem,
26-
AxisPointerComponentOption,
27-
TooltipComponentOption,
28-
GridComponentOption,
29-
Color as ZRColor
30-
} from 'echarts';
21+
import type {EChartsOption as EChartOption, ECharts} from 'echarts';
3122
import React, {useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
3223
import {WithStyled, primaryColor, transitionProps} from '~/utils/style';
3324
import useECharts, {Options, Wrapper, useChartTheme} from '~/hooks/useECharts';
@@ -36,7 +27,6 @@ import GridLoader from 'react-spinners/GridLoader';
3627
import defaultsDeep from 'lodash/defaultsDeep';
3728
import styled from 'styled-components';
3829
import useThrottleFn from '~/hooks/useThrottleFn';
39-
import type {LinesSeriesOption} from 'echarts/charts';
4030

4131
const Tooltip = styled.div`
4232
position: absolute;
@@ -48,14 +38,23 @@ const Tooltip = styled.div`
4838
display: none;
4939
${transitionProps(['color', 'background-color'])}
5040
`;
51-
52-
type RenderItem = CustomSeriesRenderItem;
41+
// type RenderItem = EChartOption.SeriesCustom.RenderItem;
42+
type RenderItem = any;
5343
type GetValue = (i: number) => number;
5444
type GetCoord = (p: [number, number]) => [number, number];
5545

5646
export type StackChartProps = {
57-
options?: EChartsOption;
47+
options?: EChartOption;
5848
title?: string;
49+
// data?: Partial<Omit<NonNullable<EChartOption<EChartOption.SeriesCustom>['series']>[number], 'data'>> & {
50+
// minZ: number;
51+
// maxZ: number;
52+
// minX: number;
53+
// maxX: number;
54+
// minY: number;
55+
// maxY: number;
56+
// data: number[][];
57+
// };
5958
data?: any;
6059
loading?: boolean;
6160
zoom?: boolean;
@@ -116,11 +115,11 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
116115
[getPoint, rawData]
117116
);
118117

119-
const renderItem = useCallback(
120-
(params, api) => {
118+
const renderItem = useCallback<RenderItem>(
119+
(params: any, api: any) => {
121120
const points = makePolyPoints(params.dataIndex as number, api.value as GetValue, api.coord as GetCoord);
122121
return {
123-
type: 'path',
122+
type: 'polygon',
124123
silent: true,
125124
z: api.value?.(1),
126125
shape: {
@@ -147,9 +146,8 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
147146
useEffect(() => {
148147
dotsRef.current = dots;
149148
}, [dots]);
150-
151-
const AxisPointer = options?.axisPointer as AxisPointerComponentOption;
152-
const pointerLabelFormatter = AxisPointer.label?.formatter;
149+
const axisPointer: any = options?.axisPointer;
150+
const pointerLabelFormatter = axisPointer?.label?.formatter;
153151

154152
// formatter change will cause echarts rerender axis pointer label
155153
// so we need to use 2 refs instead of dots and highlight to get rid of dependencies of these two variables
@@ -161,15 +159,14 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
161159
if ('string' === typeof pointerLabelFormatter) {
162160
return pointerLabelFormatter;
163161
}
164-
// return pointerLabelFormatter(params, dotsRef.current[highLightRef.current]);
165-
return pointerLabelFormatter(params);
162+
return pointerLabelFormatter(params, dotsRef.current[highLightRef.current]);
166163
},
167164
[pointerLabelFormatter]
168165
);
169166

170167
const theme = useChartTheme();
171168

172-
const chartOptions = useMemo<EChartsOption>(() => {
169+
const chartOptions: any = useMemo<EChartOption>(() => {
173170
// eslint-disable-next-line @typescript-eslint/no-unused-vars
174171
const {color, colorAlt, toolbox, series, ...defaults} = chart;
175172

@@ -240,8 +237,7 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
240237
const mouseout = useCallback(() => {
241238
setHighlight(null);
242239
setDots([]);
243-
const formatters = chartOptions.tooltip as TooltipComponentOption;
244-
if (formatters.formatter) {
240+
if (chartOptions.tooltip?.formatter) {
245241
setTooltip('');
246242
if (tooltipRef.current) {
247243
tooltipRef.current.style.display = 'none';
@@ -257,13 +253,13 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
257253
}
258254

259255
const {offsetX, offsetY} = e;
260-
if (offsetY < negativeY + ((chartOptions['grid'] as GridComponentOption)?.top as number) ?? 0) {
256+
if (offsetY < negativeY + (chartOptions?.grid?.top as number) ?? 0) {
261257
mouseout();
262258
return;
263259
}
264-
const [x, y] = echarts.convertFromPixel('grid', [offsetX, offsetY]) as [number, number];
265-
const seriesData = echart?.getOption().series as LinesSeriesOption;
266-
const data = (seriesData.data as number[][]) ?? [];
260+
const [x, y] = echarts.convertFromPixel('grid' as any, [offsetX, offsetY]) as [number, number];
261+
const seriesData: any = echarts.getOption().series;
262+
const data = (seriesData[0].data as number[][]) ?? [];
267263

268264
// find right on top step
269265
const steps = data.map(row => row[1]).sort((a, b) => a - b);
@@ -300,11 +296,10 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
300296
}
301297

302298
// set tooltip
303-
const formatters = chartOptions.tooltip as TooltipComponentOption;
304-
if (formatters.formatter) {
299+
if (chartOptions.tooltip?.formatter) {
305300
setTooltip(
306301
// eslint-disable-next-line @typescript-eslint/no-explicit-any
307-
highlight == null ? '' : (formatters.formatter as any)?.(dots[highlight])
302+
highlight == null ? '' : (chartOptions.tooltip?.formatter as any)?.(dots[highlight])
308303
);
309304
if (tooltipRef.current) {
310305
if (step == null) {
@@ -384,9 +379,9 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
384379
}
385380
});
386381
} else {
387-
const seriesData = echart.getOption().series as LinesSeriesOption;
388-
const data = (seriesData.data as number[][]) ?? [];
389-
const getCoord: GetCoord = pt => echart.convertToPixel('grid', pt) as [number, number];
382+
const seriesData: any = echart.getOption().series;
383+
const data = (seriesData[0]?.data as number[][]) ?? [];
384+
const getCoord: GetCoord = pt => echart.convertToPixel('grid' as any, pt) as [number, number];
390385
const getValue: GetValue = i => data[highlight][i];
391386
echart.setOption({
392387
graphic: {
@@ -430,7 +425,7 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
430425
}
431426
});
432427
} else {
433-
const getCoord: GetCoord = pt => echart.convertToPixel('grid', pt) as [number, number];
428+
const getCoord: GetCoord = pt => echart.convertToPixel('grid' as any, pt) as [number, number];
434429
echart.setOption({
435430
graphic: {
436431
elements: dots.map((dot, i) => {
@@ -449,7 +444,7 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
449444
},
450445
style: {
451446
fill: '#fff',
452-
stroke: (chartOptions.color as ZRColor[])?.[0],
447+
stroke: chartOptions.color?.[0],
453448
lineWidth: 2
454449
}
455450
};

frontend/packages/mock/data/app/component_tabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
export default [
1818
'scalar',
1919
'image',
20-
// 'text',
20+
'text',
2121
'embeddings',
2222
'audio',
2323
'histogram',
@@ -30,4 +30,4 @@ export default [
3030
'x2paddle',
3131
'fastdeploy_server'
3232
];
33-
// export default ['dynamic_graph'];
33+
// export default ['histogram'];

0 commit comments

Comments
 (0)