Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use clamp function to calculate left, top and bright values #156

Merged
merged 1 commit into from
Sep 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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