Skip to content

Commit

Permalink
Added brush to time-chart (#14929)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorem--ipsum committed Aug 30, 2023
1 parent d295b91 commit 42cfb99
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default typedVisualModule({
},
},
},
module: ({ container, host }) => {
module: ({ container, host, updateWhere }) => {
const myChart = echarts.init(container, 'dark');

myChart.setOption({
Expand All @@ -103,6 +103,7 @@ export default typedVisualModule({
},
tooltip: {
trigger: 'axis',
transitionDuration: 0,
axisPointer: {
type: 'cross',
label: {
Expand All @@ -118,6 +119,10 @@ export default typedVisualModule({
saveAsImage: {},
},
},
brush: {
toolbox: ['lineX'],
xAxisIndex: 0,
},
grid: {
left: '3%',
right: '4%',
Expand Down Expand Up @@ -148,6 +153,8 @@ export default typedVisualModule({
async update({ table, where, parameterValues }) {
const { splitColumn, metric, numberToStack, showOthers, timeGranularity } = parameterValues;

myChart.off('brushend');

const vs = splitColumn
? (
await host.sqlQuery(
Expand Down Expand Up @@ -187,13 +194,36 @@ export default typedVisualModule({
const effectiveVs = vs && showOthers ? vs.concat(OTHERS_VALUE) : vs;
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;
myChart.setOption(
{
dataset: {
dimensions: ['time'].concat(vs || ['met']),
source: sourceData,
},
animation: false,
legend: effectiveVs
? {
data: effectiveVs,
Expand Down

0 comments on commit 42cfb99

Please sign in to comment.