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

Legend #189

Merged
merged 23 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dc3142d
Add initial victory-legend
janesh-travolta Aug 24, 2016
e203fe0
updated victory-legend
janesh-travolta Aug 31, 2016
08ecee3
merged master
janesh-travolta Sep 12, 2016
358af4a
minor improvements
janesh-travolta Sep 13, 2016
7d15430
Merge pull request #116 from janesh-travolta/victory-legend
boygirl Sep 21, 2016
e3a9c31
Merge branch 'master' into legend
angelanicholas Jan 11, 2017
8846970
lint and spelling
angelanicholas Jan 18, 2017
6da5333
address PR comments and other refactoring
angelanicholas Jan 18, 2017
619fc26
update demo
angelanicholas Jan 18, 2017
62d081f
update tests
angelanicholas Jan 18, 2017
1294b67
reorder component methods
angelanicholas Jan 18, 2017
4a42957
move leftOffset calc to getLegendState
angelanicholas Jan 18, 2017
080c387
don't pass props around unnecessarily
angelanicholas Jan 18, 2017
1dadd57
fix standalone demo
angelanicholas Jan 18, 2017
d3a59df
move demo for consistency
angelanicholas Jan 18, 2017
1373951
remove state in favor of calculated props in render
angelanicholas Jan 19, 2017
88b1abf
consolidate orientation checks by storing in calculated props
angelanicholas Jan 19, 2017
e9905c8
add theme prop and move default styles
angelanicholas Jan 19, 2017
783031a
fix tests
angelanicholas Jan 19, 2017
d74b1ff
add colorScale prop
angelanicholas Jan 19, 2017
bb1252d
alphabetize props
angelanicholas Jan 19, 2017
ea7a65e
alphabetize default props, remove default padding prop
angelanicholas Jan 19, 2017
bb3a74a
allow height width padding to be specified in theme
angelanicholas Jan 19, 2017
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
Prev Previous commit
Next Next commit
add theme prop and move default styles
  • Loading branch information
angelanicholas committed Jan 19, 2017
commit e9905c8f6dd4f3e9139ee5c3d3e69946c5637b7d
2 changes: 1 addition & 1 deletion demo/victory-legend-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const LegendDemo = () => (
padding={20}
standalone={false}
orientation="horizontal"
style={{ label: { fill: "#ccc" }}}
style={{ labels: { fill: "#ccc" }}}
/>
</svg>
</div>
Expand Down
47 changes: 20 additions & 27 deletions src/victory-legend/victory-legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,9 @@ import { PropTypes as CustomPropTypes, TextSize, Helpers } from "../victory-util
import { merge, isEmpty, defaults, sumBy, maxBy } from "lodash";
import VictoryLabel from "../victory-label/victory-label";
import VictoryContainer from "../victory-container/victory-container";
import VictoryTheme from "../victory-theme/victory-theme";
import Point from "../victory-primitives/point";

const defaultStyles = {
symbol: {
fill: "black",
type: "circle"
},
label: {
fontSize: 14,
fontFamily: "'Gill Sans', 'Gill Sans MT', 'Ser­avek', 'Trebuchet MS', sans-serif",
color: "#252525",
backgroundColor: "#d9d9d9",
stroke: "transparent"
}
};
const defaultLegendData = [
{ name: "Series 1" },
{ name: "Series 2" }
Expand Down Expand Up @@ -62,6 +50,7 @@ export default class VictoryLegend extends React.Component {
labelComponent: PropTypes.element,
symbolSpacer: PropTypes.number,
gutter: PropTypes.number,
theme: PropTypes.object,
standalone: PropTypes.bool,
style: PropTypes.shape({
symbol: PropTypes.object,
Expand All @@ -80,6 +69,7 @@ export default class VictoryLegend extends React.Component {
labelComponent: <VictoryLabel/>,
containerComponent: <VictoryContainer/>,
groupComponent: <g/>,
theme: VictoryTheme.grayscale,
standalone: true,
style: {}
};
Expand All @@ -102,17 +92,21 @@ export default class VictoryLegend extends React.Component {
return padding.left + contentWidth + padding.right;
}

getCalculatedProps(props) {
let { height, width } = props;
const isHorizontal = props.orientation === "horizontal";
const padding = Helpers.getPadding(props);
getCalculatedProps() {
const { role } = this.constructor;
const { data, orientation, theme } = this.props;
let { height, width } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to define width / height in the theme too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And padding

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!


const legendTheme = theme && theme[role] && theme[role].style ? theme[role].style : {};
const isHorizontal = orientation === "horizontal";
const padding = Helpers.getPadding(this.props);
const symbolStyles = [];
const labelStyles = [];
let leftOffset = 0;

const textSizes = props.data.map((datum, i) => {
const styles = this.getComponentStyles(datum, props, "label");
symbolStyles[i] = this.getComponentStyles(datum, props, "symbol");
const textSizes = data.map((datum, i) => {
const styles = this.getStyles(datum, legendTheme, "labels");
symbolStyles[i] = this.getStyles(datum, legendTheme, "symbol");
labelStyles[i] = styles;

const textSize = TextSize.approximateTextSize(datum.name, styles);
Expand All @@ -129,14 +123,13 @@ export default class VictoryLegend extends React.Component {
width = this.calculateLegendWidth(textSizes, padding, isHorizontal);
}

return Object.assign({},
props,
{ isHorizontal, padding, textSizes, height, width, labelStyles, symbolStyles }
);
return Object.assign({}, this.props, {
isHorizontal, padding, textSizes, height, width, labelStyles, symbolStyles, theme: legendTheme
});
}

getComponentStyles(datum, props, key) {
return merge({}, defaultStyles[key], props.style[key], datum[key]);
getStyles(datum, theme, key) {
return merge({}, theme[key], this.props.style[key], datum[key]);
}

getSymbolSize(datum, fontSize) {
Expand Down Expand Up @@ -236,7 +229,7 @@ export default class VictoryLegend extends React.Component {
}

render() {
const props = this.getCalculatedProps(this.props);
const props = this.getCalculatedProps();
const group = this.renderGroup(props, this.renderLegendItems(props));
return props.standalone ? this.renderContainer(props, group) : group;
}
Expand Down
9 changes: 9 additions & 0 deletions src/victory-theme/grayscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,14 @@ export default {
},
labels: centeredLabelStyles
}
}, baseProps),
legend: assign({
style: {
symbol: {
fill: charcoal,
type: "circle"
},
labels: baseLabelStyles
}
}, baseProps)
};
9 changes: 9 additions & 0 deletions src/victory-theme/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,14 @@ export default {
},
labels: centeredLabelStyles
}
}, baseProps),
legend: assign({
style: {
symbol: {
fill: blueGrey700,
type: "circle"
},
labels: baseLabelStyles
}
}, baseProps)
};