forked from elastic/elastic-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legend/series): add hover interaction on legend items
addresses elastic#24
- Loading branch information
1 parent
c94dd22
commit 455a033
Showing
6 changed files
with
130 additions
and
6 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
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,47 @@ | ||
import { getSpecId } from '../utils/ids'; | ||
import { GeometryValue } from './rendering'; | ||
import { DataSeriesColorsValues } from './series'; | ||
import { belongsToDataSeries, isEqualSeriesKey } from './series_utils'; | ||
|
||
describe('Series utility functions', () => { | ||
test('can compare series keys for identity', () => { | ||
const seriesKeyA = ['a', 'b', 'c']; | ||
const seriesKeyB = ['a', 'b', 'c']; | ||
const seriesKeyC = ['a', 'b', 'd']; | ||
const seriesKeyD = ['d']; | ||
const seriesKeyE = ['b', 'a', 'c']; | ||
|
||
expect(isEqualSeriesKey(seriesKeyA, seriesKeyB)).toBe(true); | ||
expect(isEqualSeriesKey(seriesKeyB, seriesKeyC)).toBe(false); | ||
expect(isEqualSeriesKey(seriesKeyA, seriesKeyD)).toBe(false); | ||
expect(isEqualSeriesKey(seriesKeyA, seriesKeyE)).toBe(false); | ||
expect(isEqualSeriesKey(seriesKeyA, [])).toBe(false); | ||
}); | ||
|
||
test('can determine if a geometry value belongs to a data series', () => { | ||
const geometryValueA: GeometryValue = { | ||
specId: getSpecId('a'), | ||
datum: null, | ||
seriesKey: ['a', 'b', 'c'], | ||
}; | ||
|
||
const dataSeriesValuesA: DataSeriesColorsValues = { | ||
specId: getSpecId('a'), | ||
colorValues: ['a', 'b', 'c'], | ||
}; | ||
|
||
const dataSeriesValuesB: DataSeriesColorsValues = { | ||
specId: getSpecId('b'), | ||
colorValues: ['a', 'b', 'c'], | ||
}; | ||
|
||
const dataSeriesValuesC: DataSeriesColorsValues = { | ||
specId: getSpecId('a'), | ||
colorValues: ['a', 'b', 'd'], | ||
}; | ||
|
||
expect(belongsToDataSeries(geometryValueA, dataSeriesValuesA)).toBe(true); | ||
expect(belongsToDataSeries(geometryValueA, dataSeriesValuesB)).toBe(false); | ||
expect(belongsToDataSeries(geometryValueA, dataSeriesValuesC)).toBe(false); | ||
}); | ||
}); |
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,31 @@ | ||
import { GeometryValue } from './rendering'; | ||
import { DataSeriesColorsValues } from './series'; | ||
|
||
export function isEqualSeriesKey(a: any[], b: any[]): boolean { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
|
||
let ret = true; | ||
|
||
a.forEach((aVal: any, idx: number) => { | ||
if (aVal !== b[idx]) { | ||
ret = false; | ||
} | ||
}); | ||
|
||
return ret; | ||
} | ||
|
||
export function belongsToDataSeries(geometryValue: GeometryValue, dataSeriesValues: DataSeriesColorsValues): boolean { | ||
const legendItemSeriesKey = dataSeriesValues.colorValues; | ||
const legendItemSpecId = dataSeriesValues.specId; | ||
|
||
const geometrySeriesKey = geometryValue.seriesKey; | ||
const geometrySpecId = geometryValue.specId; | ||
|
||
const hasSameSpecId = legendItemSpecId === geometrySpecId; | ||
const hasSameSeriesKey = isEqualSeriesKey(legendItemSeriesKey, geometrySeriesKey); | ||
|
||
return hasSameSpecId && hasSameSeriesKey; | ||
} |
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