Skip to content

Commit

Permalink
Apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroledesma committed Oct 3, 2019
1 parent ad2bdfe commit 35e03d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/charts/WCartesian/__snapshots__/WCartesian.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ exports[`Charts/WCartesian Should be render correctly with bars and lines 1`] =
<g id="0">
<defs>
<clipPath id="path-0-testBar">
<rect rx="5" ry="5" x="59" y="400" width="32" height="194" fill="tomato"></rect>
<rect rx="5" ry="5" x="59" y="400" width="32" height="194"></rect>
</clipPath>
</defs>
<!---->
<g id="line" style="clip-path: url(#path-0-testBar);">
<rect x="75" y="400" width="0" height="0" fill="#48c0b6" style="transition: all 1s ease;" data-height="0" data-width="32" data-y="400" data-x="59" class="v-enter v-enter-active"></rect>
</g>
Expand All @@ -100,9 +101,10 @@ exports[`Charts/WCartesian Should be render correctly with bars and lines 1`] =
<g id="1">
<defs>
<clipPath id="path-1-testBar">
<rect rx="5" ry="5" x="284" y="52" width="32" height="542" fill="tomato"></rect>
<rect rx="5" ry="5" x="284" y="52" width="32" height="542"></rect>
</clipPath>
</defs>
<!---->
<g id="line" style="clip-path: url(#path-1-testBar);">
<rect x="300" y="400" width="0" height="0" fill="#48c0b6" style="transition: all 1s ease;" data-height="348" data-width="32" data-y="52" data-x="284" class="v-enter v-enter-active"></rect>
</g>
Expand All @@ -112,9 +114,10 @@ exports[`Charts/WCartesian Should be render correctly with bars and lines 1`] =
<g id="2">
<defs>
<clipPath id="path-2-testBar">
<rect rx="5" ry="5" x="509" y="226" width="32" height="368" fill="tomato"></rect>
<rect rx="5" ry="5" x="509" y="226" width="32" height="368"></rect>
</clipPath>
</defs>
<!---->
<g id="line" style="clip-path: url(#path-2-testBar);">
<rect x="525" y="400" width="0" height="0" fill="#48c0b6" style="transition: all 1s ease;" data-height="174" data-width="32" data-y="226" data-x="509" class="v-enter v-enter-active"></rect>
</g>
Expand Down
4 changes: 2 additions & 2 deletions src/charts/WPieChart/WPieChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export default {
},
computed: {
curCx () {
return getPercentValue(this.cx, this.width, this.width / 2)
return getPercentValue({ percent: this.cx, totalValue: this.width, defaultValue: this.width / 2 })
},
curCy () {
return getPercentValue(this.cy, this.height, this.height / 2)
return getPercentValue({ percent: this.cy, totalValue: this.height, defaultValue: this.height / 2 })
},
},
render (h) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/mathsPie.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export const polarToCartesian = (cx, cy, radius, angle) => ({
y: cy + Math.sin(-RADIAN * angle) * radius,
})

export const getPercentValue = (percent, totalValue, defaultValue = 0, validate = false) => {
export const getPercentValue = ({ percent, totalValue, defaultValue = 0 }) => {
if (!isNumber(percent) && !isString(percent)) {
return defaultValue
}

let value

if (isPercent(percent)) {
const index = percent.indexOf('%')
const index = percent.slice(0, -1)
value = totalValue * parseFloat(percent.slice(0, index)) / 100
} else {
value = +percent
Expand All @@ -48,7 +48,7 @@ export const getPercentValue = (percent, totalValue, defaultValue = 0, validate
value = defaultValue
}

if (validate && value > totalValue) {
if (value > totalValue) {
value = totalValue
}

Expand Down

0 comments on commit 35e03d4

Please sign in to comment.