-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Maps] geo line source #76572
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
Merged
Merged
[Maps] geo line source #76572
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9762345
[Maps] geo line source
nreese 060e44a
update editor with metrics
nreese c4788cd
show track name in tooltip
nreese a203cf0
fix styling by category
nreese a1895c0
avoid killing ES, limit to 100 tracks
nreese fa9f66e
better source tooltip message
nreese 335d440
merge with master
nreese c365867
merge with master
nreese dccc802
fix imports
nreese bce45df
increase max tracks
nreese 77dee60
Merge branch 'master' into geo_line
kibanamachine 1cb8aae
use tracks icon
nreese 891a60b
tslint
nreese 96ac781
Making layer wizard select tooltip flex
elizabetdev 02f492b
tslint and jest snapshot updates
nreese 4c415cc
clean up
nreese 15f7799
Merge branch 'master' into geo_line
kibanamachine 5bb7212
add trimmed property to tooltip
nreese 4427613
change complete label to 'track is complete'
nreese 4485f93
show incomplete data icon if tracks are trimmed
nreese 5da8cdb
add jest test for getSourceTooltipContent
nreese 7bbfa54
clean up areResultsTrimmed logic
nreese c0c72f8
split request into 2 fetches
nreese b7e6390
Merge branch 'master' into geo_line
kibanamachine d932913
Merge branch 'master' of github.com:elastic/kibana into geo_line
nreese e7c9032
review feedback
nreese 11d5701
do not allow selecting split field as sort field
nreese 7364c8c
reduce number of tracks to 250
nreese 2bc733d
tslint
nreese File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/maps/public/classes/sources/es_geo_line_source/convert_to_geojson.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { convertToGeoJson } from './convert_to_geojson'; | ||
|
|
||
| const esResponse = { | ||
| aggregations: { | ||
| tracks: { | ||
| buckets: { | ||
| ios: { | ||
| doc_count: 1, | ||
| path: { | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'LineString', | ||
| coordinates: [ | ||
| [-95.339639, 41.584389], | ||
| [-95.339639, 41.0], | ||
| ], | ||
| }, | ||
| properties: { | ||
| complete: true, | ||
| }, | ||
| }, | ||
| }, | ||
| osx: { | ||
| doc_count: 1, | ||
| path: { | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'LineString', | ||
| coordinates: [ | ||
| [-97.902775, 48.940572], | ||
| [-97.902775, 48.0], | ||
| ], | ||
| }, | ||
| properties: { | ||
| complete: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| it('Should convert elasticsearch aggregation response into feature collection', () => { | ||
| const geoJson = convertToGeoJson(esResponse, 'machine.os.keyword'); | ||
| expect(geoJson.numTrimmedTracks).toBe(1); | ||
| expect(geoJson.featureCollection.features.length).toBe(2); | ||
| expect(geoJson.featureCollection.features[0]).toEqual({ | ||
| geometry: { | ||
| coordinates: [ | ||
| [-95.339639, 41.584389], | ||
| [-95.339639, 41.0], | ||
| ], | ||
| type: 'LineString', | ||
| }, | ||
| id: 'ios', | ||
| properties: { | ||
| complete: true, | ||
| doc_count: 1, | ||
| ['machine.os.keyword']: 'ios', | ||
| }, | ||
| type: 'Feature', | ||
| }); | ||
| }); |
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/maps/public/classes/sources/es_geo_line_source/convert_to_geojson.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import _ from 'lodash'; | ||
| import { Feature, FeatureCollection } from 'geojson'; | ||
| import { extractPropertiesFromBucket } from '../../../../common/elasticsearch_util'; | ||
|
|
||
| const KEYS_TO_IGNORE = ['key', 'path']; | ||
|
|
||
| export function convertToGeoJson(esResponse: any, entitySplitFieldName: string) { | ||
| const features: Feature[] = []; | ||
| let numTrimmedTracks = 0; | ||
|
|
||
| const buckets = _.get(esResponse, 'aggregations.tracks.buckets', {}); | ||
| const entityKeys = Object.keys(buckets); | ||
| for (let i = 0; i < entityKeys.length; i++) { | ||
| const entityKey = entityKeys[i]; | ||
| const bucket = buckets[entityKey]; | ||
| const feature = bucket.path as Feature; | ||
| if (!feature.properties!.complete) { | ||
| numTrimmedTracks++; | ||
| } | ||
| feature.id = entityKey; | ||
| feature.properties = { | ||
| [entitySplitFieldName]: entityKey, | ||
| ...feature.properties, | ||
| ...extractPropertiesFromBucket(bucket, KEYS_TO_IGNORE), | ||
| }; | ||
| features.push(feature); | ||
| } | ||
|
|
||
| return { | ||
| featureCollection: { | ||
| type: 'FeatureCollection', | ||
| features, | ||
| } as FeatureCollection, | ||
| numTrimmedTracks, | ||
| }; | ||
| } |
151 changes: 151 additions & 0 deletions
151
x-pack/plugins/maps/public/classes/sources/es_geo_line_source/create_source_editor.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React, { Component } from 'react'; | ||
|
|
||
| import { IndexPattern } from 'src/plugins/data/public'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { EuiFormRow, EuiPanel } from '@elastic/eui'; | ||
| import { SingleFieldSelect } from '../../../components/single_field_select'; | ||
| import { GeoIndexPatternSelect } from '../../../components/geo_index_pattern_select'; | ||
|
|
||
| import { getGeoPointFields } from '../../../index_pattern_util'; | ||
| import { GeoLineForm } from './geo_line_form'; | ||
|
|
||
| interface Props { | ||
| onSourceConfigChange: ( | ||
| sourceConfig: { | ||
| indexPatternId: string; | ||
| geoField: string; | ||
| splitField: string; | ||
| sortField: string; | ||
| } | null | ||
| ) => void; | ||
| } | ||
|
|
||
| interface State { | ||
| indexPattern: IndexPattern | null; | ||
| geoField: string; | ||
| splitField: string; | ||
| sortField: string; | ||
| } | ||
|
|
||
| export class CreateSourceEditor extends Component<Props, State> { | ||
| state: State = { | ||
| indexPattern: null, | ||
| geoField: '', | ||
| splitField: '', | ||
| sortField: '', | ||
| }; | ||
|
|
||
| _onIndexPatternSelect = (indexPattern: IndexPattern) => { | ||
| const pointFields = getGeoPointFields(indexPattern.fields); | ||
| this.setState( | ||
| { | ||
| indexPattern, | ||
| geoField: pointFields.length ? pointFields[0].name : '', | ||
| sortField: indexPattern.timeFieldName ? indexPattern.timeFieldName : '', | ||
| }, | ||
| this.previewLayer | ||
| ); | ||
| }; | ||
|
|
||
| _onGeoFieldSelect = (geoField?: string) => { | ||
| if (geoField === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| this.setState( | ||
| { | ||
| geoField, | ||
| }, | ||
| this.previewLayer | ||
| ); | ||
| }; | ||
|
|
||
| _onSplitFieldSelect = (newValue: string) => { | ||
| this.setState( | ||
| { | ||
| splitField: newValue, | ||
| }, | ||
| this.previewLayer | ||
| ); | ||
| }; | ||
|
|
||
| _onSortFieldSelect = (newValue: string) => { | ||
| this.setState( | ||
| { | ||
| sortField: newValue, | ||
| }, | ||
| this.previewLayer | ||
| ); | ||
| }; | ||
|
|
||
| previewLayer = () => { | ||
| const { indexPattern, geoField, splitField, sortField } = this.state; | ||
|
|
||
| const sourceConfig = | ||
| indexPattern && indexPattern.id && geoField && splitField && sortField | ||
| ? { indexPatternId: indexPattern.id, geoField, splitField, sortField } | ||
| : null; | ||
| this.props.onSourceConfigChange(sourceConfig); | ||
| }; | ||
|
|
||
| _renderGeoSelect() { | ||
| if (!this.state.indexPattern) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <EuiFormRow | ||
| label={i18n.translate('xpack.maps.source.esGeoLine.geofieldLabel', { | ||
| defaultMessage: 'Geospatial field', | ||
| })} | ||
| > | ||
| <SingleFieldSelect | ||
| placeholder={i18n.translate('xpack.maps.source.esGeoLine.geofieldPlaceholder', { | ||
| defaultMessage: 'Select geo field', | ||
| })} | ||
| value={this.state.geoField} | ||
| onChange={this._onGeoFieldSelect} | ||
| fields={getGeoPointFields(this.state.indexPattern.fields)} | ||
| /> | ||
| </EuiFormRow> | ||
| ); | ||
| } | ||
|
|
||
| _renderGeoLineForm() { | ||
| if (!this.state.indexPattern || !this.state.geoField) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <GeoLineForm | ||
| indexPattern={this.state.indexPattern} | ||
| onSortFieldChange={this._onSortFieldSelect} | ||
| onSplitFieldChange={this._onSplitFieldSelect} | ||
| sortField={this.state.sortField} | ||
| splitField={this.state.splitField} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <EuiPanel> | ||
| <GeoIndexPatternSelect | ||
| value={ | ||
| this.state.indexPattern && this.state.indexPattern.id ? this.state.indexPattern.id : '' | ||
| } | ||
| onChange={this._onIndexPatternSelect} | ||
| isGeoPointsOnly={true} | ||
| /> | ||
| {this._renderGeoSelect()} | ||
| {this._renderGeoLineForm()} | ||
| </EuiPanel> | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.