diff --git a/docs/api/cautious-journey.flaglabel.md b/docs/api/cautious-journey.flaglabel.md
index 776f07a..e47f1ee 100644
--- a/docs/api/cautious-journey.flaglabel.md
+++ b/docs/api/cautious-journey.flaglabel.md
@@ -13,3 +13,9 @@ export interface FlagLabel extends BaseLabel, ChangeSet
```
Extends: BaseLabel, ChangeSet
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [requires](./cautious-journey.flaglabel.requires.md) | Array<unknown> | |
+
diff --git a/docs/api/cautious-journey.flaglabel.requires.md b/docs/api/cautious-journey.flaglabel.requires.md
new file mode 100644
index 0000000..710b2f3
--- /dev/null
+++ b/docs/api/cautious-journey.flaglabel.requires.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [FlagLabel](./cautious-journey.flaglabel.md) > [requires](./cautious-journey.flaglabel.requires.md)
+
+## FlagLabel.requires property
+
+Signature:
+
+```typescript
+requires: Array;
+```
diff --git a/docs/api/cautious-journey.statelabel.md b/docs/api/cautious-journey.statelabel.md
index b91a9ff..aa40614 100644
--- a/docs/api/cautious-journey.statelabel.md
+++ b/docs/api/cautious-journey.statelabel.md
@@ -9,9 +9,9 @@ Grouped labels: the equivalent of a radio group.
Signature:
```typescript
-export interface StateLabel extends BaseLabel, ChangeSet
+export interface StateLabel extends BaseLabel
```
-Extends: BaseLabel, ChangeSet
+Extends: BaseLabel
## Properties
diff --git a/docs/api/cautious-journey.statevalue.md b/docs/api/cautious-journey.statevalue.md
index 1775ee1..3de7e63 100644
--- a/docs/api/cautious-journey.statevalue.md
+++ b/docs/api/cautious-journey.statevalue.md
@@ -9,9 +9,9 @@ One of many values for a particular state.
Signature:
```typescript
-export interface StateValue extends BaseLabel
+export interface StateValue extends BaseLabel, ChangeSet
```
-Extends: BaseLabel
+Extends: BaseLabel, ChangeSet
## Properties
diff --git a/docs/api/cautious-journey.syncoptions.md b/docs/api/cautious-journey.syncoptions.md
index e1a096a..5683f2e 100644
--- a/docs/api/cautious-journey.syncoptions.md
+++ b/docs/api/cautious-journey.syncoptions.md
@@ -18,6 +18,7 @@ export interface SyncOptions
| [flags](./cautious-journey.syncoptions.flags.md) | Array<[FlagLabel](./cautious-journey.flaglabel.md)> | |
| [logger](./cautious-journey.syncoptions.logger.md) | Logger | |
| [project](./cautious-journey.syncoptions.project.md) | string | |
+| [random](./cautious-journey.syncoptions.random.md) | prng | |
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |
| [states](./cautious-journey.syncoptions.states.md) | Array<[StateLabel](./cautious-journey.statelabel.md)> | States from project config. |
diff --git a/docs/api/cautious-journey.syncoptions.random.md b/docs/api/cautious-journey.syncoptions.random.md
new file mode 100644
index 0000000..ae78280
--- /dev/null
+++ b/docs/api/cautious-journey.syncoptions.random.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [random](./cautious-journey.syncoptions.random.md)
+
+## SyncOptions.random property
+
+Signature:
+
+```typescript
+random: prng;
+```
diff --git a/src/labels.ts b/src/labels.ts
index 3631aea..89b7f7d 100644
--- a/src/labels.ts
+++ b/src/labels.ts
@@ -31,16 +31,23 @@ export interface BaseLabel {
* Display color.
*/
color?: string;
+
+ /**
+ * Long-form description.
+ */
desc?: string;
+
+ /**
+ * Label priority.
+ */
priority: number;
- requires: Array;
}
/**
* Individual labels: the equivalent of a checkbox.
*/
export interface FlagLabel extends BaseLabel, ChangeSet {
- /* empty */
+ requires: Array;
}
/**
@@ -56,7 +63,7 @@ export interface StateChange extends ChangeSet {
/**
* One of many values for a particular state.
*/
-export interface StateValue extends BaseLabel {
+export interface StateValue extends BaseLabel, ChangeSet {
/**
* State changes that could occur to this value.
*/
@@ -66,7 +73,7 @@ export interface StateValue extends BaseLabel {
/**
* Grouped labels: the equivalent of a radio group.
*/
-export interface StateLabel extends BaseLabel, ChangeSet {
+export interface StateLabel extends BaseLabel {
/**
* Values for this state.
*/
@@ -121,17 +128,15 @@ export function prioritySort(labels: Array): A
/**
* Pick a label color, preferring the label data if set, falling back to a randomly selected color.
- *
- * TODO: this is a terrible overload
*/
export function getLabelColor(colors: Array, random: prng, flag: FlagLabel): string;
export function getLabelColor(colors: Array, random: prng, state: StateLabel, value: StateValue): string;
export function getLabelColor(colors: Array, random: prng, label: BaseLabel, value?: StateValue): string {
- if (doesExist(value) && doesExist(value.color)) {
+ if (doesExist(value) && doesExist(value.color) && value.color !== '') {
return value.color;
}
- if (doesExist(label.color)) {
+ if (doesExist(label.color) && label.color !== '') {
return label.color;
}
diff --git a/src/utils.ts b/src/utils.ts
index a863e04..bfe75d7 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -15,6 +15,6 @@ export function defaultUntil(...items: Array>): T {
}
export function randomItem(items: Array, source: prng): T {
- const idx = Math.floor(source() * items.length);
+ const idx = source.int32() % items.length;
return items[idx];
}
diff --git a/test/TestLabels.ts b/test/TestLabels.ts
index 54ec9fc..49dc6aa 100644
--- a/test/TestLabels.ts
+++ b/test/TestLabels.ts
@@ -1,6 +1,7 @@
import { expect } from 'chai';
+import { alea } from 'seedrandom';
-import { getLabelNames, prioritySort } from '../src/labels';
+import { getLabelColor, getLabelNames, prioritySort } from '../src/labels';
describe('label helpers', () => {
describe('label name helper', () => {
@@ -30,23 +31,21 @@ describe('label helpers', () => {
it('should return all states', () => {
const values = [{
+ adds: [],
becomes: [],
name: 'bin',
priority: 1,
+ removes: [],
requires: [],
}];
const states = [{
- adds: [],
name: 'foo',
priority: 1,
- removes: [],
requires: [],
values,
}, {
- adds: [],
name: 'bar',
priority: 1,
- removes: [],
requires: [],
values,
}];
@@ -92,4 +91,59 @@ describe('label helpers', () => {
expect(sorted[0]).to.deep.equal(FIRST_LABEL);
});
});
+
+ describe('label color helper', () => {
+ it('should return the value color', () => {
+ expect(getLabelColor(['test'], alea(), {
+ color: 'beans',
+ name: '',
+ priority: 1,
+ values: [],
+ }, {
+ adds: [],
+ becomes: [],
+ color: 'not',
+ name: '',
+ priority: 1,
+ removes: [],
+ })).to.equal('not');
+ });
+
+ it('should return the state color when value color is unset', () => {
+ expect(getLabelColor(['test'], alea(), {
+ color: 'beans',
+ name: '',
+ priority: 1,
+ values: [],
+ }, {
+ adds: [],
+ becomes: [],
+ color: '',
+ name: '',
+ priority: 1,
+ removes: [],
+ })).to.equal('beans');
+ });
+
+ it('should return the flag color', () => {
+ expect(getLabelColor(['test'], alea(), {
+ adds: [],
+ color: 'not',
+ name: '',
+ priority: 1,
+ removes: [],
+ requires: [],
+ })).to.equal('not');
+ });
+
+ it('should return a random color when the flag color is unset', () => {
+ expect(getLabelColor(['test'], alea(), {
+ adds: [],
+ name: '',
+ priority: 1,
+ removes: [],
+ requires: [],
+ })).to.equal('test');
+ });
+ });
});