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

[FEATURE] Title alignment Left or Right options #3706

Closed
SmashedBird opened this issue Dec 14, 2016 · 35 comments
Closed

[FEATURE] Title alignment Left or Right options #3706

SmashedBird opened this issue Dec 14, 2016 · 35 comments

Comments

@SmashedBird
Copy link

In v2 the title options for "position" are top,right,left,bottom.
It would be nice to have an option for textAlign (left, center,right).
Currently, by default textAlign is center.

For exemple, I would like to have my text at the top [position:'top'] aligned to the left [textAlign:'left'] instead of center.

@Jareechang
Copy link
Contributor

@SmashedBird. I am working on this, I will PR soon.

When PR comes in:

We should be able to offer textAlign option with these selections: left, right, center 😄

@etimberg
Copy link
Member

@Jareechang in the interests of consistency, is it possible to also support alignment for vertical legends (top, bottom, center). If so, is it possible to use a single enum of values that are direction agnostic?

@Jareechang
Copy link
Contributor

support alignment for vertical legends
Yes, the text alignment will be supported for different positions (top, right, left, bottom). Is that what you mean ?

single enum of values
can you expand on what you mean by single enum of values ?

@etimberg
Copy link
Member

Yup, that's what I meant. For the top and bottom positions the text could be left, center, or right but for the left and right positions the options would be top, center, bottom.

For the enum, I was thinking 3 values start, center, end that would translate as follows

Value Title Position Alignment
start top / bottom Left
start left / right Top
center * center
end top / bottom Right
end left / right Bottom

@Jareechang
Copy link
Contributor

ah I see, thanks for expanding. That makes sense. I'll need to come up with a strategy for checking title Position with the enums.

@Jareechang
Copy link
Contributor

Jareechang commented Feb 22, 2017

hey @etimberg, looking over the enum values, I am having a difficult time implementing it with those values.

the position alignment is based on unique X and Y value for vertical or horizontal positions.

Alternatives

1. Add more enum values
May I suggest expanding values to include a new category of positions (Vertical or horizontal):

Value Title position Alignment
start_vertical top / bottom Left
start_horizontal left / right Top

....

positions: start_horizontal, start_vertical, end_vertical, end_horizontal

2. Nested K-V pairs
This is an example, but i'll most likely write this in a module with public methods for matching vertical or horizontal.

var positionToAlignment = {
    vertical: {
        top: {
            x: ...,
            y: ...
        },
        bottom: {
           ...
        },
        center: {
            ....
        }
    },
    horizontal: {
        left: {
            ...
        },
        right: {
            ...
        },
        center: {
            ...
        }
    },
};

Let me know what you think.

@etimberg
Copy link
Member

@Jareechang in your proposal, what would happen if the user set start_horizontal but the legend was on the left or the right side?

@Jareechang
Copy link
Contributor

Jareechang commented Feb 23, 2017

well, in the case, we would most likely need to enforce / validate that in our "pattern matcher" when getting the enum values.

Steps:

  1. Take in user inputs
  2. Pattern matcher — match inputs to correct enum values
  3. Get X and Y values from given enum values

rough Example:
Matcher

match -> 
   isHorizontal ? 
        isValid ? 
             returnValueBasedOnAlignment
   isVertical ? 
         isValid ?
              returnValueBasedOnAlignment
input: { titlePosition: 'top / bottom', alignment: 'Left' } 
    -> START_HORIZONTAL

input: { titlePosition: 'left / right', alignment: 'Left' } 
    -> CENTER (default to center because invalid user input)

@simonbrunel
Copy link
Member

simonbrunel commented Feb 23, 2017

@Jareechang if we need a method that returns x and y for position and align, it's fine to have these two arguments, no need for extra options values. This is a simple case and I don't think we need any JavaScript "kind-of" enum, let's compare strings since it should not be used at so many places.

These options should satisfy @SmashedBird and @etimberg requests (consistent with this proposal):

  • title.position: position of the box around the chart (top, left, right, bottom)
  • title.align: title alignment inside the layout box (start, center, end, stretch)
  • title.textAlign: horizontal alignment of text (left, center and right)

title.position is already implemented and textAlign seems directly mapped to context.textAlign.

image

@SmashedBird
Copy link
Author

Awesome. Thank you for the good work @simonbrunel

@Jareechang
Copy link
Contributor

quick question @simonbrunel or @etimberg. I am trying to implement this solution but I am blocked by some implementation.

Both of these use the me.margins property.

Align Left:
screen shot 2017-03-11 at 1 04 38 pm

Align Right (works fine):

screen shot 2017-03-11 at 1 04 25 pm

is me.margins.left mis-calculated ? or maybe I need to account for Yscale offset ?

@etimberg etimberg added this to the Version 2.7 milestone May 21, 2017
@stranger08
Copy link

hello. I still can't find this feature in latest documentation.
Is it available or not?

@simonbrunel simonbrunel modified the milestones: Version 2.8, Version 2.7 Aug 23, 2017
@Hintalo
Copy link

Hintalo commented Sep 6, 2017

Yes this would be a very nice feature.
But until it is made available: is there any way of showing either the y-axis title or the Chart-Title at the top left position, simpy written horizontally (i.e. left-to-right) ?
Currently I have the problem that the y-axis title is always shown as rotated-text (i.e. bottom-to-top) and the Chart-Title is shown at the center.
Thanks.

@sizilium
Copy link

Although this feature is called "Title alignment options" please implement the same for the Legend.
I need the Legend to be right-aligned on top.
Thanks.

@mrdansk
Copy link

mrdansk commented Jan 17, 2018

Can a more flexible text positioning be added, I have a requirement for a certain format to be replicated and it would be useful to able to attach several text elements at several positions with multiline and size/font/colour formatting. Similar to my crudely drawn example.

@Hedva
Copy link

Hedva commented Apr 25, 2018

Any updates on this?
@Jareechang did you made any progress with #3706 ?
This is a really nice feature to have within Chartjs

@Koshux
Copy link

Koshux commented May 8, 2018

I am also interested in text-alignment of both the legend items as well as the chart title. Does anyone know whether progress has been made on any of these two possible configurations?

@heytimc
Copy link

heytimc commented Jun 6, 2018

+1

2 similar comments
@Hantzley
Copy link

Hantzley commented Jun 7, 2018

+1

@BWagener
Copy link

+1

@kcabadingk8
Copy link

+1

1 similar comment
@josezulu
Copy link

+1

@manhar-developer
Copy link

Hi @Jareechang
Please update on this . is this feature available

@radhasatam
Copy link

+1

@Lenophie
Copy link

Lenophie commented Aug 8, 2018

Any update on this ?

@oivindth
Copy link

+1

2 similar comments
@lalit-lintel
Copy link

+1

@sudheej
Copy link

sudheej commented Aug 19, 2018

+1

@Jareechang
Copy link
Contributor

Hey Everyone, unfortunately, sorry I do not have much time. Also, I do not use the library much anymore so have not been able to keep up with the developments.

@Mattinn
Copy link

Mattinn commented May 9, 2019

I'm also interested in this feature +1

@AlbertoCrespoGuzman
Copy link

me too

@consciousnessdev
Copy link

Hope finish soon :)

@tomvrampio
Copy link

+1

Going to have to hide the legend and make an HTML replacement because of this

@tobibuenter
Copy link

+1

@benmccann
Copy link
Contributor

I believe this was implemented for v3: #6908

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

No branches or pull requests