@@ -191,7 +191,8 @@ export default class AngularColorPickerController {
191191 'AngularColorPickerController.options.swatch' ,
192192 'AngularColorPickerController.options.pos' ,
193193 'AngularColorPickerController.options.inline' ,
194- 'AngularColorPickerController.options.placeholder'
194+ 'AngularColorPickerController.options.placeholder' ,
195+ 'AngularColorPickerController.options.round' ,
195196 ] ,
196197 this . reInit . bind ( this )
197198 ) ;
@@ -393,6 +394,10 @@ export default class AngularColorPickerController {
393394 } ) ;
394395
395396 this . visible = this . options . inline ;
397+
398+ if ( this . options . round ) {
399+ this . options . hue = false ;
400+ }
396401 }
397402
398403 merge ( options , defaultOptions ) {
@@ -515,9 +520,11 @@ export default class AngularColorPickerController {
515520 var el = angular . element ( this . $element [ 0 ] . querySelector ( '.color-picker-grid .color-picker-picker' ) ) ;
516521 var bounding = container . getBoundingClientRect ( ) ;
517522
518- el . css ( {
519- 'top' : ( bounding . height * this . lightnessPos / 100 ) + 'px' ,
520- } ) ;
523+ if ( ! this . options . round ) {
524+ el . css ( {
525+ 'top' : ( bounding . height * this . lightnessPos / 100 ) + 'px' ,
526+ } ) ;
527+ }
521528 } ) ;
522529 }
523530
@@ -527,7 +534,7 @@ export default class AngularColorPickerController {
527534 var el = angular . element ( this . $element [ 0 ] . querySelector ( '.color-picker-grid .color-picker-picker' ) ) ;
528535 var bounding = container . getBoundingClientRect ( ) ;
529536
530- if ( this . options . round ) {
537+ if ( this . options . round ) {
531538 el . css ( {
532539 left : ( bounding . width * this . xPos / 100 ) + 'px' ,
533540 top : ( bounding . height * this . yPos / 100 ) + 'px' ,
@@ -542,10 +549,6 @@ export default class AngularColorPickerController {
542549 }
543550
544551 gridUpdate ( ) {
545- if ( ! this . options . updateBackgroundColor ) {
546- return ;
547- }
548-
549552 var el = angular . element ( this . $element [ 0 ] . querySelector ( '.color-picker-grid' ) ) ;
550553
551554 el . css ( {
@@ -674,17 +677,18 @@ export default class AngularColorPickerController {
674677 var el = this . find ( '.color-picker-grid-inner' ) ;
675678 var offset = this . offset ( el ) ;
676679
677- if ( this . options . round ) {
680+ if ( this . options . round ) {
678681 var dx = ( ( event . pageX - offset . left ) * 2.0 / el . prop ( 'offsetWidth' ) ) - 1.0 ;
679682 var dy = - ( ( event . pageY - offset . top ) * 2.0 / el . prop ( 'offsetHeight' ) ) + 1.0 ;
680683
681- var tmpSaturation = Math . sqrt ( dx * dx + dy * dy ) ;
684+ var tmpSaturation = Math . sqrt ( dx * dx + dy * dy ) ;
682685 var tmpHue = Math . atan2 ( dy , dx ) ;
683686
684687 this . saturation = 100 * tmpSaturation ;
685688 var degHue = tmpHue * 57.29577951308233 ; // rad to deg
686- if ( degHue < 0.0 )
689+ if ( degHue < 0.0 ) {
687690 degHue += 360.0 ;
691+ }
688692 this . hue = degHue ;
689693 this . lightness = 100 ;
690694 } else {
@@ -710,10 +714,25 @@ export default class AngularColorPickerController {
710714 if ( this . options . round ) {
711715 var angle = this . hue * 0.01745329251994 ; // deg to rad
712716 var px = Math . cos ( angle ) * this . saturation ;
713- var py = - Math . sin ( angle ) * this . saturation ;
717+ var py = - Math . sin ( angle ) * this . saturation ;
714718
715719 this . xPos = ( px + 100.0 ) * 0.5 ;
716- this . yPos = ( py + 100.0 ) * 0.5 ;
720+ this . yPos = ( py + 100.0 ) * 0.5 ;
721+
722+ // because we are using percentages this can be half of 100%
723+ var center = 50 ;
724+ // distance of pointer from the center of the circle
725+ var distance = Math . pow ( center - this . xPos , 2 ) + Math . pow ( center - this . yPos , 2 ) ;
726+ // distance of edge of circle from the center of the circle
727+ var radius = Math . pow ( center , 2 ) ;
728+
729+ // if not inside the circle
730+ if ( distance > radius ) {
731+ var rads = Math . atan2 ( this . yPos - center , this . xPos - center ) ;
732+
733+ this . xPos = Math . cos ( rads ) * center + center ;
734+ this . yPos = Math . sin ( rads ) * center + center ;
735+ }
717736 } else {
718737 this . saturationPos = ( this . saturation / 100 ) * 100 ;
719738
0 commit comments