-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat: Custom point renderer #2245
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 } from '@storybook/addon-knobs'; | ||
import React from 'react'; | ||
|
||
import { | ||
Axis, | ||
Chart, | ||
LineSeries, | ||
niceTimeFormatByDay, | ||
Position, | ||
ScaleType, | ||
Settings, | ||
timeFormatter, | ||
} from '@elastic/charts'; | ||
import { KIBANA_METRICS } from '@elastic/charts/src/utils/data_samples/test_dataset_kibana'; | ||
|
||
import { ChartsStory } from '../../types'; | ||
import { useBaseTheme } from '../../use_base_theme'; | ||
import { getColorPicker } from '../utils/components/get_color_picker'; | ||
|
||
const dateFormatter = timeFormatter(niceTimeFormatByDay(1)); | ||
const data = KIBANA_METRICS.metrics.kibana_os_load.v1.data.slice(10, 150); | ||
|
||
export const Example: ChartsStory = (_, { title, description }) => { | ||
const showColorPicker = boolean('Show color picker', false); | ||
|
||
return ( | ||
<Chart title={title} description={description}> | ||
<Settings | ||
showLegend | ||
showLegendExtra | ||
legendPosition={Position.Right} | ||
baseTheme={useBaseTheme()} | ||
legendColorPicker={showColorPicker ? getColorPicker('leftCenter') : undefined} | ||
/> | ||
<Axis id="bottom" position={Position.Bottom} showOverlappingTicks tickFormat={dateFormatter} /> | ||
<Axis | ||
id="left" | ||
title={KIBANA_METRICS.metrics.kibana_os_load.v1.metric.title} | ||
position={Position.Left} | ||
tickFormat={(d) => `${Number(d).toFixed(0)}%`} | ||
/> | ||
<LineSeries | ||
id="test" | ||
xScaleType={ScaleType.Time} | ||
yScaleType={ScaleType.Linear} | ||
xAccessor={0} | ||
yAccessors={[1]} | ||
color="lightgray" // never overridden | ||
pointStyleAccessor={(datum) => { | ||
return { | ||
shape: (ctx, coordinates) => { | ||
ctx.beginPath(); | ||
ctx.ellipse(coordinates.x, coordinates.y, 5, 5, Math.PI / 4, 0, 2 * Math.PI); | ||
ctx.fill(); | ||
ctx.fillText(Math.floor(datum.y1), coordinates.x - 5, coordinates.y - 10); | ||
}, | ||
visible: true; | ||
}; | ||
}} | ||
data={data.map(([x, y], i) => [x, y + 60, i])} | ||
/> | ||
</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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hey @qbob1 thanks again for contributing to elastic charts!
Looking over these changes I wonder what is the primary goal or feature that you are looking for from these changes?
Are you looking for a way to define unique shape for the points aside from the limited
PointShape
s? In that case we could add an option to provide aPath2D
, to support any abstract path/symbol.Or are you looking for support of value labels on line/area charts (i.e. #797)?
The reason I ask is because we are not big fans of exposing the
ctx
directly to the user to do with as they please. With that said I'm happy to hear your thoughts and get the changes you are looking for added to the library.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.
Totally understandable!
Fortunately, I was able to find a work around for #797 and posted a comment to help anyone else that may need to display the labels.
I'd say a Path2D would be excellent and a much cleaner solution.
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.
Thanks for adding that comment to #797.
Perfect, if you'd like to refactor this PR or create a fresh PR to add the option to assign a
Path2D
toPointStyle.shape
I'll take another look. Otherwise it'll probably be a few weeks before we get around to adding it ourselves.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.
I wouldn't mind taking a crack at it. Any preference on implementation?