-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: [IGL-98] Removed error when all is null in AreaChart
- Loading branch information
1 parent
5ab9240
commit 7c9c663
Showing
1 changed file
with
92 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,114 @@ | ||
import type { DataSet } from '../AreaChart'; | ||
import type { DataSet } from "../AreaChart"; | ||
|
||
type DataWithRender = DataSet & { | ||
render?: { | ||
[index: string]: number | null; | ||
uiScoreBackground: number | null; | ||
}; | ||
render?: { | ||
[index: string]: number | null; | ||
uiScoreBackground: number | null; | ||
}; | ||
}; | ||
|
||
export function getUniqueKeys(data: DataWithRender[]): string[] { | ||
return data.reduce((keys: string[], data) => { | ||
if (data.render) { | ||
const keysStartingWithFakeScore = Object.keys(data.render).filter((key) => | ||
key.startsWith('fakeScore'), | ||
); | ||
|
||
keysStartingWithFakeScore.map((key) => { | ||
if (!keys.includes(key)) { | ||
keys.push(key); | ||
return data.reduce((keys: string[], data) => { | ||
if (data.render) { | ||
const keysStartingWithFakeScore = Object.keys(data.render).filter(key => | ||
key.startsWith("fakeScore") | ||
); | ||
|
||
keysStartingWithFakeScore.map(key => { | ||
if (!keys.includes(key)) { | ||
keys.push(key); | ||
} | ||
|
||
return null; | ||
}); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
return keys; | ||
}, []); | ||
return keys; | ||
}, []); | ||
} | ||
|
||
export function getNullSequenceRanges(data: DataSet[]): number[][] { | ||
const sequenceRanges = []; | ||
let start = null; | ||
|
||
for (let i = 0; i < data.length; i += 1) { | ||
if (data[i].score === null && start === null) { | ||
start = i; | ||
} else if (data[i].score !== null && start !== null) { | ||
sequenceRanges.push([start, i - 1]); | ||
start = null; | ||
const sequenceRanges = []; | ||
let start = null; | ||
|
||
for (let i = 0; i < data.length; i += 1) { | ||
if (data[i].score === null && start === null) { | ||
start = i; | ||
} else if (data[i].score !== null && start !== null) { | ||
sequenceRanges.push([start, i - 1]); | ||
start = null; | ||
} | ||
} | ||
} | ||
|
||
if (start !== null) { | ||
sequenceRanges.push([start, data.length - 1]); | ||
} | ||
if (start !== null) { | ||
sequenceRanges.push([start, data.length - 1]); | ||
} | ||
|
||
return sequenceRanges; | ||
return sequenceRanges; | ||
} | ||
|
||
export function getFakeScore( | ||
data: DataWithRender[], | ||
sequenceRanges: number[][], | ||
data: DataWithRender[], | ||
sequenceRanges: number[][] | ||
): DataWithRender[] { | ||
sequenceRanges.map((range, index) => { | ||
const [first, last] = range; | ||
const fakeScore = `fakeScore${index}`; | ||
|
||
if (first === 0) { | ||
data[first].render = { | ||
...data[first].render, | ||
[fakeScore]: data[last + 1].score, | ||
uiScoreBackground: data[last + 1].score, | ||
}; | ||
} | ||
sequenceRanges.map((range, index) => { | ||
const [first, last] = range; | ||
const fakeScore = `fakeScore${index}`; | ||
const endIsNull = data.length - 1 === last; | ||
const startIsNull = first === 0; | ||
|
||
if (endIsNull && startIsNull) { | ||
data[first].render = { | ||
...data[first].render, | ||
[fakeScore]: 0, | ||
uiScoreBackground: 0 | ||
}; | ||
|
||
data[last].render = { | ||
...data[last].render, | ||
[fakeScore]: 0, | ||
uiScoreBackground: 0 | ||
}; | ||
|
||
return null; | ||
} | ||
|
||
if (startIsNull) { | ||
data[first].render = { | ||
...data[first].render, | ||
[fakeScore]: data[last + 1].score, | ||
uiScoreBackground: data[last + 1].score | ||
}; | ||
} | ||
|
||
if (last === data.length - 1) { | ||
data[last].render = { | ||
...data[last].render, | ||
[fakeScore]: data[first - 1].score, | ||
uiScoreBackground: data[first - 1].score, | ||
}; | ||
} | ||
if (endIsNull) { | ||
data[last].render = { | ||
...data[last].render, | ||
[fakeScore]: data[first - 1].score, | ||
uiScoreBackground: data[first - 1].score | ||
}; | ||
} | ||
|
||
data.map((item: DataWithRender, index) => { | ||
if (item.render === undefined) { | ||
item.render = { | ||
uiScoreBackground: item.score, | ||
}; | ||
} | ||
|
||
if (index === first - 1) { | ||
item.render = { | ||
...item.render, | ||
[fakeScore]: item.score, | ||
uiScoreBackground: item.score, | ||
}; | ||
} | ||
|
||
if (index === last + 1) { | ||
item.render = { | ||
...item.render, | ||
[fakeScore]: item.score, | ||
uiScoreBackground: item.score, | ||
}; | ||
} | ||
|
||
return null; | ||
}); | ||
data.map((item: DataWithRender, i) => { | ||
if (item.render === undefined) { | ||
item.render = { | ||
uiScoreBackground: item.score | ||
}; | ||
} | ||
|
||
if (i === first - 1 || i === last + 1) { | ||
item.render = { | ||
...item.render, | ||
[fakeScore]: item.score, | ||
uiScoreBackground: item.score | ||
}; | ||
} | ||
|
||
return null; | ||
}); | ||
return null; | ||
}); | ||
|
||
return null; | ||
}); | ||
|
||
return data; | ||
return data; | ||
} |