Skip to content

Commit

Permalink
Merge pull request #156 from janschoenherr/master
Browse files Browse the repository at this point in the history
use clamp function to calculate left, top and bright values
  • Loading branch information
linx4200 authored Sep 2, 2018
2 parents ea08a50 + ae80344 commit d5de672
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.4.1",
"clamp": "^1.0.1",
"connect-history-api-fallback": "^1.1.0",
"css-loader": "^0.28.11",
"eslint": "^3.19.0",
Expand Down
21 changes: 4 additions & 17 deletions src/components/common/Saturation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</template>

<script>
import clamp from 'clamp'
import throttle from 'lodash.throttle'
export default {
Expand Down Expand Up @@ -53,24 +54,10 @@ export default {
var yOffset = container.getBoundingClientRect().top + window.pageYOffset
var pageX = e.pageX || (e.touches ? e.touches[0].pageX : 0)
var pageY = e.pageY || (e.touches ? e.touches[0].pageY : 0)
var left = pageX - xOffset
var top = pageY - yOffset
if (left < 0) {
left = 0
} else if (left > containerWidth) {
left = containerWidth
} else if (top < 0) {
top = 0
} else if (top > containerHeight) {
top = containerHeight
}
var left = clamp(pageX - xOffset, 0, containerWidth)
var top = clamp(pageY - yOffset, 0, containerHeight)
var saturation = left / containerWidth
var bright = -(top / containerHeight) + 1
bright = bright > 0 ? bright : 0
bright = bright > 1 ? 1 : bright
var bright = clamp(-(top / containerHeight) + 1, 0, 1)
this.throttle(this.onChange, {
h: this.colors.hsv.h,
Expand Down

0 comments on commit d5de672

Please sign in to comment.