-
-
Notifications
You must be signed in to change notification settings - Fork 205
fix: pass svgEl instead of g element to addLegend #104
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,12 +128,11 @@ class Pie { | |||||||||||||||||||||||
| const legendItems = this.data.datasets[0].data | ||||||||||||||||||||||||
| .map((data, i) => ({ color: this.options.dataColors[i], text: this.data.labels[i] })); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // move legend down to prevent overlaping with title | ||||||||||||||||||||||||
| const legendG = this.svgEl.append('g') | ||||||||||||||||||||||||
| .attr('transform', 'translate(0, 30)'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (this.options.showLegend) { | ||||||||||||||||||||||||
| addLegend(legendG, { | ||||||||||||||||||||||||
| const legendItems = this.data.datasets | ||||||||||||||||||||||||
| .map((data, i) => ({ color: this.options.dataColors[i], text: data.label || '' })); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| addLegend(this.svgEl, { | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| addLegend(this.svgEl, { | |
| // If there is a title, render the legend in a translated group so it | |
| // appears below the title (which is drawn at y = 30). | |
| let legendParent = this.svgEl; | |
| if (this.title) { | |
| legendParent = this.svgEl.append('g') | |
| .attr('class', 'xkcd-legend-group') | |
| .attr('transform', 'translate(0, 30)'); | |
| } | |
| addLegend(legendParent, { |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -229,11 +229,7 @@ class Radar { | |||||||||||||||||||
| const legendItems = this.data.datasets | ||||||||||||||||||||
| .map((data, i) => ({ color: this.options.dataColors[i], text: data.label || '' })); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // move legend down to prevent overlaping with title | ||||||||||||||||||||
| const legendG = this.svgEl.append('g') | ||||||||||||||||||||
| .attr('transform', 'translate(0, 30)'); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| addLegend(legendG, { | ||||||||||||||||||||
| addLegend(this.svgEl, { | ||||||||||||||||||||
|
||||||||||||||||||||
| addLegend(this.svgEl, { | |
| // If a title is present, shift the legend down to avoid overlapping it | |
| let legendParent = this.svgEl; | |
| if (this.options.title) { | |
| legendParent = this.svgEl.append('g') | |
| .attr('transform', 'translate(0,30)'); | |
| } | |
| addLegend(legendParent, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pie: legendItems is computed from slice labels (datasets[0].data + this.data.labels) but then shadowed inside the showLegend block with a different legendItems derived from this.data.datasets (dataset labels). This makes the pie legend incorrect (often only 1 item) and also leaves the first legendItems unused. Use a single legendItems based on slice labels for the legend, and avoid redeclaring/shadowing it in the block.