Describe the solution you'd like
Allow AccessorFn type for yAccessors, y0Accessors, markSizeAccessor and splitSeriesAccessors.
This is currently allowed for the xAccessor
Describe alternatives you've considered
Reformatting the data before passing it to elastic charts.
Additional context
We need to refactor the way that we track the accessors from the string of the accessor to the index order of the original accessor values.
One change is to update the split series map to use an array to match the provided splitSeriesAccessors array.
|
function getSplitAccessors(datum: Datum, accessors: Accessor[] = []): Map<string | number, string | number> { |
|
const splitAccessors = new Map<string | number, string | number>(); |
|
if (typeof datum === 'object' && datum !== null) { |
|
accessors.forEach((accessor: Accessor) => { |
|
const value = datum[accessor as keyof typeof datum]; |
|
if (typeof value === 'string' || typeof value === 'number') { |
|
splitAccessors.set(accessor, value); |
|
} |
|
}); |
|
} |
|
return splitAccessors; |
|
} |
Secondly, we need to use the yAccessor index rather than the string itself to allow use of AccessorFn
|
const seriesKeys = [...splitAccessors.values(), accessor]; |
|
const seriesKey = getSeriesKey({ |
|
specId, |
|
yAccessor: accessor, |
|
splitAccessors, |
|
}); |
which includes updating the getSeriesKey method
|
export function getSeriesKey({ |
|
specId, |
|
yAccessor, |
|
splitAccessors, |
|
}: Pick<XYChartSeriesIdentifier, 'specId' | 'yAccessor' | 'splitAccessors'>): string { |
|
const joinedAccessors = [...splitAccessors.entries()] |
|
.sort(([a], [b]) => (a > b ? 1 : -1)) |
|
.map(([key, value]) => `${key}-${value}`) |
|
.join('|'); |
|
return `spec{${specId}}yAccessor{${yAccessor}}splitAccessors{${joinedAccessors}}`; |
|
} |
⚠️ This is likely a breaking change unless we want to provide backwards compatibility by using the Accessor string when available and the index otherwise.
Related to #808
Describe the solution you'd like
Allow
AccessorFntype foryAccessors,y0Accessors,markSizeAccessorandsplitSeriesAccessors.This is currently allowed for the
xAccessorDescribe alternatives you've considered
Reformatting the data before passing it to elastic charts.
Additional context
We need to refactor the way that we track the accessors from the string of the accessor to the index order of the original accessor values.
One change is to update the split series map to use an array to match the provided
splitSeriesAccessorsarray.elastic-charts/src/chart_types/xy_chart/utils/series.ts
Lines 288 to 299 in dcd7077
Secondly, we need to use the yAccessor index rather than the string itself to allow use of
AccessorFnelastic-charts/src/chart_types/xy_chart/utils/series.ts
Lines 174 to 179 in dcd7077
which includes updating the
getSeriesKeymethodelastic-charts/src/chart_types/xy_chart/utils/series.ts
Lines 272 to 282 in dcd7077
Related to #808