gps-global-types 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.tsx +0 -0
- package/line.types.tsx +0 -0
- package/mst.types.tsx +180 -0
- package/package.json +12 -0
- package/pie.types.tsx +68 -0
package/index.tsx
ADDED
|
File without changes
|
package/line.types.tsx
ADDED
|
File without changes
|
package/mst.types.tsx
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
|
|
2
|
+
export interface mstGlobalTypes {
|
|
3
|
+
//form values
|
|
4
|
+
charge: number, //= -100, // repulsion
|
|
5
|
+
radius: number, //= 15, // user adjustment of node radius
|
|
6
|
+
cluster: number, //= 0, // less than highlight threshold for links
|
|
7
|
+
distance: number //=
|
|
8
|
+
linkLabelSize: number, //= 12, // fontSize of link labels
|
|
9
|
+
center: [number, number,]//[800,500],// where on the page does the tree spawn (x,y )
|
|
10
|
+
fuzzyThreshold: number, //= 0, // nodes outside of requested list that are x alleles away from the original mst
|
|
11
|
+
neighbor: number, //= 1, // how many isolate neighbors to return (minimum)
|
|
12
|
+
slim?: boolean, //false //are the node labels collapsed or expanded?
|
|
13
|
+
|
|
14
|
+
//interactive nodes
|
|
15
|
+
// checkedNodes:mrsnId[], ????
|
|
16
|
+
// highlightedNodes:mrsnId[] ????
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const colorFields= ['armordPatientId','mlst','sampleType','armordFacility','armordCountry','custom color'] as const; //no :string[] ! removes 'const'
|
|
20
|
+
export const dateFields= ['armordCultureDate','month','quarter','year'] as const;
|
|
21
|
+
export const labelFields= ['armordMrsnIdLBL','mrsnIdLBL','armordAccessionNumberLBL','armordPatientIdLBL','custom label'] as const;
|
|
22
|
+
|
|
23
|
+
export type colorKey = typeof colorFields[number];
|
|
24
|
+
export type dateKey = typeof dateFields[number];
|
|
25
|
+
export type labelKey = typeof labelFields[number];
|
|
26
|
+
|
|
27
|
+
type RegexMatchedString<Pattern extends string> =
|
|
28
|
+
`${string & { __brand: Pattern }}`;
|
|
29
|
+
//TYPES OF STRINGS
|
|
30
|
+
type armordAccessionNumber = string // who KNOWS the format of these
|
|
31
|
+
type ObjectId = RegexMatchedString<'[a-zA-Z0-9]{12}'> //12 byte string meant to index mongo docs
|
|
32
|
+
type armordMrsnId = string // 6 o/* */r 7 digit number typically, but the bi-db is a cesspool
|
|
33
|
+
type mrsnId = string // ###### ('MRSN' + 6 or 7 digit number) typically, but the bi-db is a cesspool
|
|
34
|
+
type armordPatientId = RegexMatchedString<'M\d+'> // M###### ('M'+6 digit number), but the bi-db is a cesspool
|
|
35
|
+
type Hex = RegexMatchedString<'#\d{6}'> // 6 digit String hexadecimal w/ '#' prepended
|
|
36
|
+
type Rgb = RegexMatchedString<'rgb\([1-256],[1-256],[1-256]\)'> // format rgb(\d[1-256],\d[1-256],\d[1-256])
|
|
37
|
+
type Color = Hex|Rgb|String
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
interface ColorType {
|
|
45
|
+
color:Color, //unique hex of parameter
|
|
46
|
+
value:number //count of how many times value will be represented in the pie
|
|
47
|
+
}
|
|
48
|
+
type LabelType = RegexMatchedString<'(\w&)*'> // if many, seperated by '&' qhich are interpreted as newlines in front-end. var names ends with 'LBL'.
|
|
49
|
+
type DateType = string | Date // must be able to be interpreted as date type by Date js object
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
interface ExtraNodeTypeFields {
|
|
53
|
+
id:ObjectId,//unique identifier referenced by Graph.links and d3 Force. String but it's a string of a mongo id
|
|
54
|
+
beforeAndAfter?:ColorType[] //[=[{color:'#fff',value:1}]] so it doesnt break on recalculation
|
|
55
|
+
dateArr:DateType[], // array of armordCultureDates used for beforeAndAfter coloring
|
|
56
|
+
hover?:String, // [=""] //unique fieldfields \/ \/ list seperated by ', ' (only tier1 alleles for now)
|
|
57
|
+
mrsnIds: String[] // for selection logic between table and node=
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type NodeType = ExtraNodeTypeFields | Record<colorKey|dateKey, ColorType[]> | Record<labelKey, LabelType[]>;
|
|
61
|
+
|
|
62
|
+
interface EdgeType {
|
|
63
|
+
source:string, //node _id edge to
|
|
64
|
+
target:string, //node _id edge from
|
|
65
|
+
value:number //distance between source and target
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type CustomDictEntry = Record<colorKey|dateKey,Color> | Record<labelKey,string>;
|
|
69
|
+
type CustomDict = Record<ObjectId,CustomDictEntry>
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
export interface MSTGraph {
|
|
74
|
+
nodes :NodeType[] // core parameter of d3tree.js . keeps all isolates collection data
|
|
75
|
+
links :EdgeType[] // core parameter of d3tree.js
|
|
76
|
+
latest :{armordCultureDate:Date, armordMrsnId:mrsnId[]} // earliest node for easy toggling
|
|
77
|
+
custom :CustomDict // . I KNOW THIS IS DUMB but from user's pov it results in seamless color transitions across pages
|
|
78
|
+
legend :MSTLegend // saves legend configs across all color fields
|
|
79
|
+
}interface FlashTable {
|
|
80
|
+
"_id": ObjectId,
|
|
81
|
+
"MRSN ID¹": mrsnId,
|
|
82
|
+
"Cx Date": Date|string,
|
|
83
|
+
"Cx Source": string,
|
|
84
|
+
"Wards": string,
|
|
85
|
+
"Prev Report #²": string,
|
|
86
|
+
"Accession #": armordAccessionNumber,
|
|
87
|
+
"Last Name": "...",
|
|
88
|
+
"DOD ID": "..."
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface FlashData { //todo: add 'tier1s' here
|
|
92
|
+
dateCreated:Date,
|
|
93
|
+
first:boolean, //first node added to thec cluster
|
|
94
|
+
isolateCount:number,
|
|
95
|
+
lastModified:Date,
|
|
96
|
+
mostRecent:{
|
|
97
|
+
_id:ObjectId[],
|
|
98
|
+
armordCultureDate:Date|string,
|
|
99
|
+
isos:Record<string,any>[], //todo
|
|
100
|
+
}
|
|
101
|
+
mostCloselyRelated:{
|
|
102
|
+
_id:ObjectId,
|
|
103
|
+
armordCultureDate:Date|string,
|
|
104
|
+
distance:number
|
|
105
|
+
},
|
|
106
|
+
patientCount:number,
|
|
107
|
+
st:string,
|
|
108
|
+
table:FlashTable[],
|
|
109
|
+
wardCount:string,
|
|
110
|
+
wgsId:string
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
interface MSTResult {
|
|
115
|
+
flash:FlashData,
|
|
116
|
+
graph:MSTGraph,
|
|
117
|
+
tabular:{
|
|
118
|
+
isolate:Record<string,any>[],
|
|
119
|
+
amr:Record<string,any>[]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface LegendBullet { //or custom upload data
|
|
124
|
+
color:Color,
|
|
125
|
+
label:string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type MSTLegend = Record<colorKey,LegendBullet[]>|Record<dateKey,'date'> | {'beforeAndAfter':[{color:'#666666', label:'Before '} ,{color:'#4a64aa', label:'After '}]}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
interface SnapshotType {
|
|
133
|
+
_id:ObjectId,
|
|
134
|
+
form:mstGlobalTypes,
|
|
135
|
+
legend:LegendBullet[],
|
|
136
|
+
nodes:Record<ObjectId,LegendBullet>,
|
|
137
|
+
scheme:string,
|
|
138
|
+
transforms:Record<ObjectId,{x:number,y:number}>
|
|
139
|
+
}
|
|
140
|
+
/** /mst route RESULT
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @typedef D3treeProps
|
|
144
|
+
* @property {MSTGraph} data except it only requires links,nodes,legend, and custom
|
|
145
|
+
* @property {ForceObject} form
|
|
146
|
+
* @property {String|null} _id cluster _id
|
|
147
|
+
* @property {function(Snapshot)} setSnapshot
|
|
148
|
+
* @property {function(MSTGraph)} setData trigger parent data state which affects variables in parent
|
|
149
|
+
* @property {function([[import('../../typedefs/MSTree').mrsnId[],Boolean ]])} setSelected connects nodes to table rows on click
|
|
150
|
+
*/
|
|
151
|
+
/**force
|
|
152
|
+
* @typedef d3Data
|
|
153
|
+
* @property {EdgeType[]} links
|
|
154
|
+
* @property {NodeType[]} pies
|
|
155
|
+
*/
|
|
156
|
+
/**string
|
|
157
|
+
* @typedef ItolProps
|
|
158
|
+
* @property {string} scheme
|
|
159
|
+
* @property {ObjectId[]} isolates targets centered for analysis
|
|
160
|
+
* @property {int} neighbors min # of nearest samples to include (beyond targets)
|
|
161
|
+
* @property {int} threshold max allelic distance from the targets to include
|
|
162
|
+
*/
|
|
163
|
+
//IDK WHY THESE EXIST
|
|
164
|
+
/**
|
|
165
|
+
* @typedef MstFields
|
|
166
|
+
* @property {String[]} clusterNickName
|
|
167
|
+
* @property {String[]} scheme
|
|
168
|
+
* @property {Date} lastModified
|
|
169
|
+
* @property {Date} dateModified
|
|
170
|
+
*
|
|
171
|
+
*
|
|
172
|
+
*
|
|
173
|
+
*
|
|
174
|
+
*
|
|
175
|
+
*
|
|
176
|
+
* @typedef {{...SplashReq,...MstFields}} MSTreeReq
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
179
|
+
// module.exports = { MSTGraph, MSTLegend, NodeType,EdgeType,Hex, ColorField,LabelField}
|
|
180
|
+
// exports.unused = {};
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gps-global-types",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "types shared between front-end and back-end",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "lizz",
|
|
10
|
+
"type":"module",
|
|
11
|
+
"license": "ISC"
|
|
12
|
+
}
|
package/pie.types.tsx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BaseType, Selection, SimulationNodeDatum } from "d3"
|
|
2
|
+
import { Ref, RefObject } from "react"
|
|
3
|
+
import { EdgeType, svgSelection } from "../../Link/link.types"
|
|
4
|
+
import { ObjectId, Color, RegexMatchedString } from "@/assets/types/global.types"
|
|
5
|
+
import { colorKey, dateKey, labelKey } from "../../mst.types"
|
|
6
|
+
|
|
7
|
+
export interface ColorField {//TYPES OF GRAPH FIELDS ColorField datefields become colorFields but require additional processing
|
|
8
|
+
color: string, // unique hex or rgb of parameter
|
|
9
|
+
value: number, // count of how many times value will be represented in the pie
|
|
10
|
+
latest?: string // most recent node designation; diff coloring logic for 'latest' nodes
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type LabelField = string //if n>1, seperated by '&' which are interpreted as newlines in front-end. var names ends with 'LBL'.
|
|
14
|
+
export interface ColorType {
|
|
15
|
+
color: Color, //unique hex of parameter
|
|
16
|
+
value: number //count of how many times value will be represented in the pie
|
|
17
|
+
}
|
|
18
|
+
type LabelType = RegexMatchedString<'(\w&)*'> // if many, seperated by '&' qhich are interpreted as newlines in front-end. var names ends with 'LBL'.
|
|
19
|
+
type DateType = string | Date // must be able to be interpreted as date type by Date js object
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
interface ExtraNodeTypeFields extends d3.SimulationNodeDatum {
|
|
23
|
+
id: ObjectId,//unique identifier referenced by Graph.links and d3 Force. String but it's a string of a mongo id
|
|
24
|
+
beforeAndAfter?: ColorType[], //[=[{color:'#fff',value:1}]] so it doesnt break on recalculation
|
|
25
|
+
dateArr: DateType[], // array of armordCultureDates used for beforeAndAfter coloring
|
|
26
|
+
hover?: string, // [=""] //unique fieldfields \/ \/ list seperated by ', ' (only tier1 alleles for now)
|
|
27
|
+
nodeids: ObjectId[] // for selection logic between table and node=
|
|
28
|
+
x?: number,
|
|
29
|
+
y?: number,
|
|
30
|
+
fx?: number | null,
|
|
31
|
+
fy?: number | null,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type NodeType = ExtraNodeTypeFields & {
|
|
35
|
+
[K in colorKey | dateKey]: ColorType[];
|
|
36
|
+
} & {
|
|
37
|
+
[K in labelKey]: LabelType[];
|
|
38
|
+
}; //d3.Selection<SVGGElement, NodeType, d3.BaseType, unknown>
|
|
39
|
+
export type ParentSelection = Selection<SVGGElement, NodeType, BaseType, unknown>
|
|
40
|
+
export type PieSelection = Selection<SVGCircleElement, NodeType, BaseType, NodeType[]>
|
|
41
|
+
export type PieTextSelection = Selection<SVGTextElement, NodeType, SVGGElement, NodeType>
|
|
42
|
+
export interface PieType {
|
|
43
|
+
g: ParentSelection,
|
|
44
|
+
data: NodeType[],
|
|
45
|
+
labelField: keyof NodeType, //todo acceptable strings!
|
|
46
|
+
}
|
|
47
|
+
export interface SelectionObj {
|
|
48
|
+
mrsnIds: string[],
|
|
49
|
+
active: boolean
|
|
50
|
+
}
|
|
51
|
+
export interface InitializeDragProps {
|
|
52
|
+
sticky: boolean,
|
|
53
|
+
sim: RefObject<d3.Simulation<d3.SimulationNodeDatum, any>>,
|
|
54
|
+
setSelected: React.Dispatch<React.SetStateAction<SelectionObj>>,
|
|
55
|
+
height: number,
|
|
56
|
+
width: number// todo can this be a global const somewhere instead?
|
|
57
|
+
}
|
|
58
|
+
export interface NodeColorProps {
|
|
59
|
+
colorField: keyof NodeType,
|
|
60
|
+
svg: ParentSelection,
|
|
61
|
+
formRadius: number
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface newLabelProps {
|
|
65
|
+
labelField: keyof NodeType,
|
|
66
|
+
svg: ParentSelection,
|
|
67
|
+
slim: boolean
|
|
68
|
+
}
|