-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow functional accessors (range) accessors on split series
- refactor series filter logic to allow fn accessors - cleanup filter logic to reuse code - fix filters on _all buckets with no x metric
- Loading branch information
1 parent
57ed86d
commit 8e7b5d0
Showing
7 changed files
with
252 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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 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 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,90 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { AccessorFn, Accessor } from '@elastic/charts'; | ||
import { BUCKET_TYPES } from '../../../data/public'; | ||
import { FakeParams, Aspect } from '../types'; | ||
|
||
export const COMPLEX_X_ACCESSOR = '__customXAccessor__'; | ||
export const COMPLEX_SPLIT_ACCESSOR = '__complexSplitAccessor__'; | ||
|
||
export const getXAccessor = (aspect: Aspect): Accessor | AccessorFn => { | ||
return ( | ||
getComplexAccessor(COMPLEX_X_ACCESSOR)(aspect) ?? | ||
(() => (aspect.params as FakeParams)?.defaultValue) | ||
); | ||
}; | ||
|
||
const getFieldName = (fieldName: string, index?: number) => { | ||
const indexStr = index !== undefined ? `::${index}` : ''; | ||
|
||
return `${fieldName}${indexStr}`; | ||
}; | ||
|
||
/** | ||
* Returns accessor function for complex accessor types | ||
* @param aspect | ||
*/ | ||
export const getComplexAccessor = (fieldName: string) => ( | ||
aspect: Aspect, | ||
index?: number | ||
): Accessor | AccessorFn | undefined => { | ||
if (!aspect.accessor) { | ||
return; | ||
} | ||
|
||
if ( | ||
!( | ||
(aspect.aggType === BUCKET_TYPES.DATE_RANGE || aspect.aggType === BUCKET_TYPES.RANGE) && | ||
aspect.formatter | ||
) | ||
) { | ||
return aspect.accessor; | ||
} | ||
|
||
const formatter = aspect.formatter; | ||
const accessor = aspect.accessor; | ||
const fn: AccessorFn = (d) => { | ||
const v = d[accessor]; | ||
if (!v) { | ||
return; | ||
} | ||
const f = formatter(v); | ||
return f; | ||
}; | ||
|
||
fn.fieldName = getFieldName(fieldName, index); | ||
|
||
return fn; | ||
}; | ||
|
||
export const getSplitSeriesAccessorFnMap = ( | ||
splitSeriesAccessors: Array<Accessor | AccessorFn> | ||
): Map<string | number, AccessorFn> => { | ||
const m = new Map<string | number, AccessorFn>(); | ||
|
||
splitSeriesAccessors.forEach((accessor, index) => { | ||
if (typeof accessor === 'function') { | ||
const fieldName = getFieldName(COMPLEX_SPLIT_ACCESSOR, index); | ||
m.set(fieldName, accessor); | ||
} | ||
}); | ||
|
||
return m; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.