Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Theme bugs #407

Merged
merged 4 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/components/victory-axis/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default {

const styles = this.getEvaluatedStyles(style, tick, index);
const tickLayout = {
position: this.getTickPosition(styles.tickStyle, orientation, isVertical),
position: this.getTickPosition(styles, orientation, isVertical),
transform: this.getTickTransform(scale(ticks[index]), globalTransform, isVertical)
};

Expand All @@ -204,7 +204,6 @@ export default {
scale(ticks[index]) + globalTransform.y : gridOffset.y + globalTransform.y
}
};

childProps[index] = {
axis: axisProps,
axisLabel: axisLabelProps,
Expand Down Expand Up @@ -271,7 +270,8 @@ export default {
const scaleTicks = scale.ticks(props.tickCount);
const ticks = Array.isArray(scaleTicks) && scaleTicks.length ? scaleTicks : scale.domain();
if (props.crossAxis) {
return includes(ticks, 0) ? without(ticks, 0) : ticks;
const filteredTicks = includes(ticks, 0) ? without(ticks, 0) : ticks;
return filteredTicks.length ? filteredTicks : ticks;
}
return ticks;
}
Expand Down Expand Up @@ -349,9 +349,11 @@ export default {
},

getTickPosition(style, orientation, isVertical) {
const size = style.size || 0;
const padding = style.padding || 0;
const tickSpacing = size + padding;
const {tickStyle, labelStyle} = style;
const size = tickStyle.size || 0;
const tickPadding = tickStyle.padding || 0;
const labelPadding = labelStyle.padding || 0;
const tickSpacing = size + tickPadding + labelPadding;
const sign = orientationSign[orientation];
return {
x: isVertical ? sign * tickSpacing : 0,
Expand Down
17 changes: 7 additions & 10 deletions src/components/victory-chart/victory-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,25 +259,22 @@ export default class VictoryChart extends React.Component {

render() {
const props = this.state && this.state.nodesWillExit ?
this.state.oldProps : this.props;
this.state.oldProps || this.props : this.props;
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "chart");
const { standalone, events, eventKey } = modifiedProps;
const childComponents = ChartHelpers.getChildComponents(modifiedProps,
modifiedProps.defaultAxes);
const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);
const container = modifiedProps.standalone && this.getContainer(modifiedProps, calculatedProps);
const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
if (modifiedProps.events) {
const group = this.renderGroup(newChildren, calculatedProps.style.parent);
const container = standalone ? this.getContainer(modifiedProps, calculatedProps) : group;
if (events) {
return (
<VictorySharedEvents events={modifiedProps.events}
eventKey={modifiedProps.eventKey}
container={container}
>
<VictorySharedEvents events={events} eventKey={eventKey} container={container}>
{newChildren}
</VictorySharedEvents>
);
}

const group = this.renderGroup(newChildren, calculatedProps.style.parent);
return modifiedProps.standalone ? React.cloneElement(container, container.props, group) : group;
return standalone ? React.cloneElement(container, container.props, group) : group;
}
}
23 changes: 9 additions & 14 deletions src/components/victory-group/victory-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fallbackProps = {
export default class VictoryGroup extends React.Component {
static displayName = "VictoryGroup";

static role = "group-wrapper";
static role = "group";

static propTypes = {
animate: PropTypes.object,
Expand Down Expand Up @@ -220,7 +220,7 @@ export default class VictoryGroup extends React.Component {
getColorScale(props, child) {
const role = child.type && child.type.role;
const colorScaleOptions = child.props.colorScale || props.colorScale;
if (role !== "group-wrapper" && role !== "stack-wrapper") {
if (role !== "group" && role !== "stack") {
return undefined;
}
return props.theme && props.theme.group ? colorScaleOptions || props.theme.group.colorScale
Expand Down Expand Up @@ -262,7 +262,7 @@ export default class VictoryGroup extends React.Component {
colorScale: this.getColorScale(props, child),
key: index,
labelComponent: labelComponent || child.props.labelComponent,
xOffset: role === "stack-wrapper" ? xOffset : undefined
xOffset: role === "stack" ? xOffset : undefined
}, childProps));
}
return newChildren;
Expand All @@ -289,30 +289,25 @@ export default class VictoryGroup extends React.Component {

render() {
const props = this.state && this.state.nodesWillExit ?
this.state.oldProps : this.props;
this.state.oldProps || this.props : this.props;
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "group");
const { theme, standalone, events, eventKey } = modifiedProps;
const defaultStyle = theme && theme.group && theme.group.style ? theme.group.style : {};
const style = Helpers.getStyles(modifiedProps.style, defaultStyle, "auto", "100%");
const childComponents = React.Children.toArray(modifiedProps.children);
const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents, style,
fallbackProps.props);

const container = standalone && this.getContainer(modifiedProps, calculatedProps);
const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
if (modifiedProps.events) {
const group = this.renderGroup(newChildren, style.parent);
const container = standalone ?
this.getContainer(modifiedProps, calculatedProps) : group;
if (events) {
return (
<VictorySharedEvents
events={events}
eventKey={eventKey}
container={container}
>
<VictorySharedEvents events={events} eventKey={eventKey} container={container}>
{newChildren}
</VictorySharedEvents>
);
}
const group = this.renderGroup(newChildren, style.parent);

return standalone ? React.cloneElement(container, container.props, group) : group;
}
}
20 changes: 7 additions & 13 deletions src/components/victory-stack/victory-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fallbackProps = {
export default class VictoryStack extends React.Component {
static displayName = "VictoryStack";

static role = "stack-wrapper";
static role = "stack";

static propTypes = {
animate: PropTypes.object,
Expand Down Expand Up @@ -194,7 +194,7 @@ export default class VictoryStack extends React.Component {
getColorScale(props, child) {
const role = child.type && child.type.role;
const colorScaleOptions = child.props.colorScale || props.colorScale;
if (role !== "group-wrapper" && role !== "stack-wrapper") {
if (role !== "group" && role !== "stack") {
return undefined;
}
return props.theme ? colorScaleOptions || props.theme.props.colorScale
Expand Down Expand Up @@ -248,31 +248,25 @@ export default class VictoryStack extends React.Component {

render() {
const props = this.state && this.state.nodesWillExit ?
this.state.oldProps : this.props;
this.state.oldProps || this.props : this.props;
const modifiedProps = Helpers.modifyProps(props, fallbackProps, "stack");
const { theme, standalone, events, eventKey} = modifiedProps;
const fallbackStyle = theme && theme.stack && theme.stack.style ?
theme.stack.style : {};
const style = Helpers.getStyles(modifiedProps.style, fallbackStyle, "auto", "100%");
const childComponents = React.Children.toArray(modifiedProps.children);

const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents, style);

const container = standalone && this.getContainer(modifiedProps, calculatedProps);
const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
const group = this.renderGroup(newChildren, style.parent);
const container = standalone ? this.getContainer(modifiedProps, calculatedProps) : group;
if (events) {
return (
<VictorySharedEvents
events={events}
eventKey={eventKey}
container={container}
>
<VictorySharedEvents events={events} eventKey={eventKey} container={container}>
{newChildren}
</VictorySharedEvents>
);
}
const group = this.renderGroup(newChildren, style.parent);

return modifiedProps.standalone ? React.cloneElement(container, container.props, group) : group;
return standalone ? React.cloneElement(container, container.props, group) : group;
}
}
2 changes: 1 addition & 1 deletion src/helpers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default {
getChildStyle(child, index, calculatedProps) {
const { style } = calculatedProps;
const role = child.type && child.type.role;
const defaultFill = role === "stack-wrapper" ?
const defaultFill = role === "stack" ?
undefined : this.getColor(calculatedProps, child, index);
const defaultColor = role === "line" ?
{fill: "none", stroke: defaultFill} : {fill: defaultFill};
Expand Down