Skip to content
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

Add missing contents property to legend option #494

Merged
merged 2 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 41 additions & 1 deletion packages/clay-charts/demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@
margin: 20px;
padding: 10px;
}

.pie-legend {
float: right;
padding: 5px;
position: relative;
right: 50px;
text-transform: uppercase;
top: -150px;
}
.pie-legend a {
background: none;
color: #000;
font-weight: bold;
padding: 5px;
text-decoration: none;
}
.pie-legend a:hover {
background: #000;
color: #fff;
}
</style>


Expand Down Expand Up @@ -125,6 +145,7 @@ <h2>Scatter</h2>
<div class="clay-chart-example">
<h2>Pie</h2>
<div id="pie"></div>
<div class="pie-legend"></div>
</div>

<div class="clay-chart-example">
Expand Down Expand Up @@ -320,8 +341,16 @@ <h2>Bubble</h2>
var lineChart = new metal.LineChart({
columns: dummyData.columns_1,
tooltip: {
format: {
value(d) {
return `${d}%`;
}
},
show: true
},
legend: {
position: 'right'
},
}, '#line');
createChartControls(lineChart, 'line');

Expand Down Expand Up @@ -370,7 +399,18 @@ <h2>Bubble</h2>
document.querySelector('#vertical-small'),
];
}
}
},
legend: {
contents: {
bindto: '.pie-legend',
template(title, color) {

Choose a reason for hiding this comment

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

Hey @julien

Not sure if this is applicable or not, but should we consider bringing this svg template over to Clay somehow so that it can be leveraged? Maybe even if it was just provided as a utility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it sounds like a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Robert-Frampton, should I close this pull request until we have an idea of how we want to include this svg template?

Choose a reason for hiding this comment

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

Hey @julien, since this is adding missing config, let's merge it and then do the abstraction in another issue.

return `<p><svg width="15" height="10">
<rect x="2.5" width="10" height="10" style="fill:${color}"></rect></svg>
<a href="#" class="legend-title">${title}</a>
</p>`;
},
},
},
}, '#pie');
createChartControls(pieChart, 'pie', dummyPercentData);

Expand Down
6 changes: 5 additions & 1 deletion packages/clay-charts/src/ChartBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,15 @@ ChartBase.STATE = {
/**
* Legend display options.
* @instance
* @memberof ChartBase
* @memberof ChartBas

Choose a reason for hiding this comment

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

Typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thanks

* @type {?Object|undefined}
* @default undefined
*/
legend: Config.shapeOf({
contents: Config.shapeOf({
bindto: Config.string(),
template: Config.oneOfType([Config.func(), Config.string()]),
}),
hide: Config.bool(),
position: Config.oneOf(['bottom', 'inset', 'right']),
inset: Config.shapeOf({
Expand Down