[Service] ColorPalette is now ColorService

This commit is contained in:
Pete Richards 2015-08-13 16:06:26 -07:00
parent 889a5c6ea9
commit 48f345a46b
2 changed files with 32 additions and 7 deletions

View File

@ -84,6 +84,13 @@
"model": {"composition": []}, "model": {"composition": []},
"properties": [] "properties": []
} }
],
"services": [
{
"key": "colorService",
"implementation": "services/ColorService.js",
"description": "Provides objects for working with colors."
}
] ]
} }
} }

View File

@ -108,9 +108,8 @@ define(
}; };
/** /**
* A color palette which returns colors from a predefined palette. * A color palette stores a set of colors and allows for different
* When all colors in the palette have been allocated, it starts reusing * methods of color allocation.
* colors.
* *
* @constructor * @constructor
*/ */
@ -122,15 +121,34 @@ define(
} }
/** /**
* * @returns {Color} the next unused color in the palette. If all colors
* @return {Color} the next color in the palette. * have been allocated, it will wrap around.
*/ */
ColorPalette.prototype.getColor = function () { ColorPalette.prototype.getNextColor = function () {
var color = this.colors[this.nextColor % this.colors.length]; var color = this.colors[this.nextColor % this.colors.length];
this.nextColor++; this.nextColor++;
return color; return color;
}; };
return ColorPalette; /**
* @param {number} index the index of the color to return. An index
* value larger than the size of the index will wrap around.
* @returns {Color}
*/
ColorPalette.prototype.getColor = function (index) {
return this.colors[index % this.colors.length];
};
function ColorService() {}
ColorService.prototype.ColorPalette = ColorPalette;
ColorService.prototype.Color = Color;
function getColorService() {
return new ColorService();
}
return getColorService;
} }
); );