Skip to content

Commit cedfa90

Browse files
authored
Merge pull request #87 from setaman/dev
Dev
2 parents 8ee486a + ca0c3f4 commit cedfa90

20 files changed

+1041
-581
lines changed

README.md

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ After you have initialized the component, use it everywhere you want in your app
6969
lineMode="in 10"
7070
:legend="true"
7171
:legendValue="180"
72+
:legendFormatter="({currentValue}) => new Intl.NumberFormat('de-DE').format(currentValue)"
7273
legendClass="legend-custom-style"
7374
dash="60 0.9"
7475
animation="reverse 700 400"
@@ -111,6 +112,7 @@ This table below provides a quick overview over all available options. To gain m
111112
| **[`emptyColorFill`](#emptycolorfill)** | String \| Object | same as `color` | "transparent" |
112113
| **[`legend`](#legend)** | Boolean | | true |
113114
| **[`legendValue`](#legendvalue)** | Number \| String | any number, accepts a `.` or `","` as decimals delimiter | |
115+
| **[`legendFormatter`](#legendformatter)** [![npm](https://img.shields.io/badge/v1.3.0-blue?style=flat-square)](#legendformatter) | Function | Function that returns formatted value | |
114116
| **[`animation`](#animation)** | String | "default \| rs \| loop \| reverse \| bounce [duration delay]" | "default 1000 400"|
115117
| **[`loading`](#loading)** | Boolean | |false|
116118
| **[`determinate`](#determinate)** | Boolean | |false|
@@ -150,7 +152,9 @@ this.myProgress = 55.5;
150152
this.myProgress = this.tasksDone * 100 / maxTasks; // the percentage of done tasks
151153
```
152154

153-
>:heavy_exclamation_mark: The `progress` is always used to fill the progress circle line. So you cannot customize this value, it should be always in the range [-100, 100] and not valid Numbers lead to **[`noData`](#noData)** state. For customization purpose please use **[`legendValue`](#legendvalue)**.
155+
>:heavy_exclamation_mark: The `progress` is always used to fill the progress circle line. So you cannot customize this
156+
>value, it should be always in the range [-100, 100] and not valid Numbers lead to **[`noData`](#noData)** state.
157+
>For customization purpose please use **[`legendValue`](#legendvalue)** and take a look at **[`legendFormatter`](#legendformatter)**.
154158
155159
>If **[`legendValue`](#legendvalue)** is defined the progress will **NOT** be displayed as circle legend.
156160
@@ -308,29 +312,75 @@ Is a Boolean. It defines whether the **[`progress`](#progress)** or from you def
308312

309313
###### Animated: :heavy_check_mark:
310314

311-
Is any number. Use this property if you want to customize the shown progress as the legend of the circle. If defined, `legendValue` will replace **[`progress`](#progress)** as the circle legend!
312-
313-
[![npm](https://img.shields.io/badge/v1.1.1-blue?style=flat-square)](#legendvalue) You can set any precision of the decimal numbers. If the prop is defined as a string, you can specify the `","` as decimals separator (e.g "123,123" for german numbers).
315+
Is any Number or String. Use this property if you want to show progress value as the legend of the circle that is not in
316+
the range [-100, 100]. If defined, `legendValue` will replace [`progress`](#progress) as the circle legend!
317+
You can set any precision of the decimal numbers. If the prop is defined as a string, you can specify the `","`
318+
as decimals delimiter (e.g "123,123" for german numbers), apart from this the value must generally be a valid JavaScript Number.
319+
For more customization possibilities please use [`legendFormatter`](#legendformatter) or [`scoped slot`](#default).
314320

315321
###### Example: :scroll:
316322

317-
Let's say you need to display a rating from 0 to 5 of a product with 3.5 stars. Since **[`progress`](#progress)** can take values only from 0 to 100 your need an additional property `legendValue`. You can show the product rating like in the following example:
323+
Let's say you need to display a rating from 0 to 5 of a product with 3.5 stars. Setting the [`progress`](#progress) to 3.5 will
324+
fill the circle to 3.5 percent, and this is not what we need, since we want to display the percentage of 5 as progress.
325+
At this point we need an additional property `legendValue`. We can show the product rating like in the following example:
318326

319327
```js
320-
<vue-ellipse-progress progress="progress" :legend-value="rating" />
328+
<vue-ellipse-progress :progress="progress" :legend-value="rating" />
321329
...
322330
this.rating = 3.5;
323331
this.progress = this.rating * 100 / 5; // the rating percentage
324332
```
325333
Now you can display custom progress value that still animated and circle progress fills properly!
326334

327-
```vuejs
328-
legend-value="345,12345" // set "," as delimiter defining the value as string
335+
```vue
336+
<vue-ellipse-progress legend-value="345,12345" /> // set "," as delimiter defining the value as string
329337
```
330338

331339
>:heavy_exclamation_mark: note that `legendValue` replaces **[`progress`](#progress)** as circle legend but not vice versa.
332340
333341

342+
<br>
343+
344+
- ### `legendFormatter`
345+
346+
[![npm](https://img.shields.io/badge/v1.3.0-blue?style=flat-square)](#legendformatter)
347+
348+
Is a Function that must return your custom formatted value. The function takes counter properties object as argument and
349+
is called on every tick of the counter. Here the formatting of [legendValue](#legendvalue) or [progress](#progress)
350+
is completely up to you and you have full freedom to adjust the presentation to your needs. The function can return any
351+
value, even HTML.
352+
353+
>:grey_exclamation: alternatively you can use **[`scoped slot`](#default)** for custom formatting.
354+
355+
###### Example: :scroll:
356+
357+
Let's see how it works. The function takes counter properties object as argument that you can use to define custom formatting.
358+
`currentValue` is the most relevant value, as it is the actual value at specific counter tick. The return value will be
359+
displayed as the legend of the circle.
360+
361+
```js
362+
const myFormatter = ({ currentValue, currentRawValue, duration, previousCountStepValue, start, end, difference, oneStepDifference, startTime, elapsed }) => {
363+
return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(currentValue);
364+
}
365+
```
366+
You can also return HTML:
367+
```js
368+
const myFormatter = ({ currentValue }) => {
369+
return `
370+
<span style="font-weight: bold; font-size: 1.6rem">${new Intl.NumberFormat("de-DE").format(currentValue)}</span>
371+
<span>€</span>
372+
`;
373+
}
374+
```
375+
376+
Finally, set your formatter as prop:
377+
378+
```vue
379+
<vue-ellipse-progress :legend-formatter="myFormatter"/>
380+
<!-- shorter version if you wish-->
381+
<vue-ellipse-progress :legend-formatter="({ currentValue }) => `My Format ${currentValue}`"/>
382+
````
383+
334384
<br>
335385
336386
- ### `animation`
@@ -517,6 +567,23 @@ data: [
517567

518568
### Slot options
519569

570+
- #### `default`
571+
572+
Use this slot, if you want to customize the presentation of the circle legend and make a use of the animated counter,
573+
so your formatting still animated. This works similar to the [`legendFormatter`](#legendformatter) and is just
574+
an alternative way to provide a custom format. You can access animated counter properties through the scoped slot
575+
props and adjust the presentation of the legend to your needs.
576+
577+
```vue
578+
<vue-ellipse-progress :progress="50">
579+
<template v-slot:default="{ counterTick }">
580+
<span style="font-weight: bold; font-size: 1.6rem; color: green;">
581+
{{ myFormatter(counterTick.currentValue) }}
582+
</span>
583+
</template>
584+
</vue-ellipse-progress>
585+
```
586+
520587
- #### `legend-value`
521588

522589
In this slot you can put an additional element that you want to display beside the progress
@@ -530,8 +597,12 @@ This code ...
530597
```html
531598
<vue-ellipse-progress ....>
532599

533-
<span slot="legend-value">/200</span>
534-
<p slot="legend-caption">TASKS DONE</p>
600+
<template v-slot:legend-value>
601+
<span slot="legend-value">/200</span>
602+
</template>
603+
<template v-slot:legend-caption>
604+
<p slot="legend-caption">TASKS DONE</p>
605+
</template>
535606

536607
</vue-ellipse-progress>
537608
```

0 commit comments

Comments
 (0)