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

Legend Symbol Parameter [New Feature] #4811

Closed
wants to merge 15 commits into from
Closed

Legend Symbol Parameter [New Feature] #4811

wants to merge 15 commits into from

Conversation

touletan
Copy link
Contributor

@touletan touletan commented Oct 4, 2017

New Feature proposed to display symbol on legend
Legend Symbol Parameter [New Feature] #4804

@benmccann
Copy link
Contributor

@touletan you can push updates to an existing PR. you didn't really have to close #4806. please make updates on the same PR in the future. let us know if you're not sure how to do that

legendSymbolLarge: Boolean

// Width of legend symbol used if legendSymbolLarge is true
boxWidth: Number
Copy link
Member

Choose a reason for hiding this comment

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

My only comment here is that I think it would be better to remove legendSymbolLarge and imply it if boxWidth is set. So if boxWidth !== undefined then it will be used, otherwise it will be set to fontSize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if I'm not wrong, boxWidth is defaulted to 40 so it will be always defined. If we remove default value it may impact current users upgrading to that new version.

Copy link
Member

Choose a reason for hiding this comment

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

ahh, I missed that. To make that clearer I would suggest a rename to useFontSize or something. Let's wait to rename it until @simonbrunel gets a chance to review this

@@ -44,112 +44,121 @@ var exports = module.exports = {
}
},

drawPoint: function(ctx, style, radius, x, y) {
var type, edgeLength, xOffset, yOffset, height, size;
drawPoint: function(ctx, style, width, height, x, y, isLineWidthZero) {
Copy link
Member

Choose a reason for hiding this comment

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

what is isLineWidthZero used for here?

Copy link
Contributor Author

@touletan touletan Oct 6, 2017

Choose a reason for hiding this comment

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

For polygon (circle, rect, ....) if line width is 0, then no border are displayed (no strike).
This is replication of the current behavior for the rect symbol. Not doing this may impact the current users upgrading to that new version even if they don't change anything to their code (regression).

@simonbrunel
Copy link
Member

The options logic path seems a bit unclear and I don't think the helpers.canvas.drawPoint should be changed (it's a public method and modifying its signature like you did is a breaking change). Though, I'm not sure to get the result of that feature very well, @touletan can you please post screenshots of the different use cases you are trying to implement?

@touletan
Copy link
Contributor Author

touletan commented Oct 6, 2017

@simonbrunel , my specific need is to use a large line as legend symbol while keeping the dot as point style on the lines.
image

I did few additional changes to be able to use other symbols that were already available as points.
image

All the logic about usePointStyle is to avoid breaking that current functionality.

Agree about the helper signature, it could break external plugin using it. I propose the rename the new method and keep the same logic in it. The code from the current method will be changed to call the new method from there and parameter values will be defaulted/updated so the outcome is the same.

@simonbrunel
Copy link
Member

I think it's fine to add a new helpers.canvas.(draw)Symbol that split the radius into width and height and have drawPoint calling this method. Though, I don't like the extra isLineWidthZero parameter, which seems to only prevent ctx.stroke.

What about a new helpers.canvas.symbol method that simply creates the shape (no ctx.fill or ctx.stroke)? The calling code would be responsible to fill and/or stroke this shape:

drawPoint: (...) {
    helpers.canvas.symbol(ctx, style, w, h, x, y); // would be exports.symbol(...)
    ctx.stroke();
    ctx.fill();
}

The legend would use only the helpers.canvas.symbol method.

Then I would maybe expose the following dataset/legend options:

legend: {             // nested options under the dataset
    symbol: 'rect',   // default to rect
    boxWidth: ...
}

if usePointStyle is true, it would override symbol and boxWidth.

@touletan
Copy link
Contributor Author

touletan commented Oct 6, 2017

sounds like a plan. @etimberg, any other comments before I start working on it?

@touletan
Copy link
Contributor Author

touletan commented Oct 6, 2017

@simonbrunel, ctx.fill() is not required for each symbol, so it should stay in the method logic.

@etimberg
Copy link
Member

etimberg commented Oct 7, 2017

@touletan I have no other comments. 😄

@touletan
Copy link
Contributor Author

touletan commented Oct 7, 2017

@etimberg , @simonbrunel , @benmccann , new version completed and ready for review.

Dominic Jean and others added 2 commits October 7, 2017 12:31
…. Symbol type,, boxWidth, border Color and border Width can be defined at dataset level
@etimberg
Copy link
Member

@simonbrunel have you had a chance to review this since it was last changed?

@touletan
Copy link
Contributor Author

updates done

@touletan
Copy link
Contributor Author

should be good now

@benmccann
Copy link
Contributor

@touletan this PR needs to be rebased before it can be merged

@benmccann
Copy link
Contributor

@touletan just a reminder that this PR needs to be rebased

@touletan
Copy link
Contributor Author

touletan commented Jul 17, 2018 via email

@benmccann
Copy link
Contributor

I would recommend developing each feature on a new branch. You are on the master branch which I would recommend you not to use in the future

This might not be exactly right, but hopefully will work or be pretty close:

git remote add upstream git@github.com:chartjs/Chart.js.git
git fetch upstream
git merge upstream/master (at this point you will have merge conflicts and will need to fix them)
git add . (to mark all merge conflicts as fixed)
git rebase --continue
git push -f

@touletan
Copy link
Contributor Author

After additional testing, I removed the code related to the point rotation, since it was causing issue with the legend symbol position. I need help to figure out how to re-introduce point rotation ....

@touletan
Copy link
Contributor Author

that version is good for review.

@benmccann
Copy link
Contributor

@touletan I'm very sorry this PR will need to be rebased again. Would you be able to update it?

@benmccann
Copy link
Contributor

Thanks @touletan! And sorry again for the delay on getting this in. We are trying to get through the backlog of open reviews. I'm afraid it's hard for us all to find enough spare time, but hopefully we will make it through them all eventually

}
var radius = width / 2;
var yRadius = height / 2;
var padLeft = isPoint ? radius - width / 2 / Math.sqrt(2) : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment explaining why padding is necessary and what isPoint is doing? I'm not sure what that part is for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added comments on that. In the production version some symbols can only be called as point and they are not usign the full width since the size is based on the radius. When is used as a legend, I want to be sure that the symbol width = the width value pass as parameter. So to not impact the current behavior (when symbol is called for a point) I did that logic for the impacted symbols. I.e. Add padding when called as a point (not usign the full width) and use the full width (no padding) when called as a legend symbol.

@simonbrunel simonbrunel removed this from the Version 2.7.3 milestone Oct 15, 2018
@@ -44,8 +45,13 @@ defaults._set('global', {
// lineDashOffset :
// lineJoin :
// lineWidth :
// pointStyle: symbol use on legend when usePointStyle is set
// legendSymbol : Symbol use on legend if not usePointStyle
// boxWidth : width of legend symbol if not userPointStyle
Copy link
Member

Choose a reason for hiding this comment

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

userPointStyle should be usePointStyle.
I would also reword these to something like:

			// pointStyle: symbol used on legend when 'usePointStyle' is true
			// legendSymbol : symbol used on legend when usePointStyle is false
			// boxWidth : width of legend symbol when usePointStyle is false

@benmccann
Copy link
Contributor

@touletan would you be able to rebase this PR?

@benmccann
Copy link
Contributor

@touletan I just wanted to check in one last time to see if you still have an interest in moving forward with this PR. It's been needing to be rebased for quite awhile. We'll close it as inactive if we don't hear back soon though you're always welcome to reopen it in the future when you find time to work on it again

@touletan
Copy link
Contributor Author

touletan commented Apr 6, 2019 via email

@benmccann
Copy link
Contributor

@touletan I'm going to close this PR as inactive for the moment to help us keep track of which PRs need review, but please feel free to reopen if you get a chance to rebase and we'll be happy to take a look at it

@benmccann benmccann closed this May 20, 2019
@flaushi
Copy link

flaushi commented Oct 19, 2019

I'd be in need of this boxHeight option... thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants