tigrr / circle-progress

Responsive, accessible, animated, stylable with CSS circular progress bar available as plain (vanilla) JS and jQuery plugin.
https://tigrr.github.io/circle-progress
MIT License
171 stars 44 forks source link

Split % symbol from value #14

Closed kulbabskyy closed 2 years ago

kulbabskyy commented 2 years ago

Hi, its is possible to split % symbol from value in the separated text node, to make it smaller and align the bar value to the center of progress bar?

Also will be great if we can place some text at the bottom of the value, like on the screenshot i attached. Thank You!

IMG_20220609_205338

tigrr commented 2 years ago

You can do any formatting if you provide your own function for textFormat. I. e., for your screenshot:

const cp = new CircleProgress('.progress', {
    value: 33,
    max: 50,
    textFormat: (value, max) => `
        <tspan class="circle-progress-value-number" dx="7px">${Math.round(value / max * 100)}</tspan><tspan class="circle-progress-percent" dy="-1em">%</tspan>
        <tspan class="circle-progress-absolute-values" x="50" y="50" dy="2.1em">${value}/${max}</tspan>
    `,
})

See the entire demo.

kulbabskyy commented 2 years ago

Thank you for sharing this snippets. This is awesome! Its possible to make own layouts.

The current style on the demo link is very useful, maybe you will consider to add it in the lib?

tigrr commented 2 years ago

I surely will.

One thing to mention: if you use custom formatting, take care for sanitizing your variables, since it goes into innerHTML and may be used for XSS attacks. Inserting value and max is safe since they are formatted by Circle Progress. But for other values, especially coming from users, you should take special care.