Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
QUIQQER
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
163
Issues
163
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QUIQQER
QUIQQER
Commits
4b957f8b
Verified
Commit
4b957f8b
authored
Dec 20, 2018
by
Jan Wennrich
🏡
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: colors can be excluded from being returned by js color util's random-color-methods
parent
c2b3a5d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
8 deletions
+53
-8
bin/QUI/utils/Color.js
bin/QUI/utils/Color.js
+53
-8
No files found.
bin/QUI/utils/Color.js
View file @
4b957f8b
...
...
@@ -18,8 +18,28 @@ define('utils/Color', [], function () {
* @link https://github.com/mrmrs/colors
*
* @licence MIT
*
* @typedef {Object} ColorPalette
* @property {string} aqua
* @property {string} black
* @property {string} blue
* @property {string} fuchsia
* @property {string} gray
* @property {string} green
* @property {string} lime
* @property {string} maroon
* @property {string} navy
* @property {string} olive
* @property {string} purple
* @property {string} red
* @property {string} silver
* @property {string} teal
* @property {string} white
* @property {string} yellow
*
* @type ColorPalette
*/
c
olorPalette
:
{
C
olorPalette
:
{
aqua
:
"
#7FDBFF
"
,
black
:
"
#111111
"
,
blue
:
"
#0074D9
"
,
...
...
@@ -68,11 +88,22 @@ define('utils/Color', [], function () {
/**
* Returns a random color from the custom color pallet.
* Optionally an array of colors from the palette that should not be picked, can be passed.
*
* @param {array} [excludedColors] - Colors that should not be returned
*
* @return {String}
*/
getRandomHexColorFromPallet
:
function
()
{
var
colors
=
Object
.
values
(
this
.
colorPalette
);
getRandomHexColorFromPallet
:
function
(
excludedColors
)
{
var
colors
=
Object
.
values
(
this
.
ColorPalette
);
// Remove the excluded colors
if
(
excludedColors
)
{
excludedColors
.
forEach
(
function
(
excludedColor
)
{
colors
.
splice
(
colors
.
indexOf
(
excludedColor
),
1
);
});
}
return
colors
[
Math
.
floor
(
Math
.
random
()
*
colors
.
length
)];
},
...
...
@@ -82,20 +113,34 @@ define('utils/Color', [], function () {
* The amount of colors to return can be passed as an argument.
* If more colors are requested than there are in the pallet, some colors may appear multiple times.
*
* Optionally an array of colors from the palette that should not be picked, can be passed.
*
* Random picking taken from Bergi from {@link https://stackoverflow.com/a/19270021|Stack Overflow}
*
* @param {number} requestedColorsAmount
* @param {array} [excludedColors] - Colors that should not be returned
*
* @return {Array<String>}
*/
getRandomHexColorsFromPallet
:
function
(
requestedColorsAmount
)
{
var
colors
=
Object
.
values
(
this
.
colorPalette
),
amountOfColors
=
colors
.
length
,
getRandomHexColorsFromPallet
:
function
(
requestedColorsAmount
,
excludedColors
)
{
var
colors
=
Object
.
values
(
this
.
ColorPalette
);
// Remove the excluded colors
if
(
excludedColors
)
{
excludedColors
.
forEach
(
function
(
excludedColor
)
{
colors
.
splice
(
colors
.
indexOf
(
excludedColor
),
1
);
});
}
var
amountOfColors
=
colors
.
length
,
result
=
[];
if
(
requestedColorsAmount
>
amountOfColors
)
{
result
=
result
.
concat
(
this
.
getRandomHexColorsFromPallet
(
requestedColorsAmount
-
amountOfColors
)
this
.
getRandomHexColorsFromPallet
(
requestedColorsAmount
-
amountOfColors
,
excludedColors
)
);
requestedColorsAmount
=
amountOfColors
;
}
...
...
@@ -122,7 +167,7 @@ define('utils/Color', [], function () {
* @return {String}
*/
getHexColorFromPallet
:
function
(
name
)
{
return
this
.
c
olorPalette
[
name
];
return
this
.
C
olorPalette
[
name
];
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment