-
Notifications
You must be signed in to change notification settings - Fork 7
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
tweak(tupaiaWeb): RN-249: getting x-Name in viz export #5886
Changes from 5 commits
f0d30e7
ab1ec2a
fadb0a0
add6eb8
72ad0d6
7283ac3
90f95de
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import React from 'react'; | ||
|
@@ -41,13 +41,13 @@ const renderXAxisLabel = ( | |
label: string | undefined, | ||
fillColor: string | undefined, | ||
isEnlarged: boolean, | ||
isExporting: boolean, | ||
isExporting: boolean | ||
): LabelProps | undefined => { | ||
if (label && isEnlarged && !isExporting) { | ||
if (label && isEnlarged) { | ||
return { | ||
value: label, | ||
fill: fillColor, | ||
offset: -5, | ||
offset: isExporting ? -50 : -5, | ||
position: 'insideBottom', | ||
}; | ||
} | ||
|
@@ -76,6 +76,7 @@ interface XAxisProps { | |
|
||
export const XAxis = ({ config, report, isExporting = false, isEnlarged = false }: XAxisProps) => { | ||
const fillColor = isExporting ? DARK_BLUE : getContrastTextColor(); | ||
const tickMargin = isExporting ? 20 : 0; | ||
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. This is the space between the x-axis label and tick label. |
||
const { Bar, Composed } = ChartType; | ||
const { chartType, chartConfig } = config; | ||
const { data = [] } = report; | ||
|
@@ -154,6 +155,7 @@ export const XAxis = ({ config, report, isExporting = false, isEnlarged = false | |
return { left: 0, right: 10 }; | ||
}; | ||
|
||
|
||
const renderVerticalTick = (tickProps: TickProps & { x: number; y: number }) => { | ||
const { payload, x, y } = tickProps; | ||
|
||
|
@@ -177,7 +179,7 @@ export const XAxis = ({ config, report, isExporting = false, isEnlarged = false | |
tick={getXAxisTickMethod()} | ||
tickFormatter={formatXAxisTick} | ||
padding={getXAxisPadding()} | ||
tickSize={6} | ||
tickMargin={tickMargin} | ||
{...(isTimeSeries ? AXIS_TIME_PROPS : { dataKey: 'name' })} | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,9 @@ const getRealDataKeys = (chartConfig: CartesianChartConfig['chartConfig'] | {}) | |
const getLegendAlignment = ( | ||
legendPosition: LegendPosition, | ||
isExporting: boolean, | ||
): Pick<LegendProps, 'align' | 'verticalAlign' | 'layout'> => { | ||
): Pick<LegendProps, 'align' | 'verticalAlign'> => { | ||
if (isExporting) { | ||
return { verticalAlign: 'top', align: 'right', layout: 'vertical' }; | ||
return { verticalAlign: 'top', align: 'right' }; | ||
} | ||
if (legendPosition === 'bottom') { | ||
return { verticalAlign: 'bottom', align: 'center' }; | ||
|
@@ -218,7 +218,7 @@ export const CartesianChart = ({ | |
const aspect = !isEnlarged && !isMobileSize && !isExporting ? 1.6 : undefined; | ||
const height = getHeight(isExporting, isEnlarged, hasLegend, isMobileSize); | ||
|
||
const { verticalAlign, align, layout } = getLegendAlignment(legendPosition, isExporting); | ||
const { verticalAlign, align } = getLegendAlignment(legendPosition, isExporting); | ||
|
||
const presentationOptions = 'presentationOptions' in config ? config.presentationOptions : {}; | ||
|
||
|
@@ -252,7 +252,6 @@ export const CartesianChart = ({ | |
<Legend | ||
verticalAlign={verticalAlign} | ||
align={align} | ||
layout={layout} | ||
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. The 'layout' property (whether 'horizontal' or 'vertical') does not affect the custom component as expected. This is because the component already has its own styling, including alignment and flex properties. Therefore, the layout property is not needed in this case. |
||
content={getCartesianLegend({ | ||
chartConfig, | ||
getIsActiveKey, | ||
|
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 is intended to prevent overlapping between tick labels and the x-axis. Given the tick labels are restricted to a maximum number of characters (using ellipses for longer text) this approach should resolve the issue.