-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
[SIP-6] removed get_data for BigNumber #5861
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import * as color from 'd3-color'; | ||
|
||
import BigNumberVis, { renderTooltipFactory } from './BigNumber'; | ||
import { d3FormatPreset } from '../../modules/utils'; | ||
|
||
const TIME_COLUMN = '__timestamp'; | ||
|
||
function transform(data, formData) { | ||
let bigNumber; | ||
let trendlineData; | ||
const metricName = formData.metric.label || formData.metric; | ||
const compareSuffix = formData.compare_suffix || ''; | ||
const compareLag = +formData.compare_lag || 0; | ||
const supportTrendline = formData.viz_type === 'big_number'; | ||
const showTrendline = supportTrendline && formData.show_trend_line; | ||
let percentChange = 0; | ||
const subheader = formData.subheader || ''; | ||
let formattedSubheader = subheader; | ||
if (supportTrendline) { | ||
const sortedData = [...data].sort((a, b) => a[TIME_COLUMN] - b[TIME_COLUMN]); | ||
bigNumber = sortedData[sortedData.length - 1][metricName]; | ||
if (compareLag > 0) { | ||
const compareIndex = sortedData.length - (compareLag + 1); | ||
if (compareIndex >= 0) { | ||
const compareValue = sortedData[compareIndex][metricName]; | ||
percentChange = compareValue === 0 | ||
? 0 : (bigNumber - compareValue) / Math.abs(compareValue); | ||
const formatPercentChange = d3.format('+.1%'); | ||
formattedSubheader = `${formatPercentChange(percentChange)} ${compareSuffix}`; | ||
} | ||
} | ||
trendlineData = showTrendline | ||
? sortedData.map(point => ({ x: point[TIME_COLUMN], y: point[metricName] })) | ||
: null; | ||
} else { | ||
bigNumber = data[0][metricName]; | ||
trendlineData = null; | ||
} | ||
|
||
let className = ''; | ||
if (percentChange > 0) { | ||
className = 'positive'; | ||
} else if (percentChange < 0) { | ||
className = 'negative'; | ||
} | ||
|
||
return { | ||
bigNumber, | ||
trendlineData, | ||
className, | ||
subheader: formattedSubheader, | ||
showTrendline, | ||
}; | ||
} | ||
|
||
function adaptor(slice, payload) { | ||
const { formData, containerId } = slice; | ||
|
||
const transformedData = transform(payload.data, formData); | ||
const startYAxisAtZero = formData.start_y_axis_at_zero; | ||
const formatValue = d3FormatPreset(formData.y_axis_format); | ||
let userColor; | ||
if (formData.color_picker) { | ||
const { r, g, b } = formData.color_picker; | ||
userColor = color.rgb(r, g, b).hex(); | ||
} | ||
|
||
ReactDOM.render( | ||
<BigNumberVis | ||
width={slice.width()} | ||
height={slice.height()} | ||
formatBigNumber={formatValue} | ||
startYAxisAtZero={startYAxisAtZero} | ||
mainColor={userColor} | ||
gradientId={`big_number_${containerId}`} | ||
renderTooltip={renderTooltipFactory(formatValue)} | ||
{...transformedData} | ||
/>, | ||
document.getElementById(containerId), | ||
); | ||
} | ||
|
||
export default adaptor; |
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,5 @@ | ||
import adaptor from './adaptor'; | ||
import BigNumber from './BigNumber'; | ||
|
||
export { BigNumber }; | ||
export default adaptor; |
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
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.
This was used only in this file. Not sure it is useful to export now. (ok to expert if there are other places using or unit test)
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.
Actually it is also used in adaptor for the prop
renderTooltip
. That is why I exported it :)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 missed that. Thank you!