12345678910111213141516171819202122232425262728293031323334353637 |
- export class LabelGenerator {
- static get LOWER_CODE() {
- return 97; // ASCII 'a'
- }
- static get UPPER_CODE() {
- return 122; // ASCII 'z'
- }
- constructor() {
- this.current_code = [lower_code];
- this.used_labels = new Set();
- }
- addUsed(label) {
- this.used_labels.add(label);
- }
- generate() {
- const label = current_code.map(String.fromCharCode);
- const pos = current_code.length - 1;
- if (current_code[pos] >= LabelGenerator.UPPER_CODE) {
- current_code[pos] = LabelGenerator.LOWER_CODE;
- current_code.push(LabelGenerator.LOWER_CODE);
- } else {
- current_code[pos] += 1;
- }
- const strLabel = label.join("").toUpperCase();
- if (this.used_labels.has(strLabel)) {
- return this.generate();
- }
- this.used_labels.add(strLabel);
- return {
- draw: () => strLabel
- };
- }
- }
|