gps-global-types 1.0.25 → 1.0.27

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/link.types.tsx CHANGED
@@ -1,23 +1,10 @@
1
- import type { BaseType, Selection, SimulationLinkDatum, SimulationNodeDatum } from 'd3';
2
- import type { mstGlobalTypes } from './mst.types.tsx';
3
- import type { NodeType } from './pie.types.js';
4
- interface coords {
5
- x: number,
6
- y: number
7
- }
1
+ import { BaseType, Selection, SimulationLinkDatum, SimulationNodeDatum } from 'd3';
2
+ import { mstGlobalTypes } from './mst.types.tsx';
3
+ import { NodeType } from './pie.types.tsx';
4
+
8
5
  export interface EdgeType extends SimulationLinkDatum<NodeType> { // extends SimulationLinkDatum<NodeType>} anything not defined here was added by d3 (or i fucked up)
9
6
  source: NodeType // node _id edge to
10
7
  target: NodeType // node _id edge from
11
8
  value: number // distance between source and target
12
9
  }
13
10
 
14
- export type gLinkType = Selection<SVGGElement, EdgeType, BaseType, unknown>
15
- export interface LinkType {
16
- g: gLinkType
17
- }
18
-
19
- export interface LinkProps {
20
- data: EdgeType[],
21
- force: mstGlobalTypes
22
- }
23
- export type svgSelection = Selection<BaseType, gLinkType, Element, LinkType>; //Selection<Element,LinkType,Element,any>
package/mst.types.tsx CHANGED
@@ -1,8 +1,7 @@
1
- import type { ClusterFields } from "./cluster.types.js";
2
- import type { armordAccessionNumber, Color, mrsnId, ObjectId, RegexMatchedString } from "./global.types.js";
3
- import type { IsolateFields } from "./isolate.types.js";
4
- import type { EdgeType } from "./link.types.js";
5
- import type { NodeType } from "./pie.types.js";
1
+ import { ClusterFields } from "./cluster.types.tsx";
2
+ import { armordAccessionNumber, Color, mrsnId, ObjectId } from "./global.types.tsx";
3
+ import { IsolateFields } from "./isolate.types.tsx";
4
+ import { EdgeType } from "./link.types.tsx";
6
5
 
7
6
  export interface mstGlobalTypes {
8
7
  //form values
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gps-global-types",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "types shared between front-end and back-end",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,10 +11,13 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "d3": "^7.9.0",
14
- "react": "^19.1.1"
15
- },
16
- "devDependencies": {
14
+ "react": "^19.1.1",
17
15
  "@types/d3": "^7.4.3",
18
16
  "typescript": "^5.9.2"
19
- }
17
+ },
18
+ "browserList": [
19
+ ">0.2%",
20
+ "not dead",
21
+ "not op_mini all"
22
+ ]
20
23
  }
package/pie.types.tsx CHANGED
@@ -1,6 +1,6 @@
1
- import type { BaseType, Selection, SimulationNodeDatum } from "d3";
2
- import type { ObjectId, Color, RegexMatchedString, mrsnId } from "./global.types.tsx"
3
- import type { colorKey, dateKey, labelKey } from "./mst.types.tsx"
1
+ import { BaseType, Selection, SimulationNodeDatum } from "d3";
2
+ import { ObjectId, Color, RegexMatchedString, mrsnId } from "./global.types.tsx"
3
+ import { colorKey, dateKey, labelKey } from "./mst.types.tsx"
4
4
 
5
5
  export interface ColorField {//TYPES OF GRAPH FIELDS ColorField datefields become colorFields but require additional processing
6
6
  color: string, // unique hex or rgb of parameter
package/tsconfig.json CHANGED
@@ -32,7 +32,7 @@
32
32
  // Recommended Options
33
33
  "strict": true,
34
34
  "jsx": "react-jsx",
35
- "verbatimModuleSyntax": true,
35
+ "verbatimModuleSyntax": false,
36
36
  "isolatedModules": true,
37
37
  "noUncheckedSideEffectImports": true,
38
38
  "moduleDetection": "force",
package/confused.js DELETED
@@ -1,236 +0,0 @@
1
- //var d3 = require('d3');//
2
- import { interpolateRgb } from 'd3-interpolate';
3
- import countryDict from '../static/coords.js'; // this file contains all facilities w corresponding countries as a dictionary
4
- const rainbow = ["ac9f9d", "beada1", "c0b7a6", "bcbbaa", "b8bfad", "a4c0b8", "9cbdbe", "97b6c2", "96acc1", "9ba5bb"]; //DO NOT DELETE
5
- import { isolateModel } from './isolate.model.tsx';
6
- import { toHex, dateToYMD } from '../helpers/reformatData.tsx';
7
- import Node from './node.model.tsx';
8
- import { colorFields, CustomDict, dateFields, dateKey, MSTGraph, MSTLegend, SnapshotType } from 'gps-global-types/mst.types.tsx';
9
- import { NodeType } from 'gps-global-types/pie.types.tsx';
10
- import { EdgeType } from 'gps-global-types/link.types.tsx';
11
- import { ObjectId } from 'gps-global-types/global.types.tsx';
12
-
13
- interface graphProps {
14
- name:string,
15
- snapshotData:SnapshotType
16
- }
17
- // console.log('LBL fields', lblFields)
18
- export class Graph implements MSTGraph { //implements MSTGraph
19
- name:string;
20
- // scheme:string;
21
- //colorCalendar:lol;
22
-
23
- nodes:NodeType[] = [];
24
- links:EdgeType[] = [];
25
- legend:MSTLegend;
26
- custom:CustomDict= {}
27
- snapshotData:SnapshotType
28
- latest = { armordCultureDate: new Date('1900-01-01'), isos: [], _id: [] };
29
- missing: Record<string,any>[] = []
30
- constructor(props:graphProps) {
31
- this.name = props.name;
32
- var tempLegend:Record<string, any> = {};
33
- colorFields.forEach((c) => {
34
- tempLegend[c] = new Set();
35
- });
36
- dateFields.forEach((d) => {
37
- tempLegend[d] = 'date'; //[{color:'#e4f1f1',label:'freshest'}, {color:'#062a51',label:'most stale'}];;
38
- });
39
- tempLegend['custom color'] = [{ color: '#ffeeff', label: 'No custom file imported yet' }]; //before custom field is initialized
40
- tempLegend.beforeAndAfter = 'beforeAndAfter';//changed this because otherwise the 'Most Recent' entry duplicates
41
- this.legend = tempLegend as MSTLegend
42
- this.snapshotData = props.snapshotData ;
43
-
44
- }
45
-
46
- /**
47
- * @summary populate included nodes with relevant sequencedIsolates data in a format d3tree.js can parse
48
- * @param {isolateModel[]} isolateData
49
- * @param {Object<ObjectId,ObjectId[]>} mappings parent id, baby ids
50
- * @adescription HOWDY - if you AREN'T criminally obsessed with dicitonaries, this code will change that
51
- */
52
- buildNodes(mappings:Record<ObjectId,ObjectId[]>, isolateData:typeof isolateModel[]) {
53
- var graphCalendar = {}; //used to determine color gradients after all dates have been collected
54
- dateFields.forEach((field) => {
55
- graphCalendar[field] = []
56
- })
57
- /** maps matrix index to node
58
- * @type {Object<integer,Node>}
59
- *
60
- */
61
- var nodeDict = {}; //initialize with parent nodes omg obvi . u DUMB O.DUMBO MSCGEEE
62
- var missingCount = 0; //keep track of the missing agenda
63
- // isolateData.forEach((iso) => {
64
- var i = 0;
65
- while (i < isolateData.length) {
66
- var id = isolateData[i]._id.toString();
67
- // console.log(i, '...,', iso._id)
68
- if (missingCount < this.missing.length) {
69
- for (var m = this.missing.length - 1; m > -1; m--) { //backwards cuz splice is a dangerous beast
70
- var missId = this.missing[m];
71
- if (missId === id) {
72
-
73
- console.log(m, ' m/ss/ng ', missingCount, '!!!!', id, isolateData[i])
74
- this.missing.splice(m, 1);
75
- //ITS A MISSING NODE!!!!!!!!!!;
76
- missingCount++;
77
-
78
- this.missing.push(isolateData[i]);
79
- var deleted = isolateData.splice(i, 1);
80
-
81
- m = -1;
82
- }
83
- }
84
- }
85
-
86
- var iso = isolateData[i]
87
- if (isolateData[i]) {
88
-
89
- iso._id = iso._id.toString();
90
- var node;
91
- var nodeId = mappings[iso._id];
92
- //
93
- var node = nodeDict[nodeId];
94
-
95
- if (!node) {
96
- node = new Node();
97
- if (nodeId) { //dad uninitialized
98
- node.id = nodeId;
99
- } else { //no dad
100
- node.id = iso._id.split(' ')[0];
101
- }
102
- }
103
- // iso.armordMrsnId = iso.mstMrsnId;
104
- iso.armordCultureDate = iso.mstCultureDate;
105
- node.nodeids.push(iso._id)
106
- node.mrsnIds.push(iso.mrsnIds); //for custom
107
- this.custom[iso._id] = { mrsnId: iso.mrsnId }; //estabish custom entry. mrsnId for csv unless hmm
108
-
109
- //1. COLOR FIELDS + LEGEND
110
- colorFields.forEach((field) => {
111
- if (field === 'country') {
112
- iso.country = countryDict[iso.armordFacility];
113
- }
114
- const value = toHex(iso[field])
115
- const isNotCustom = (field.includes('custom') == false);
116
- // console.log(isNotCustom, isNotCustom && this.snapshotData )
117
- if (isNotCustom) {
118
- this.legend[field].add(value + '&' + iso[field]); //add entry to legend
119
- node.populate(field, value);
120
- this.custom[iso._id][field] = value;
121
- } else if (this.snapshotData) {//populate initial snapshot colors
122
- const snapColor = this.snapshotData?.nodes[iso._id]?.color ? this.snapshotData.nodes[iso._id].color : 'grey'
123
-
124
- node.populate(field, snapColor);
125
- this.custom[iso._id][field] = snapColor
126
- }
127
- });
128
-
129
- //2. LBL FIELDS
130
- lblFields.forEach((field) => {
131
- var isoField = iso[field.slice(0, -3)];
132
- if (field.match('custom') && this.snapshotData && this.snapshotData?.nodes[iso._id]) { //populate initial snapshot labels
133
- isoField = this.snapshotData?.nodes[iso._id]?.label //? this.snapshotData?.nodes[iso._id]?.label : 'grey' ;
134
- this.custom[iso._id][field] = this.snapshotData?.nodes[iso._id]?.label;
135
- }
136
- else if (!isoField) isoField = '-';
137
- if (field == 'noLabelLBL') node[field] = ' ';
138
- else node[field] += isoField + '&';
139
- this.custom[iso._id][field] = isoField;
140
- });
141
-
142
- // 3. DATE FIELDS
143
- const nodeDate = new Date(iso.armordCultureDate);
144
- if (nodeDate > new Date(this.latest.armordCultureDate)) this.latest = { armordCultureDate: nodeDate, isos: [iso] }; // parent_id: [node.id], armordMrsnId: [iso.armordMrsnId]
145
- else if (nodeDate.getTime() === this.latest.armordCultureDate.getTime()) {
146
- this.latest.isos.push(iso);
147
- }
148
- const nodeDateStr = dateToYMD(nodeDate);
149
- const nodeYear = nodeDate.getFullYear();
150
- const nodeMonth = nodeYear + '-' + nodeDate.getMonth();
151
- const nodeQuarter = nodeYear + 'QTR' + ((nodeMonth <= 3) ? 1 : (nodeMonth <= 6) ? 2 : (nodeMonth <= 9) ? 3 : 4);
152
-
153
-
154
- var fieldMap = { 'armordCultureDate': nodeDateStr, 'quarter': nodeQuarter, 'month': nodeMonth, 'year': nodeYear };
155
- this.custom[iso._id] = { ...fieldMap, ...this.custom[iso._id] };
156
- dateFields.forEach((field) => {
157
- node.populate(field, fieldMap[field]);
158
- graphCalendar[field].push(fieldMap[field]);
159
- })
160
- // 3.5 sneaky before and after array
161
- node.dateArr.push(nodeDate);
162
-
163
- // 4. dont FORGET THE HOVER !!!
164
- node.hover = node.hover.concat(iso.tier1);
165
-
166
- //ADD HER TO THE NODES
167
- nodeDict[node.id] = node;
168
- i++
169
-
170
- } //missing
171
- //0. get mapping/ parent id of iso
172
-
173
- }
174
-
175
- // configure colorCalendar based on graphCalendar
176
- /**
177
- * return a color based on its field and date
178
- * @type {Object<String,Object<Date,String>>}
179
- * */
180
- var colorCalendar = {}
181
- Object.entries(graphCalendar).forEach(([field, arr]) => { //gradient time light (recent) -> dark (oldest)
182
- arr = arr.sort()
183
- var temp = {};
184
- const max = arr.length
185
- var normal = function (x) { return (max < 2) ? 1 : (x) / (max - 1) }
186
- var gradient = interpolateRgb('#e4f1f1', '#062a51');
187
- arr.forEach((date, i) => {
188
- temp[date] = gradient(normal(i));
189
- })
190
- colorCalendar[field] = temp;
191
- });
192
-
193
- this.latest._id = this.latest.isos.map(i => { return i._id });
194
-
195
- Object.entries(nodeDict).forEach(([key, node]) => {
196
- if (this.snapshotData && this.snapshotData?.transforms[key]) {//initialize node position if snapshot is included
197
- node.x = this.snapshotData.transforms[key].x;
198
- node.y = this.snapshotData.transforms[key].y;
199
- }
200
- node.hover = Array.from(new Set(node.hover)); //convert array of tier 1 alleles into a string of unique values
201
- this.tier1s = this.tier1s.concat(node.hover)
202
- node.hover = node.hover.reduce((prev, curr) => {
203
- return prev + ', ' + curr;
204
- }, '');
205
- node.hover = node.hover.substring(2) //remove silly first comma
206
-
207
- if (!this.snapshotData) node['custom color'] = { '#fff': 1 }; //initialize dummy customcolor
208
- node.beforeAndAfter = [{ color: '#fff', value: 1 }]; //initialize dummy ColorField[] obj to avoid crashes (if beforeAndAfter is selected as initial color field, and before and Afte colors haven't been calculated yet, firefox convluses in a horrific spasm)
209
- })
210
- Object.entries(this.custom).forEach(([id, dict]) => {
211
- dateFields.forEach((field) => {
212
- this.custom[id][field] = colorCalendar[field][this.custom[id][field]]; //brain = gone ; goodbye
213
- })
214
- })
215
- colorFields.forEach((field) => {
216
- if (field.match('custom')) return
217
- this.legend[field] = Array.from(this.legend[field]).map(v => {
218
- var temp = {};
219
- var clrLbl = v.split('&');
220
- temp.color = clrLbl[0];
221
- temp.label = clrLbl[1];
222
- return temp;
223
- })
224
- // this.legend[field].push(JSON.parse(process.env.REACT_APP_MOST_RECENT_LEGEND))
225
- });
226
- this.nodes = Object.values(nodeDict);
227
- this.latest.armordCultureDate = dateToYMD(this.latest.armordCultureDate);
228
- this.colorCalendar = colorCalendar;
229
- this.tier1s = Array.from(new Set(this.tier1s))
230
-
231
- }
232
-
233
- }
234
-
235
-
236
- // export Graph //typedefs