FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adjust legend position for axis label by dlabrecq · Pull Request #2763 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .scss  (1) .tsx  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • Chart.tsx
      • ChartArea.md
      • chart-area.scss
This file contains hidden or 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
Expand Up @@ -23,7 +23,7 @@ import {
ChartLegendWrapper
} from "../ChartLegend";
import { ChartCommonStyles, ChartThemeDefinition } from '../ChartTheme';
import { getPaddingForSide, getTheme } from '../ChartUtils';
import { getLabelTextSize, getPaddingForSide, getTheme } from '../ChartUtils';

/**
* See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/victory/index.d.ts
Expand Down Expand Up @@ -363,7 +363,7 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
ariaTitle,
children,
containerComponent = allowZoom ? <VictoryZoomContainer /> : <ChartContainer />,
legendComponent = <ChartLegend />,
legendComponent = <ChartLegend/>,
legendData,
legendPosition = ChartCommonStyles.legend.position as ChartLegendPosition,
padding,
Expand Down Expand Up @@ -411,10 +411,21 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
}
let dx = 0;
let dy = defaultPadding.top;
let xAxisLabelHeight = 0;
let legendTitleHeight = legend.props.title ? 10 : 0;

// Adjust for axis label
React.Children.toArray(children).map((child: any) => {
if (child.type.role === 'axis' && child.props.label && !child.props.dependentAxis) {
xAxisLabelHeight = getLabelTextSize({text: child.props.label, theme}).height + 10;
legendTitleHeight = 0;
}
});

if (legendPosition === ChartLegendPosition.bottom) {
dy += ChartCommonStyles.legend.margin;
dy += ChartCommonStyles.legend.margin + xAxisLabelHeight + legendTitleHeight;
} else if (legendPosition === ChartLegendPosition.bottomLeft) {
dy += ChartCommonStyles.legend.margin;
dy += ChartCommonStyles.legend.margin + xAxisLabelHeight + legendTitleHeight;
dx += defaultPadding.left - 10;
} else if (legendPosition === ChartLegendPosition.right) {
dx += defaultPadding.left;
Expand Down
This file contains hidden or 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
Expand Up @@ -33,7 +33,7 @@ import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '
width={800}
>
<ChartAxis />
<ChartAxis dependentAxis showGrid />
<ChartAxis dependentAxis showGrid/>
<ChartGroup>
<ChartArea
data={[
Expand Down Expand Up @@ -83,9 +83,9 @@ import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor } from '@patte
containerComponent={<ChartVoronoiContainer labels={datum => `${datum.name}: ${datum.y}`} />}
legendData={[{ name: 'Cats' }, { name: 'Birds' }, { name: 'Dogs' }]}
legendPosition="bottom"
height={225}
height={250}
padding={{
bottom: 75, // Adjusted to accomodate legend
bottom: 100, // Adjusted to accomodate legend
left: 50,
right: 50,
top: 50,
Expand All @@ -94,8 +94,8 @@ import { Chart, ChartArea, ChartAxis, ChartGroup, ChartThemeColor } from '@patte
themeColor={ChartThemeColor.cyan}
width={650}
>
<ChartAxis />
<ChartAxis dependentAxis showGrid />
<ChartAxis label="Animals"/>
<ChartAxis dependentAxis showGrid/>
<ChartGroup>
<ChartArea
data={[
Expand Down
This file contains hidden or 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
@@ -1,7 +1,7 @@
.ws-preview {
& > * {
.area-chart-legend-bottom {
height: 225px;
height: 250px;
width: 650px;
}

Expand Down
This file contains hidden or 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
Expand Up @@ -151,31 +151,33 @@ export const ChartLegendWrapper: React.FunctionComponent<ChartLegendWrapperProps
const renderChildren = () =>
React.Children.toArray(children).map((child: any) => {
const childProps = child.props ? child.props : {};
const legendX = getLegendX({
chartWidth,
dx,
legendData: childProps.data,
legendOrientation: childProps.legendOrientation ? childProps.legendOrientation : orientation,
legendPosition: position,
legendProps: childProps,
theme,
svgWidth
});
const legendY = getLegendY({
chartHeight,
chartType,
dy,
legendData: childProps.data,
legendOrientation: childProps.legendOrientation ? childProps.legendOrientation : orientation,
legendProps: childProps,
legendPosition: position,
theme
});
if (childProps.data) {
return React.cloneElement(child as React.ReactElement<any>, {
orientation,
standalone: false,
theme,
x: getLegendX({
chartWidth,
dx,
legendData: childProps.data,
legendOrientation: childProps.legendOrientation ? childProps.legendOrientation : orientation,
legendPosition: position,
legendProps: childProps,
theme,
svgWidth
}),
y: getLegendY({
chartHeight,
chartType,
dy,
legendData: childProps.data,
legendOrientation: childProps.legendOrientation ? childProps.legendOrientation : orientation,
legendProps: childProps,
legendPosition: position,
theme
}),
x: legendX > 0 ? legendX : 0,
y: legendY > 0 ? legendY : 0,
...childProps,
});
}
Expand Down

Back | FazBrowse Home | New Git URL