-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add additional columns to Static Legend for stacked line layer (#…
…555)
- Loading branch information
Showing
13 changed files
with
351 additions
and
142 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
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,77 @@ | ||
import {getDataSortOrder} from './sort' | ||
import {getRandomTable} from '../fixtures/randomTable' | ||
import {lineTransform} from '../../transforms/line' | ||
import {NINETEEN_EIGHTY_FOUR} from '../../constants/colorSchemes' | ||
import {DomainLabel} from '../../types' | ||
|
||
describe('getDataSortOrder', () => { | ||
const xColKey = '_time' | ||
const yColKey = '_value' | ||
const maxValue = 100 | ||
const numberOfRecords = 200 | ||
const recordsPerLine = 10 | ||
const fillColKeys = ['cpu', 'host', 'machine'] | ||
const table = getRandomTable( | ||
maxValue, | ||
true, | ||
numberOfRecords, | ||
recordsPerLine, | ||
fillColKeys | ||
) | ||
|
||
it('leaves overlaid line graphs unsorted', () => { | ||
const lineOption = 'overlaid' | ||
const lineSpec = lineTransform( | ||
table, | ||
xColKey, | ||
yColKey, | ||
fillColKeys, | ||
NINETEEN_EIGHTY_FOUR, | ||
lineOption | ||
) | ||
|
||
const latestIndices = Object.values(lineSpec.columnGroupMaps.latestIndices) | ||
const sortOrder = getDataSortOrder( | ||
lineSpec.lineData, | ||
latestIndices, | ||
lineOption, | ||
DomainLabel.Y | ||
) | ||
expect(latestIndices).toEqual(sortOrder) | ||
}) | ||
|
||
it('sorts stacked line graphs in descending order', () => { | ||
const lineOption = 'stacked' | ||
const lineSpec = lineTransform( | ||
table, | ||
xColKey, | ||
yColKey, | ||
fillColKeys, | ||
NINETEEN_EIGHTY_FOUR, | ||
lineOption | ||
) | ||
const {stackedDomainValueColumn} = lineSpec | ||
|
||
const latestIndices = Object.values(lineSpec.columnGroupMaps.latestIndices) | ||
const sortOrder = getDataSortOrder( | ||
lineSpec.lineData, | ||
latestIndices, | ||
lineOption, | ||
DomainLabel.Y | ||
) | ||
expect(sortOrder.length).toBeGreaterThanOrEqual(2) | ||
sortOrder.forEach((columnIndex, index) => { | ||
if (index < sortOrder.length - 1) { | ||
expect( | ||
stackedDomainValueColumn[columnIndex] > | ||
stackedDomainValueColumn[columnIndex + 1] | ||
) | ||
} else { | ||
expect( | ||
stackedDomainValueColumn[columnIndex] < | ||
stackedDomainValueColumn[columnIndex + 1] | ||
) | ||
} | ||
}) | ||
}) | ||
}) |
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 {DomainLabel, LineData, LinePosition} from '../../types' | ||
|
||
export const getDataSortOrder = ( | ||
lineData: LineData, | ||
rowIndices: number[], | ||
position: LinePosition, | ||
domainLabel?: DomainLabel | ||
): number[] => { | ||
if (!position || position === 'overlaid') { | ||
return rowIndices | ||
} | ||
|
||
const domainLabelName = domainLabel || DomainLabel.Y | ||
|
||
const numberMap = {} | ||
const numericalValues = Object.keys(lineData).reduce( | ||
(combinedNumericalValues, id) => | ||
combinedNumericalValues.concat(lineData[id][domainLabelName]), | ||
[] | ||
) | ||
const sortable = [] | ||
rowIndices.forEach(rowIndex => { | ||
if (!numberMap[numericalValues[rowIndex]]) { | ||
numberMap[numericalValues[rowIndex]] = [] | ||
} | ||
numberMap[numericalValues[rowIndex]].push(rowIndex) | ||
sortable.push(numericalValues[rowIndex]) | ||
}) | ||
sortable.sort((first, second) => second - first) | ||
return sortable.map(numericalValue => numberMap[numericalValue].shift()) | ||
} |
Oops, something went wrong.