-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.js
More file actions
192 lines (162 loc) · 5.3 KB
/
index.js
File metadata and controls
192 lines (162 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { scaleQuantize, rgb } from "d3";
import Legend from "./Legend";
import dataSources from "../static_datasets/dataSourcesAssoc";
import config from "../../../config";
export const { isPartnerPreview } = config.profile;
export * from "./associations";
export * from "./interactors";
const ASSOCIATION_LEGEND_LABEL = "Association score";
const PRIORITISATION_LEGEND_LABEL = "Prioritisation indicator";
const TARGE_PRIORITISATION_LEGEND_TICKS = ["Unfavourable", "Favourable"];
export const DEFAULT_TABLE_PAGE_INDEX = 0;
export const DEFAULT_TABLE_PAGE_SIZE = 50;
export const DEFAULT_TABLE_PAGINATION_STATE = {
pageIndex: DEFAULT_TABLE_PAGE_INDEX,
pageSize: DEFAULT_TABLE_PAGE_SIZE,
};
export const DEFAULT_TABLE_SORTING_STATE = [{ id: "score", desc: true }];
export const DISPLAY_MODE = {
PRIORITISATION: "prioritisations",
ASSOCIATIONS: "associations",
};
export const TABLE_PREFIX = {
CORE: "core",
PINNING: "pinning",
INTERACTORS: "interactors",
UPLOADED: "uploaded",
};
export const ENTITIES = {
TARGET: "target",
EVIDENCE: "evidence",
DISEASE: "disease",
DRUG: "drug",
};
export const rowNameProperty = { [ENTITIES.TARGET]: "approvedSymbol", [ENTITIES.DISEASE]: "name" };
export const groupViewColumnsBy = (input, key) =>
input.reduce((acc, currentValue) => {
const groupKey = currentValue[key];
const { isPrivate } = currentValue;
if (isPrivate === false || typeof isPrivate === "undefined") {
if (!acc[groupKey]) {
acc[groupKey] = [];
}
acc[groupKey].push(currentValue);
} else if (isPartnerPreview) {
if (!acc[groupKey]) {
acc[groupKey] = [];
}
acc[groupKey].push(currentValue);
}
return acc;
}, {});
/* --- TABLE SHARED HELPERS --- */
export const getPriorisationSectionId = columnDef => columnDef.sectionId;
export const getCellId = (cell, entityToGet, displayedTable, tablePrefix = null) => {
const colId = cell.column.id;
const rowId = cell.row.original[entityToGet].id;
const sectionId =
displayedTable === DISPLAY_MODE.ASSOCIATIONS ? cell.column.id : cell.column.columnDef.sectionId;
return [rowId, colId, sectionId, tablePrefix];
};
export const getColumAndSection = (cell, displayedTable) => {
if (!cell.column) return [];
const colId = cell.column.id;
const sectionId =
displayedTable === DISPLAY_MODE.ASSOCIATIONS ? cell.column.id : cell.column.columnDef.sectionId;
return [colId, sectionId];
};
export const cellHasValue = score => typeof score === "number";
export const defaulDatasourcesWeigths = dataSources.map(
({ id, weight, required, aggregation }) => ({
id,
weight,
required,
aggregation,
propagate: true,
})
);
export const defaultDataSourcesFilter = dataSources.filter(
e => !e.isPrivate || (e.isPrivate && e.isPrivate === isPartnerPreview)
);
export const getWightSourceDefault = source => {
const sourcesDetails = defaulDatasourcesWeigths.find(src => src.id === source);
return sourcesDetails.weight;
};
export const checkBoxPayload = (id, aggregationId) => ({
id,
path: [aggregationId, id],
name: "dataTypes",
});
export const getControlChecked = (values, id) => values.filter(val => val.id === id).length > 0;
/* --- CONSTANTS --- */
const { primaryColor } = config.profile;
/* Associations colors */
export const ASSOCIATION_COLORS = [
rgb("#deebf7"),
rgb("#c6dbef"),
rgb("#9ecae1"),
rgb("#6baed6"),
rgb("#4292c6"),
rgb("#2171b5"),
rgb("#08519c"),
];
/* PRIORITIZATION */
// Red to blue
export const PRIORITISATION_COLORS = [
rgb("#ec2746"),
rgb("#f16d47"),
rgb("#f19d5c"),
rgb("#f0c584"),
rgb("#c8b95f"),
rgb("#95ae43"),
rgb("#52a237"),
];
/* ASSOCIATION SCALE */
export const asscScaleDomain = scaleQuantize().domain([0, 1]);
export const assocScale = asscScaleDomain.range(ASSOCIATION_COLORS);
/* PRIORITISATION SCALE */
export const prioritizationScaleDomain = scaleQuantize().domain([-1, 1]);
export const prioritizationScale = prioritizationScaleDomain.range(PRIORITISATION_COLORS);
/* LEGENDS */
const PrioritisationLegend = Legend(prioritizationScale, {
title: PRIORITISATION_LEGEND_LABEL,
tickFormat: (d, i) =>
[
TARGE_PRIORITISATION_LEGEND_TICKS[0],
" ",
" ",
" ",
" ",
TARGE_PRIORITISATION_LEGEND_TICKS[1],
][i],
});
const AssociationsLegend = Legend(assocScale, {
title: ASSOCIATION_LEGEND_LABEL,
tickFormat: ".1f",
});
export const getLegend = isAssoc => {
if (isAssoc) return AssociationsLegend;
return PrioritisationLegend;
};
/* --- GLOBAL HELPERS --- */
export const getScale = isAssoc => (isAssoc ? assocScale : prioritizationScale);
/* --- CSS VARIABLES --- */
export const tableCSSVariables = {
"--primary-color": primaryColor,
"--grey-lighter": "#f6f6f6",
"--grey-light": "#ececec",
"--grey-mid": "#e0dede",
"--grey-dark": "#b8b8b8",
"--background-color": "#fafafa",
"--text-color": "#5A5F5F",
"--table-header-min-width": "120px",
"--table-header-max-width": "160px",
"--table-left-column-width": "260px",
"--row-hover-color": "var(--grey-light)",
"--aggregations-background-color": "var(--grey-light)",
"--aggregations-border-color": "var(--grey-dark)",
"--header-border-color": "var(--grey-light)",
"--entities-border-color": "var(--grey-light)",
"--table-footer-border-color": "var(--grey-light)",
"--colums-controls-color": "var(--grey-lighter)",
};