-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(annotations): provide fallback for line annotation markers #1091
Changes from 3 commits
b495ef9
90f7dec
0496d01
2b4f5de
e58089a
4fd02b3
8159652
8c5e803
557cb8d
0ba5d9b
52ee2df
c475411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,8 +283,12 @@ function getAnchorPosition( | |
isXDomain: boolean, | ||
isChartHorizontal: boolean, | ||
specMarkerPosition?: Position, | ||
axisPosition?: Position, | ||
axisPosition?: Position | undefined, | ||
): Position { | ||
// catch the case of a chart with no axes nor specMarkerPosition for a vertical line annotation | ||
if (!axisPosition && !specMarkerPosition && isXDomain) { | ||
return Position.Bottom; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! 2b4f5de |
||
const dflPositionFromAxis = getDefaultMarkerPositionFromAxis(isXDomain, isChartHorizontal, axisPosition); | ||
|
||
if (specMarkerPosition !== undefined) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { select } from '@storybook/addon-knobs'; | ||
import React from 'react'; | ||
|
||
import { | ||
LineAnnotationDatum, | ||
Chart, | ||
LineAnnotation, | ||
AnnotationDomainTypes, | ||
BarSeries, | ||
ScaleType, | ||
Position, | ||
} from '../../src'; | ||
|
||
function generateAnnotationData(values: any[]): LineAnnotationDatum[] { | ||
return values.map((value, index) => ({ dataValue: value, details: `detail-${index}` })); | ||
} | ||
|
||
export const Example = () => { | ||
const markerPositionHorizontal = select( | ||
'horizontal marker position', | ||
[Position.Top, Position.Left, Position.Bottom, Position.Right, 'undefined'], | ||
'undefined', | ||
); | ||
const markerPositionVertical = select( | ||
'vertical marker position', | ||
[Position.Top, Position.Left, Position.Bottom, Position.Right, 'undefined'], | ||
'undefined', | ||
); | ||
return ( | ||
<Chart className="story-chart"> | ||
<LineAnnotation | ||
domainType={AnnotationDomainTypes.XDomain} | ||
id="ann" | ||
dataValues={[{ dataValue: 'bags' }]} | ||
marker={<div style={{ background: 'red' }}>Vertical</div>} | ||
markerPosition={markerPositionVertical === 'undefined' ? undefined : markerPositionVertical} | ||
/> | ||
<LineAnnotation | ||
domainType={AnnotationDomainTypes.YDomain} | ||
id="ann1" | ||
dataValues={generateAnnotationData([30])} | ||
marker={<div style={{ background: 'yellow' }}>Horizontal</div>} | ||
markerPosition={markerPositionHorizontal === 'undefined' ? undefined : markerPositionHorizontal} | ||
/> | ||
|
||
<BarSeries | ||
id="bars" | ||
name="amount" | ||
xScaleType={ScaleType.Ordinal} | ||
xAccessor="x" | ||
yAccessors={['y']} | ||
data={[ | ||
{ x: 'trousers', y: 390, val: 1222 }, | ||
{ x: 'watches', y: 23, val: 1222 }, | ||
{ x: 'bags', y: 750, val: 1222 }, | ||
{ x: 'cocktail dresses', y: 854, val: 1222 }, | ||
]} | ||
/> | ||
</Chart> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this argument is already optional when using the
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed in e58089a thank you!