Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/scales/src/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ export const generateSeriesAxis = <Axis extends ScaleAxis, Value extends ScaleVa

switch (scaleSpec.type) {
case 'linear': {
const all = sortBy(uniq(values as number[]), v => v)
const all = sortBy(
// filer null values to deal with holes in linechart
uniq(values as number[]).filter(v => v !== null),
v => v
)

return { all, min: Math.min(...all), max: Math.max(...all) }
}
Expand Down
33 changes: 33 additions & 0 deletions packages/scales/tests/compute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('generateSeriesAxis', () => {
max: 4,
}

const linearScaleExpectation2 = {
all: [2, 3, 4],
min: 2,
max: 4,
}

const timeScaleExpectation = {
all: [
new Date(Date.UTC(2018, 3, 1, 0, 0, 0, 0)),
Expand Down Expand Up @@ -116,6 +122,33 @@ describe('generateSeriesAxis', () => {
).toEqual(linearScaleExpectation)
})

it('should filter null values (holes) for linear scale', () => {
expect(
generateSeriesAxis(
[
{
id: 'A',
data: [
{ data: { [axis]: '2' } },
{ data: { [axis]: '04' } },
{ data: { [axis]: null } },
],
},
{
id: 'B',
data: [
{ data: { [axis]: '04' } },
{ data: { [axis]: 2 } },
{ data: { [axis]: '3' } },
],
},
],
axis,
{ type: 'linear' }
)
).toEqual(linearScaleExpectation2)
})

it('should compute values for time scale with native dates', () => {
expect(
generateSeriesAxis(
Expand Down