-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(barSeries): error rendering bars with negative log scale
- Loading branch information
1 parent
98f3e51
commit 30f5861
Showing
7 changed files
with
113 additions
and
49 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
67 changes: 67 additions & 0 deletions
67
storybook/stories/test_cases/12_log_with_negative_values.story.tsx
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,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { boolean, number } from '@storybook/addon-knobs'; | ||
import numeral from 'numeral'; | ||
import React from 'react'; | ||
|
||
import { Axis, Chart, Position, ScaleType, Settings } from '@elastic/charts'; | ||
import { getRandomNumberGenerator } from '@elastic/charts/src/mocks/utils'; | ||
|
||
import { ChartsStory } from '../../types'; | ||
import { useBaseTheme } from '../../use_base_theme'; | ||
import { customKnobs } from '../utils/knobs'; | ||
|
||
const rng = getRandomNumberGenerator(); | ||
|
||
const data = new Array(20).fill(1).flatMap((_, x) => | ||
['A', 'B', 'C'].map((g) => { | ||
const y1 = rng(30, 100); | ||
const y0 = rng(0.01, 20); | ||
return { | ||
x, | ||
g, | ||
y1Pos: y1, | ||
y1Neg: -y1, | ||
y0Pos: y0, | ||
y0Neg: -y0, | ||
}; | ||
}), | ||
); | ||
|
||
export const Example: ChartsStory = (_, { title, description }) => { | ||
const yScaleType = customKnobs.enum.scaleType('Scale Type', ScaleType.Log, { include: ['Linear', 'Log'] }); | ||
const [Series] = customKnobs.enum.xySeries('Series Type', 'bar', { exclude: ['bubble'] }); | ||
const logMinLimit = number('logMinLimit', 1, { min: 0 }); | ||
const yNice = boolean('Nice y ticks', false); | ||
const banded = boolean('Banded', false); | ||
const split = boolean('Split', false); | ||
const stacked = boolean('Stacked', true); | ||
const showPosData = boolean('Show positive data', false); | ||
|
||
return ( | ||
<Chart title={title} description={description}> | ||
<Settings baseTheme={useBaseTheme()} /> | ||
<Axis id="bottom" title="x" position={Position.Bottom} ticks={20} /> | ||
<Axis id="left" title="y" position={Position.Left} domain={{ min: NaN, max: NaN, logMinLimit }} /> | ||
<Series | ||
id="lines" | ||
xScaleType={ScaleType.Linear} | ||
yScaleType={yScaleType} | ||
tickFormat={(d: number) => numeral(d).format('0.[0]')} | ||
data={split ? data : data.filter(({ g }) => g === 'A')} | ||
yNice={yNice} | ||
xAccessor="x" | ||
yAccessors={showPosData ? ['y1Pos'] : ['y1Neg']} | ||
y0Accessors={!banded ? [] : showPosData ? ['y0Pos'] : ['y0Neg']} | ||
splitSeriesAccessors={split ? ['g'] : []} | ||
stackAccessors={stacked ? ['g'] : []} | ||
/> | ||
</Chart> | ||
); | ||
}; |
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