Adds legend to line graph w/ hover & toggle #8
+381
−63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds a non customisable legend to the graph via a 'line_name'
option for each line. It takes the colour of each line and the optional
'line_name' argument and creates a legend in the top right corner of the
graph showing what each line represents.
When you hover over either a thumbnail or label for a line, the line on the
graph glows (with a drop-shadow), and you can toggle a line's visibility by
clicking its label/thumbnail in the legend.
This adds the following methods to the Line class:
These methods provide the basis for our extra functionality and can be called on
the line directly.
There's also a @lines property of the LineChart class which saves all Lines
created when drawing the graph.
This is how it looks:
In this graph we've named the first two lines (Control and Variation A) – the rest are automatically named for us. We've also hidden two of the lines from the graph by clicking on their legend labels (clicking the colour thumbnail also toggles line visibility), and whenever you hover over a line label, thumbnail or dot the line in question glows.
This has been tested in all major browsers (IE7+, Chrome, Safari, FF and Opera) and works well.
I've added a few sets to the Line class to make this easy to work with, though hopefully it'll only take a quick review and to be good to merge into master :)
Also, this is how it looks with the axis label pull request (from commit 0f3d496):
What are your thoughts?