mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
feat: Adds drill to detail context menu for ECharts visualizations (#20891)
* feat: Adds drill to detail context menu for ECharts visualizations * Rebases and adds time grain * Fixes selected gauge values * Fixes Treemap edge click * Adds right click to big number trendline * Address some comments
This commit is contained in:
committed by
GitHub
parent
0042ade66f
commit
3df8335f87
@@ -27,7 +27,8 @@ import { BigNumberTotalChartProps } from '../types';
|
||||
import { getDateFormatter, parseMetricValue } from '../utils';
|
||||
|
||||
export default function transformProps(chartProps: BigNumberTotalChartProps) {
|
||||
const { width, height, queriesData, formData, rawFormData } = chartProps;
|
||||
const { width, height, queriesData, formData, rawFormData, hooks } =
|
||||
chartProps;
|
||||
const {
|
||||
headerFontSize,
|
||||
metric = 'value',
|
||||
@@ -64,6 +65,8 @@ export default function transformProps(chartProps: BigNumberTotalChartProps) {
|
||||
? formatTime
|
||||
: getNumberFormatter(yAxisFormat ?? metricEntry?.d3format ?? undefined);
|
||||
|
||||
const { onContextMenu } = hooks;
|
||||
|
||||
return {
|
||||
width,
|
||||
height,
|
||||
@@ -72,5 +75,6 @@ export default function transformProps(chartProps: BigNumberTotalChartProps) {
|
||||
headerFontSize,
|
||||
subheaderFontSize,
|
||||
subheader: formattedSubheader,
|
||||
onContextMenu,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import React, { MouseEvent } from 'react';
|
||||
import {
|
||||
t,
|
||||
getNumberFormatter,
|
||||
@@ -26,10 +26,12 @@ import {
|
||||
computeMaxFontSize,
|
||||
BRAND_COLOR,
|
||||
styled,
|
||||
QueryObjectFilterClause,
|
||||
} from '@superset-ui/core';
|
||||
import { EChartsCoreOption } from 'echarts';
|
||||
import Echart from '../components/Echart';
|
||||
import { TimeSeriesDatum } from './types';
|
||||
import { BigNumberWithTrendlineFormData, TimeSeriesDatum } from './types';
|
||||
import { EventHandlers } from '../types';
|
||||
|
||||
const defaultNumberFormatter = getNumberFormatter();
|
||||
|
||||
@@ -62,6 +64,13 @@ type BigNumberVisProps = {
|
||||
trendLineData?: TimeSeriesDatum[];
|
||||
mainColor: string;
|
||||
echartOptions: EChartsCoreOption;
|
||||
onContextMenu?: (
|
||||
filters: QueryObjectFilterClause[],
|
||||
offsetX: number,
|
||||
offsetY: number,
|
||||
) => void;
|
||||
xValueFormatter?: TimeFormatter;
|
||||
formData?: BigNumberWithTrendlineFormData;
|
||||
};
|
||||
|
||||
class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
|
||||
@@ -159,6 +168,17 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
|
||||
});
|
||||
container.remove();
|
||||
|
||||
const onContextMenu = (e: MouseEvent<HTMLDivElement>) => {
|
||||
if (this.props.onContextMenu) {
|
||||
e.preventDefault();
|
||||
this.props.onContextMenu(
|
||||
[],
|
||||
e.nativeEvent.offsetX,
|
||||
e.nativeEvent.offsetY,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="header-line"
|
||||
@@ -166,6 +186,7 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
|
||||
fontSize,
|
||||
height: maxHeight,
|
||||
}}
|
||||
onContextMenu={onContextMenu}
|
||||
>
|
||||
{text}
|
||||
</div>
|
||||
@@ -213,7 +234,7 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
|
||||
return null;
|
||||
}
|
||||
|
||||
renderTrendline(maxHeight: number) {
|
||||
renderTrendline(maxHeight: number, chartHeight: number) {
|
||||
const { width, trendLineData, echartOptions } = this.props;
|
||||
|
||||
// if can't find any non-null values, no point rendering the trendline
|
||||
@@ -221,11 +242,37 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const eventHandlers: EventHandlers = {
|
||||
contextmenu: eventParams => {
|
||||
if (this.props.onContextMenu) {
|
||||
eventParams.event.stop();
|
||||
const { data } = eventParams;
|
||||
if (data) {
|
||||
const pointerEvent = eventParams.event.event;
|
||||
const filters: QueryObjectFilterClause[] = [];
|
||||
filters.push({
|
||||
col: this.props.formData?.granularitySqla,
|
||||
grain: this.props.formData?.timeGrainSqla,
|
||||
op: '==',
|
||||
val: data[0],
|
||||
formattedVal: this.props.xValueFormatter?.(data[0]),
|
||||
});
|
||||
this.props.onContextMenu(
|
||||
filters,
|
||||
pointerEvent.offsetX,
|
||||
chartHeight - 100,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<Echart
|
||||
width={Math.floor(width)}
|
||||
height={maxHeight}
|
||||
echartOptions={echartOptions}
|
||||
eventHandlers={eventHandlers}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -260,7 +307,7 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
{this.renderTrendline(chartHeight)}
|
||||
{this.renderTrendline(chartHeight, height)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -283,6 +330,7 @@ export default styled(BigNumberVis)`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
|
||||
&.no-trendline .subheader-line {
|
||||
padding-bottom: 0.3em;
|
||||
|
||||
@@ -62,8 +62,16 @@ const formatPercentChange = getNumberFormatter(
|
||||
export default function transformProps(
|
||||
chartProps: BigNumberWithTrendlineChartProps,
|
||||
) {
|
||||
const { width, height, queriesData, formData, rawFormData, theme } =
|
||||
chartProps;
|
||||
const {
|
||||
width,
|
||||
height,
|
||||
queriesData,
|
||||
formData,
|
||||
rawFormData,
|
||||
theme,
|
||||
hooks,
|
||||
inContextMenu,
|
||||
} = chartProps;
|
||||
const {
|
||||
colorPicker,
|
||||
compareLag: compareLag_,
|
||||
@@ -221,7 +229,7 @@ export default function transformProps(
|
||||
},
|
||||
tooltip: {
|
||||
appendToBody: true,
|
||||
show: true,
|
||||
show: !inContextMenu,
|
||||
trigger: 'axis',
|
||||
confine: true,
|
||||
formatter: renderTooltipFactory(formatTime, headerFormatter),
|
||||
@@ -234,6 +242,9 @@ export default function transformProps(
|
||||
},
|
||||
}
|
||||
: {};
|
||||
|
||||
const { onContextMenu } = hooks;
|
||||
|
||||
return {
|
||||
width,
|
||||
height,
|
||||
@@ -242,6 +253,7 @@ export default function transformProps(
|
||||
className,
|
||||
headerFormatter,
|
||||
formatTime,
|
||||
formData,
|
||||
headerFontSize,
|
||||
subheaderFontSize,
|
||||
mainColor,
|
||||
@@ -252,5 +264,7 @@ export default function transformProps(
|
||||
timestamp,
|
||||
trendLineData,
|
||||
echartOptions,
|
||||
onContextMenu,
|
||||
xValueFormatter: formatTime,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user