ConceptPortal-public/rsconcept/frontend/src/utils/selectors.ts

109 lines
4.1 KiB
TypeScript
Raw Normal View History

/**
* Module: Mappings for selector UI elements.
*/
2023-09-14 16:53:38 +03:00
import { LayoutTypes } from 'reagraph';
import { type GramData, Grammeme, ReferenceType } from '@/models/language';
import { grammemeCompare } from '@/models/languageAPI';
2023-12-26 14:23:51 +03:00
import { GraphColoringScheme } from '@/models/miscellaneous';
import { CstType } from '@/models/rsform';
2023-09-29 15:33:32 +03:00
import { labelGrammeme, labelReferenceType } from './labels';
2023-09-21 14:58:01 +03:00
import { labelCstType } from './labels';
2023-09-14 16:53:38 +03:00
2023-09-27 23:36:51 +03:00
/**
* Represents options for GraphLayout selector.
2023-12-28 14:04:44 +03:00
*/
export const SelectorGraphLayout: { value: LayoutTypes; label: string }[] = [
2023-09-14 16:53:38 +03:00
{ value: 'treeTd2d', label: 'Граф: ДеревоВ 2D' },
{ value: 'treeTd3d', label: 'Граф: ДеревоВ 3D' },
{ value: 'forceatlas2', label: 'Граф: Атлас 2D' },
{ value: 'forceDirected2d', label: 'Граф: Силы 2D' },
{ value: 'forceDirected3d', label: 'Граф: Силы 3D' },
{ value: 'treeLr2d', label: 'Граф: ДеревоГ 2D' },
{ value: 'treeLr3d', label: 'Граф: ДеревоГ 3D' },
{ value: 'radialOut2d', label: 'Граф: Радиальная 2D' },
2023-12-28 14:04:44 +03:00
{ value: 'radialOut3d', label: 'Граф: Радиальная 3D' }
2023-09-14 16:53:38 +03:00
// { value: 'circular2d', label: 'circular2d'},
// { value: 'nooverlap', label: 'nooverlap'},
// { value: 'hierarchicalTd', label: 'hierarchicalTd'},
// { value: 'hierarchicalLr', label: 'hierarchicalLr'}
];
2023-09-27 23:36:51 +03:00
/**
* Represents options for {@link GraphColoringScheme} selector.
2023-12-28 14:04:44 +03:00
*/
export const SelectorGraphColoring: { value: GraphColoringScheme; label: string }[] = [
2023-09-14 16:53:38 +03:00
{ value: 'none', label: 'Цвет: моно' },
{ value: 'status', label: 'Цвет: статус' },
2023-12-28 14:04:44 +03:00
{ value: 'type', label: 'Цвет: класс' }
2023-09-14 16:53:38 +03:00
];
2023-09-27 23:36:51 +03:00
/**
* Represents options for {@link CstType} selector.
2023-12-28 14:04:44 +03:00
*/
export const SelectorCstType = Object.values(CstType).map(typeStr => ({
value: typeStr as CstType,
label: labelCstType(typeStr as CstType)
}));
2023-09-21 14:58:01 +03:00
2023-09-27 23:36:51 +03:00
/**
* Represents single option for {@link Grammeme} selector.
2023-12-28 14:04:44 +03:00
*/
2023-09-27 23:36:51 +03:00
export interface IGrammemeOption {
2023-12-28 14:04:44 +03:00
value: GramData;
label: string;
2023-09-21 14:58:01 +03:00
}
2023-09-27 23:36:51 +03:00
/**
* Compares {@link IGrammemeOption} based on Grammeme comparison.
*/
export function compareGrammemeOptions(left: IGrammemeOption, right: IGrammemeOption): number {
2023-11-20 18:03:34 +03:00
return grammemeCompare(left.value, right.value);
2023-09-27 23:36:51 +03:00
}
/**
* Represents list of {@link Grammeme}s available in reference construction.
2023-12-28 14:04:44 +03:00
*/
// prettier-ignore
2023-09-25 14:17:52 +03:00
export const SelectorGrammemesList = [
2023-09-21 14:58:01 +03:00
Grammeme.sing, Grammeme.plur,
Grammeme.nomn, Grammeme.gent, Grammeme.datv,
Grammeme.accs, Grammeme.ablt, Grammeme.loct,
2023-09-25 14:17:52 +03:00
];
2023-09-27 23:36:51 +03:00
/**
* Represents options for {@link Grammeme} selector.
2023-12-28 14:04:44 +03:00
*/
export const SelectorGrammemes: IGrammemeOption[] = SelectorGrammemesList.map(gram => ({
2023-09-27 23:36:51 +03:00
value: gram,
label: labelGrammeme(gram)
2023-09-21 14:58:01 +03:00
}));
2023-09-29 15:33:32 +03:00
/**
* Represents options for {@link ReferenceType} selector.
2023-12-28 14:04:44 +03:00
*/
export const SelectorReferenceType = Object.values(ReferenceType).map(typeStr => ({
value: typeStr as ReferenceType,
label: labelReferenceType(typeStr as ReferenceType)
}));
2023-09-29 15:33:32 +03:00
/**
* Represents recommended wordforms data.
2023-12-28 14:04:44 +03:00
*/
2023-12-27 19:34:39 +03:00
export const DefaultWordForms = [
2023-09-29 15:33:32 +03:00
{ text: 'ед им', example: 'ручка', grams: [Grammeme.sing, Grammeme.nomn] },
{ text: 'ед род', example: 'ручки', grams: [Grammeme.sing, Grammeme.gent] },
{ text: 'ед дат', example: 'ручке', grams: [Grammeme.sing, Grammeme.datv] },
{ text: 'ед вин', example: 'ручку', grams: [Grammeme.sing, Grammeme.accs] },
{ text: 'ед твор', example: 'ручкой', grams: [Grammeme.sing, Grammeme.ablt] },
{ text: 'ед пред', example: 'ручке', grams: [Grammeme.sing, Grammeme.loct] },
2023-12-28 14:04:44 +03:00
2023-09-29 15:33:32 +03:00
{ text: 'мн им', example: 'ручки', grams: [Grammeme.plur, Grammeme.nomn] },
{ text: 'мн род', example: 'ручек', grams: [Grammeme.plur, Grammeme.gent] },
{ text: 'мн дат', example: 'ручкам', grams: [Grammeme.plur, Grammeme.datv] },
{ text: 'мн вин', example: 'ручки', grams: [Grammeme.plur, Grammeme.accs] },
{ text: 'мн твор', example: 'ручками', grams: [Grammeme.plur, Grammeme.ablt] },
{ text: 'мн пред', example: 'ручках', grams: [Grammeme.plur, Grammeme.loct] }
2023-12-28 14:04:44 +03:00
];