Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Allow user to drag and select a subset of the timeline in the chart (aka brush interaction) #62636

Merged
merged 25 commits into from
Apr 30, 2020

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Apr 6, 2020

Summary

Closes #58513

  • types
  • check edgecases
  • add tests

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@mbondyra mbondyra added Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.8 v7.8.0 v8.0.0 labels Apr 6, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@mbondyra mbondyra changed the title [Lens] Brushing filter [Lens] Allow user to drag and select a subset of the timeline in the chart (aka brush interaction) Apr 6, 2020
@rayafratkina rayafratkina removed the v7.8 label Apr 6, 2020
@botelastic botelastic bot added the Feature:Embedding Embedding content via iFrame label Apr 7, 2020
@mbondyra mbondyra marked this pull request as ready for review April 8, 2020 12:02
@mbondyra mbondyra requested a review from a team April 8, 2020 12:02
@mbondyra mbondyra requested a review from a team as a code owner April 8, 2020 12:02
@mbondyra
Copy link
Contributor Author

mbondyra commented Apr 8, 2020

After talking to @ppisljar I've created this issue with potential refactoring we could benefit from: #62936

@mbondyra
Copy link
Contributor Author

mbondyra commented Apr 8, 2020

@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested this yet, but I left a few comments about the structure of the code.

}

const table = data.tables[layers[0].layerId];
const xAxisFieldName: string | undefined = xAxisColumn?.meta?.aggConfigParams?.field;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By accessing the aggConfigParams property of the table, you are breaking one of the rules that we decided to stick with in Lens: visualizations aren't allowed to write code that is specific to a single datasource. The way we usually would write this code as a result is that instead of checking for aggConfigParams or the date_histogram function, you would check for xScaleType === 'time' or dataType === 'date'

Copy link
Contributor Author

@mbondyra mbondyra Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wylieconlon but this is the information we need to pass timeFieldName, so the filter will be applied to time picker and not as a regular filter. I don't see any other way to get it. We do the same thing onClick. Do you think we should extend configuration and add xAxisFieldName?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in the meeting this should be fine as we will be moving field information off the aggConfigParams directly to meta and is something that can be provided by most datasources.

// TODO: simplify the context structure: https://github.com/elastic/kibana/issues/62936
const context: EmbeddableVisTriggerContext = {
data: {
range: [moment(min).toISOString(), moment(max).toISOString()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to set the timezone explicitly here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually checked for different timezones and it works correctly right now. How would the potential timezone setting look like?

},
},
formatHint: { id: 'date', params: { pattern: 'HH:mm' } },
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left this comment in a few places, but it will hopefully simplify this test too: we should not use the table metadata, because it's specific to only one data source.

@wylieconlon
Copy link
Contributor

@elasticmachine merge upstream

@wylieconlon
Copy link
Contributor

@mbondyra I just pushed an update to this PR because I had already made some tweaks locally, and couldn't find a way to submit a PR to your fork. Here is the reasoning behind what I've changed:

  • The behavior in your PR was only correct for the primary time field of the index pattern. While we do have some issues with secondary time fields, it's important that we don't make them worse.
  • The mechanism you were using in the PR was to expose the name of the sourceField to visualization: we decided early that this was not something visualizations should have access to, and I don't think it's needed to resolve this behavior.

The new behavior that I've pushed up has each datasource pass the primaryTimeFieldName, a concept that all of our index patterns have. If the X axis is using a different field, then a range filter is added to the filter bar instead of changing the time picker.

GIF of new behavior:

Kapture 2020-04-14 at 16 54 17

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior now LGTM with the tweaks I made. Tested in scenarios including multiple layers and non-primary time fields. The best dataset for this is actually metricbeat run locally, because it can track the start time of processes.

…-on-lens

# Conflicts:
#	x-pack/legacy/plugins/lens/public/services.ts
#	x-pack/legacy/plugins/lens/public/xy_visualization/services.ts
#	x-pack/plugins/lens/public/xy_visualization/index.ts
#	x-pack/plugins/lens/public/xy_visualization/services.ts
#	x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx
Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior does something that we don't currently support, which is that the time picker is always updated for time fields. I'm approving with the understanding that we will bind all time fields to the time picker in Lens in the near future, which means this behavior is ready for that.


return [VIS_EVENT_TO_TRIGGER.filter, VIS_EVENT_TO_TRIGGER.brush];
// case 'lnsDatatable':
// return [VIS_EVENT_TO_TRIGGER.filter];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code?

removing commented code
@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@AlonaNadler
Copy link

Hey great job!!
few things:

  • when I have two layers and using both layers time stamp, I brush the chart to zoom in and them using the time picker I move to a longer time range. It works oddly. it added a filter pill, the filter pill still focuses on the brush time range so changes I make in the time picker don't apply. I don't think it should add a filter pill.
    image
  • Sometimes a filter pill is added sometimes it doesn't

Other than that works very nice ++

…-on-lens

# Conflicts:
#	src/plugins/embeddable/public/lib/triggers/triggers.ts
#	x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx
@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@mbondyra mbondyra requested a review from flash1293 April 24, 2020 11:38
@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mbondyra mbondyra merged commit 5887c97 into elastic:master Apr 30, 2020
mbondyra added a commit to mbondyra/kibana that referenced this pull request May 1, 2020
…chart (aka brush interaction) (elastic#62636)

* feat: brushing basic example for time histogram

* test: added

* refactor: simplify the structure

* refactor: move to inline function

* refactor

* refactor

* Always use time field from index pattern

* types

* use the meta.aggConfigParams for timefieldName

* fix: test snapshot update

* Update embeddable.tsx

removing commented code

* fix: moment remov

* fix: corrections for adapting to timepicker on every timefield

* fix: fix single bar condition

* types

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
mbondyra added a commit that referenced this pull request May 1, 2020
…chart (aka brush interaction) (#62636) (#64992)

* feat: brushing basic example for time histogram

* test: added

* refactor: simplify the structure

* refactor: move to inline function

* refactor

* refactor

* Always use time field from index pattern

* types

* use the meta.aggConfigParams for timefieldName

* fix: test snapshot update

* Update embeddable.tsx

removing commented code

* fix: moment remov

* fix: corrections for adapting to timepicker on every timefield

* fix: fix single bar condition

* types

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Wylie Conlon <wylieconlon@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Embedding Embedding content via iFrame Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Allow user to drag and select a subset of the timeline in the chart (aka brush interaction)
8 participants