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

show text in the middle #30

Closed
luisrudge opened this issue Dec 2, 2014 · 7 comments
Closed

show text in the middle #30

luisrudge opened this issue Dec 2, 2014 · 7 comments

Comments

@luisrudge
Copy link

can we add an api to insert text inside ProgressBar.Circle?
I mean, I wan't to add the percentage inside of it without having to rely on external html+css.
Thanks!

@kimmobrunfeldt
Copy link
Owner

This would be a nice addition. I haven't yet added it because I wanted to delegate all CSS to the user. I have to investigate if SVG text could be a way to go.

This would also introduce setLabel or setText method to dynamically modify the text.

@luisrudge
Copy link
Author

Yeah. I'd love that!

@kimmobrunfeldt
Copy link
Owner

I'll try to work with this in the near few weeks

@kimmobrunfeldt
Copy link
Owner

Since SVG text can't be vertically centered in IE9(http://stackoverflow.com/questions/5510432/how-to-center-svg-text-vertically-in-ie9), this should be done with adding additional stuff in the container. Something like this:

<div class="progressbar-container">
    <svg viewBox="0 0 100 1" preserveAspectRatio="none"><path d="M 0,0.5 L 100,0.5" stroke="#FCB03C" stroke-width="1" fill-opacity="0" style="stroke-dasharray: 100px, 100px; stroke-dashoffset: 0px;"></path></svg>

    <p>Text</p>
</div>

With this approach, the container must have position: relative.

Also, the text attribute is only sensible for Circle and Square shapes

@davidcpell
Copy link

+1 to this!

@kimmobrunfeldt
Copy link
Owner

I'm currently working on this #38

@kimmobrunfeldt
Copy link
Owner

There's now support for text. I released 0.7.0.
Example here: http://kimmobrunfeldt.github.io/progressbar.js/#example-circle-percent

Documentation: https://github.com/kimmobrunfeldt/progressbar.js/tree/0.7.0#shapecontainer-options

Quote from docs:

   // Text options. Text element is a <p> element appended to container
    // You can add CSS rules for the text element with the className
    // NOTE: When text is set, 'position: relative' will be set to the
    // container for centering. You can also prevent all style modifications
    // with 'autoStyle: false'
    // Default: null
    text: {
        // Initial value for text.
        // Default: null
        value: 'Text',

        // Text color.
        // Default: same as stroke color (options.color)
        color: '#f00',

        // Class name for text element.
        // Default: 'progressbar-text'
        className: 'progressbar__label',

        // If true, CSS is automatically set for container and text element.
        // If you want to modify all CSS your self, set this to false
        // Default: true
        autoStyle: true
    },

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

3 participants