Skip to content

Commit

Permalink
chore(charts): Simplify pattern visibility
Browse files Browse the repository at this point in the history
Closes #7541
  • Loading branch information
dlabrecq committed Jun 13, 2022
1 parent c2e4c27 commit f8617fa
Show file tree
Hide file tree
Showing 28 changed files with 296 additions and 269 deletions.
36 changes: 14 additions & 22 deletions packages/react-charts/src/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import {
getComputedLegend,
getLabelTextSize,
getPaddingForSide,
getPatternId,
getPatternDefs,
getDefaultColorScale,
getDefaultData,
getDefaultPatternScale
getDefaultPatternProps
} from '../ChartUtils';
import { PatternScaleInterface } from '../ChartUtils/chart-patterns';

/**
* See https://github.com/FormidableLabs/victory/blob/master/packages/victory-core/src/index.d.ts
Expand Down Expand Up @@ -94,12 +93,14 @@ export interface ChartProps extends VictoryChartProps {
/**
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
defaultAxes?: AxesType;
/**
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
defaultPolarAxes?: AxesType;
Expand Down Expand Up @@ -307,13 +308,6 @@ export interface ChartProps extends VictoryChartProps {
* @propType number | { top: number, bottom: number, left: number, right: number }
*/
padding?: PaddingProps;
/**
* The optional ID to prefix pattern defs
*
* @example patternId="pattern"
* @beta
*/
patternId?: string;
/**
* The patternScale prop is an optional prop that defines a pattern to be applied to the children, where applicable.
* This prop should be given as an array of CSS colors, or as a string corresponding to a URL. Patterns will be
Expand All @@ -326,10 +320,11 @@ export interface ChartProps extends VictoryChartProps {
* @example patternScale={['url("#pattern:0")', 'url("#pattern:1")', 'url("#pattern:2")']}
* @beta
*/
patternScale?: string[];
patternScale?: PatternScaleInterface[];
/**
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
prependDefaultAxes?: boolean;
Expand Down Expand Up @@ -372,6 +367,7 @@ export interface ChartProps extends VictoryChartProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
sharedEvents?: { events: any[]; getEventState: Function };
Expand Down Expand Up @@ -460,18 +456,17 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
ariaTitle,
children,
colorScale,
isPatternDefs = false,
legendAllowWrap = false,
legendComponent = <ChartLegend />,
legendData,
legendPosition = ChartCommonStyles.legend.position as ChartLegendPosition,
padding,
patternScale,
showAxis = true,
themeColor,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
themeVariant,
patternId = getPatternId(),
patternScale,
isPatternDefs = false,

// destructure last
theme = getChartTheme(themeColor, showAxis),
Expand All @@ -488,12 +483,11 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
top: getPaddingForSide('top', padding, theme.chart.padding)
};

const defaultColorScale = getDefaultColorScale(colorScale as any, theme.chart.colorScale as string[]);
const defaultPatternScale = getDefaultPatternScale({
colorScale: defaultColorScale,
const { defaultColorScale, defaultPatternScale, patternId } = getDefaultPatternProps({
colorScale,
isPatternDefs,
patternScale,
patternId,
isPatternDefs
themeColorScale: theme.chart.colorScale as string[]
});

// Add pattern props for legend tooltip
Expand All @@ -503,7 +497,6 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
containerComponent.props.labelComponent.type.displayName === 'ChartLegendTooltip'
) {
labelComponent = React.cloneElement(containerComponent.props.labelComponent, {
patternId,
theme,
...(defaultPatternScale && { patternScale: defaultPatternScale }),
...containerComponent.props.labelComponent.props
Expand Down Expand Up @@ -580,7 +573,6 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
const { ...childProps } = child.props;
return React.cloneElement(child, {
colorScale,
patternId,
theme,
...(defaultPatternScale && { patternScale: defaultPatternScale }),
...childProps,
Expand All @@ -605,7 +597,7 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
>
{renderChildren()}
{getLegend()}
{isPatternDefs && getPatternDefs({ patternId, patternScale: defaultColorScale })}
{isPatternDefs && getPatternDefs({ patternId, colorScale: defaultColorScale })}
</VictoryChart>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export interface ChartAreaProps extends VictoryAreaProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
sharedEvents?: { events: any[]; getEventState: Function };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export interface ChartAxisProps extends VictoryAxisProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
sharedEvents?: { events: any[]; getEventState: Function };
Expand Down
2 changes: 2 additions & 0 deletions packages/react-charts/src/components/ChartBar/ChartBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export interface ChartBarProps extends VictoryBarProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
polar?: boolean;
Expand Down Expand Up @@ -348,6 +349,7 @@ export interface ChartBarProps extends VictoryBarProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
sharedEvents?: { events: any[]; getEventState: Function };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface ChartContainerProps extends VictoryContainerProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
polar?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ChartCursorContainerProps extends VictoryCursorContainerProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
children?: React.ReactElement | React.ReactElement[];
Expand Down Expand Up @@ -134,6 +135,7 @@ export interface ChartCursorContainerProps extends VictoryCursorContainerProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
polar?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface ChartCursorTooltipProps extends ChartTooltipProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
height?: number;
Expand Down Expand Up @@ -257,6 +258,7 @@ export interface ChartCursorTooltipProps extends ChartTooltipProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
width?: number;
Expand Down
12 changes: 3 additions & 9 deletions packages/react-charts/src/components/ChartDonut/ChartDonut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ChartContainer } from '../ChartContainer';
import { ChartLabel } from '../ChartLabel';
import { ChartPie, ChartPieLegendPosition, ChartPieProps } from '../ChartPie';
import { ChartCommonStyles, ChartDonutStyles, ChartThemeDefinition } from '../ChartTheme';
import { getPieLabelX, getPieLabelY, getPaddingForSide } from '../ChartUtils';
import { getPieLabelX, getPieLabelY, getPaddingForSide, PatternScaleInterface } from '../ChartUtils';

interface ChartDonutSubTitleInterface {
dy?: number;
Expand Down Expand Up @@ -361,13 +361,6 @@ export interface ChartDonutProps extends ChartPieProps {
* @propType number | Function
*/
padAngle?: NumberOrCallback;
/**
* The optional ID to prefix pattern defs
*
* @example patternId="pattern"
* @beta
*/
patternId?: string;
/**
* The patternScale prop is an optional prop that defines a pattern to be applied to the children, where applicable.
* This prop should be given as an array of CSS colors, or as a string corresponding to a URL. Patterns will be
Expand All @@ -380,7 +373,7 @@ export interface ChartDonutProps extends ChartPieProps {
* @example patternScale={['url("#pattern:0")', 'url("#pattern:1")', 'url("#pattern:2")']}
* @beta
*/
patternScale?: string[];
patternScale?: PatternScaleInterface[];
/**
* The padding props specifies the amount of padding in number of pixels between
* the edge of the chart and any rendered child components. This prop can be given
Expand All @@ -402,6 +395,7 @@ export interface ChartDonutProps extends ChartPieProps {
*
* Note: This prop should not be set manually.
*
* @private
* @hide
*/
sharedEvents?: { events: any[]; getEventState: Function };
Expand Down
Loading

0 comments on commit f8617fa

Please sign in to comment.