Added brush to time-chart (#14929)

This commit is contained in:
Sébastien 2023-08-30 13:36:50 -04:00 committed by GitHub
parent d295b9158f
commit 42cfb999cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 1 deletions

View File

@ -93,7 +93,7 @@ export default typedVisualModule({
}, },
}, },
}, },
module: ({ container, host }) => { module: ({ container, host, updateWhere }) => {
const myChart = echarts.init(container, 'dark'); const myChart = echarts.init(container, 'dark');
myChart.setOption({ myChart.setOption({
@ -103,6 +103,7 @@ export default typedVisualModule({
}, },
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
transitionDuration: 0,
axisPointer: { axisPointer: {
type: 'cross', type: 'cross',
label: { label: {
@ -118,6 +119,10 @@ export default typedVisualModule({
saveAsImage: {}, saveAsImage: {},
}, },
}, },
brush: {
toolbox: ['lineX'],
xAxisIndex: 0,
},
grid: { grid: {
left: '3%', left: '3%',
right: '4%', right: '4%',
@ -148,6 +153,8 @@ export default typedVisualModule({
async update({ table, where, parameterValues }) { async update({ table, where, parameterValues }) {
const { splitColumn, metric, numberToStack, showOthers, timeGranularity } = parameterValues; const { splitColumn, metric, numberToStack, showOthers, timeGranularity } = parameterValues;
myChart.off('brushend');
const vs = splitColumn const vs = splitColumn
? ( ? (
await host.sqlQuery( await host.sqlQuery(
@ -187,6 +194,28 @@ export default typedVisualModule({
const effectiveVs = vs && showOthers ? vs.concat(OTHERS_VALUE) : vs; const effectiveVs = vs && showOthers ? vs.concat(OTHERS_VALUE) : vs;
const sourceData = effectiveVs ? transformData(dataset, effectiveVs) : dataset; const sourceData = effectiveVs ? transformData(dataset, effectiveVs) : dataset;
myChart.on('brushend', (params: any) => {
if (!params.areas.length) return;
const [start, end] = params.areas[0].coordRange;
updateWhere(
where.changeClauseInWhere(
SqlExpression.parse(
`TIME_IN_INTERVAL(${C('__time')}, '${new Date(start).toISOString()}/${new Date(
end,
).toISOString()}')`,
),
),
);
myChart.dispatchAction({
type: 'brush',
command: 'clear',
areas: [],
});
});
const showSymbol = sourceData.length < 2; const showSymbol = sourceData.length < 2;
myChart.setOption( myChart.setOption(
{ {
@ -194,6 +223,7 @@ export default typedVisualModule({
dimensions: ['time'].concat(vs || ['met']), dimensions: ['time'].concat(vs || ['met']),
source: sourceData, source: sourceData,
}, },
animation: false,
legend: effectiveVs legend: effectiveVs
? { ? {
data: effectiveVs, data: effectiveVs,