Skip to content

Commit

Permalink
[ONL-6708] - Migrate donut component (#1291)
Browse files Browse the repository at this point in the history
* ONL-6708 - Migrate donut component

* changed radius to reactive param.

* edited radius const

* renamed const

* removed .vm test

* updated the version
  • Loading branch information
corinaper authored Sep 27, 2022
1 parent 17352d6 commit 1a42606
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ebury/chameleon-components",
"version": "2.1.2",
"version": "2.1.3",
"main": "src/main.js",
"sideEffects": false,
"author": "Ebury Team (http://labs.ebury.rocks/)",
Expand Down
9 changes: 0 additions & 9 deletions src/components/ec-donut/ec-donut.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ describe('EcDonut', () => {
expect(wrapper.element).toMatchSnapshot();
});

it('should get the correct computed properties', () => {
const wrapper = mountDonut();
const circumference = 2 * Math.PI * wrapper.vm.radius;
expect(wrapper.vm.percentageUsed).toBe(20);
const offset = circumference * (1 - wrapper.vm.percentageUsed / 100);
expect(wrapper.vm.dashArray).toBe(circumference);
expect(wrapper.vm.dashOffset).toBe(offset);
});

it('should render slots as expected', () => {
const wrapper = mountDonut({}, {
slots: {
Expand Down
75 changes: 32 additions & 43 deletions src/components/ec-donut/ec-donut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@
class="ec-donut__background"
cx="54"
cy="54"
:r="radius"
:r="RADIUS"
fill="transparent"
stroke-width="11"
/>
<circle
class="ec-donut__remaining"
cx="54"
cy="54"
:r="radius"
:r="RADIUS"
fill="transparent"
stroke-width="11"
:stroke-dasharray="dashArray"
:stroke-dasharray="circumference"
:stroke-dashoffset="0"
/>
<circle
class="ec-donut__used"
cx="54"
cy="54"
:r="radius"
:r="RADIUS"
fill="transparent"
stroke-width="11"
:stroke-dasharray="dashArray"
:stroke-dashoffset="dashOffset"
:stroke-dasharray="circumference"
:stroke-dashoffset="usedArcLength"
/>
</svg>
</div>
Expand Down Expand Up @@ -73,47 +73,36 @@
</div>
</template>

<script>
<script setup>
import { computed } from 'vue';
import EcIcon from '../ec-icon';
export default {
name: 'EcDonut',
components: { EcIcon },
props: {
amount: {
type: Number,
required: true,
},
used: {
type: Number,
required: true,
},
},
data() {
return {
radius: 48,
};
const props = defineProps({
amount: {
type: Number,
required: true,
},
computed: {
percentageUsed() {
if (this.used > this.amount) {
return 100;
}
if (this.used <= 0) {
return 0;
}
return (this.used / this.amount) * 100;
},
// Calculate the circumference
dashArray() {
return 2 * Math.PI * this.radius;
},
// Calculate the how much needs to be offset of the used circle
dashOffset() {
return this.dashArray * (1 - this.percentageUsed / 100);
},
used: {
type: Number,
required: true,
},
};
});
const RADIUS = 48;
const percentageUsed = computed(() => {
if (props.used > props.amount) {
return 100;
}
if (props.used <= 0) {
return 0;
}
return (props.used / props.amount) * 100;
});
const circumference = computed(() => 2 * Math.PI * RADIUS);
const usedArcLength = computed(() => circumference.value * (1 - percentageUsed.value / 100));
</script>

<style>
Expand Down

1 comment on commit 1a42606

@vercel
Copy link

@vercel vercel bot commented on 1a42606 Sep 27, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

chameleon – ./

chameleon-dead-plane.vercel.app
chameleon-ebury.vercel.app
chameleon-git-master-ebury.vercel.app

Please sign in to comment.