-
Notifications
You must be signed in to change notification settings - Fork 4k
/
ExperimentViewUtil.js
758 lines (720 loc) · 24 KB
/
ExperimentViewUtil.js
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
import classNames from 'classnames';
import React from 'react';
import Utils from '../../common/utils/Utils';
import { Link } from 'react-router-dom';
import Routes from '../routes';
import { getModelVersionPageRoute } from '../../model-registry/routes';
import { CollapsibleTagsCell } from '../../common/components/CollapsibleTagsCell';
import _ from 'lodash';
import ExpandableList from '../../common/components/ExpandableList';
import registryIcon from '../../common/static/registryIcon.svg';
import { TrimmedText } from '../../common/components/TrimmedText';
import { SEARCH_MAX_RESULTS } from '../actions';
import {
ATTRIBUTE_COLUMN_LABELS,
ATTRIBUTE_COLUMN_SORT_KEY,
DEFAULT_EXPANDED_VALUE,
COLUMN_TYPES,
} from '../constants';
export default class ExperimentViewUtil {
/** Returns checkbox cell for a row. */
static getCheckboxForRow(selected, checkboxHandler, cellType) {
const CellComponent = `${cellType}`;
return (
<CellComponent key='meta-check' className='run-table-container'>
<div>
<input type='checkbox' checked={selected} onChange={checkboxHandler} />
</div>
</CellComponent>
);
}
static styles = {
sortIconStyle: {
verticalAlign: 'middle',
fontSize: 20,
},
headerCellText: {
verticalAlign: 'middle',
},
sortIconContainer: {
marginLeft: 2,
minWidth: 12.5,
display: 'inline-block',
},
expander: {
pointer: 'cursor',
},
runInfoCell: {
maxWidth: 250,
},
};
/**
* Returns an icon depending on run status.
*/
static getRunStatusIcon(status) {
switch (status) {
case 'FAILED':
case 'KILLED':
return <i className='far fa-times-circle' style={{ color: '#DB1905' }} />;
case 'FINISHED':
return <i className='far fa-check-circle' style={{ color: '#10B36B' }} />;
case 'SCHEDULED':
return <i className='far fa-clock' style={{ color: '#258BD2' }} />;
default:
return <i />;
}
}
/**
* Returns table cells describing run metadata (i.e. not params/metrics) comprising part of
* the display row for a run.
*/
static getRunInfoCellsForRow(runInfo, tags, isParent, cellType, handleCellToggle, excludedKeys) {
const CellComponent = `${cellType}`;
const user = Utils.getUser(runInfo, tags);
const queryParams = window.location && window.location.search ? window.location.search : '';
const sourceType = Utils.renderSource(tags, queryParams);
const { status, start_time: startTime, end_time: endTime } = runInfo;
const duration = Utils.getDuration(startTime, endTime);
const runName = Utils.getRunName(tags);
const childLeftMargin = isParent ? {} : { paddingLeft: 16 };
const columnProps = [
{
key: 'status',
className: 'run-table-container',
title: status,
children: ExperimentViewUtil.getRunStatusIcon(status),
},
{
key: ATTRIBUTE_COLUMN_LABELS.DATE,
className: 'run-table-container',
style: { whiteSpace: 'inherit' },
children: (
<div style={childLeftMargin}>
<Link to={Routes.getRunPageRoute(runInfo.experiment_id, runInfo.run_uuid)}>
{Utils.formatTimestamp(startTime)}
</Link>
</div>
),
},
{
key: ATTRIBUTE_COLUMN_LABELS.DURATION,
className: 'run-table-container',
title: duration,
children: (
<div className='truncate-text single-line' style={ExperimentViewUtil.styles.runInfoCell}>
{duration}
</div>
),
},
{
key: ATTRIBUTE_COLUMN_LABELS.USER,
className: 'run-table-container',
title: user,
children: (
<div className='truncate-text single-line' style={ExperimentViewUtil.styles.runInfoCell}>
{user}
</div>
),
},
{
key: ATTRIBUTE_COLUMN_LABELS.RUN_NAME,
className: 'run-table-container',
title: runName,
children: (
<div className='truncate-text single-line' style={ExperimentViewUtil.styles.runInfoCell}>
{runName}
</div>
),
},
{
key: ATTRIBUTE_COLUMN_LABELS.SOURCE,
className: 'run-table-container',
title: sourceType,
children: (
<div className='truncate-text single-line' style={ExperimentViewUtil.styles.runInfoCell}>
{Utils.renderSourceTypeIcon(tags)}
{sourceType}
</div>
),
},
{
key: ATTRIBUTE_COLUMN_LABELS.VERSION,
className: 'run-table-container',
children: (
<div className='truncate-text single-line' style={ExperimentViewUtil.styles.runInfoCell}>
{Utils.renderVersion(tags)}
</div>
),
},
{
key: 'Tags',
className: 'run-table-container',
children: (
<div style={ExperimentViewUtil.styles.runInfoCell}>
<CollapsibleTagsCell tags={tags} onToggle={handleCellToggle} />
</div>
),
},
];
const excludedKeysSet = new Set(excludedKeys);
return columnProps
.filter((column) => !excludedKeysSet.has(column.key))
.map((props) => <CellComponent {...props} />);
}
/**
* Returns an icon for sorting the metric or param column with the specified key. The icon
* is visible if we're currently sorting by the corresponding column. Otherwise, the icon is
* invisible but takes up space.
*/
static getSortIcon(curOrderByKey, curOrderByAsc, canonicalKey) {
if (curOrderByKey === canonicalKey) {
return (
<span>
<i
className={curOrderByAsc ? 'fas fa-caret-up' : 'fas fa-caret-down'}
style={ExperimentViewUtil.styles.sortIconStyle}
/>
</span>
);
}
return undefined;
}
/** Returns checkbox element for selecting all runs */
static getSelectAllCheckbox(onCheckAll, isAllCheckedBool, cellType) {
const CellComponent = `${cellType}`;
return (
<CellComponent key='meta-check' className='bottom-row run-table-container'>
<input type='checkbox' onChange={onCheckAll} checked={isAllCheckedBool} />
</CellComponent>
);
}
/**
* Returns header-row table cells for columns containing run metadata.
*/
static getRunMetadataHeaderCells(onSortBy, curOrderByKey, curOrderByAsc, cellType, excludedCols) {
const CellComponent = `${cellType}`;
const getHeaderCell = (key, text, canonicalSortKey) => {
const sortIcon = ExperimentViewUtil.getSortIcon(
curOrderByKey,
curOrderByAsc,
canonicalSortKey,
);
const isSortable = canonicalSortKey !== null;
const cellClassName = classNames('bottom-row', 'run-table-container', {
sortable: isSortable,
});
return (
<CellComponent
key={'meta-' + key}
className={cellClassName}
onClick={() => (isSortable ? onSortBy(canonicalSortKey, !curOrderByAsc) : null)}
>
<span style={ExperimentViewUtil.styles.headerCellText}>{text}</span>
{isSortable && (
<span style={ExperimentViewUtil.styles.sortIconContainer}>{sortIcon}</span>
)}
</CellComponent>
);
};
const excludedColsSet = new Set(excludedCols);
return [
{
key: 'status',
canonicalSortKey: null,
},
{
key: 'start_time',
displayName: ATTRIBUTE_COLUMN_LABELS.DATE,
canonicalSortKey: ATTRIBUTE_COLUMN_SORT_KEY.DATE,
},
{
key: 'user_id',
displayName: ATTRIBUTE_COLUMN_LABELS.USER,
canonicalSortKey: ATTRIBUTE_COLUMN_SORT_KEY.USER,
},
{
key: 'run_name',
displayName: ATTRIBUTE_COLUMN_LABELS.RUN_NAME,
canonicalSortKey: ATTRIBUTE_COLUMN_SORT_KEY.RUN_NAME,
},
{
key: 'source',
displayName: ATTRIBUTE_COLUMN_LABELS.SOURCE,
canonicalSortKey: ATTRIBUTE_COLUMN_SORT_KEY.SOURCE,
},
{
key: 'source_version',
displayName: ATTRIBUTE_COLUMN_LABELS.VERSION,
canonicalSortKey: ATTRIBUTE_COLUMN_SORT_KEY.VERSION,
},
{
key: 'tags',
displayName: 'Tags',
canonicalSortKey: null,
},
{
key: 'linked-models',
displayName: 'Linked Models',
canonicalSortKey: null,
},
]
.filter((column) => !excludedColsSet.has(column.displayName))
.map((h) => getHeaderCell(h.key, <span>{h.displayName}</span>, h.canonicalSortKey));
}
static makeCanonicalKey(keyType, keyName) {
return keyType + '.`' + keyName + '`';
}
static middleTruncateKey(keyName, maxLen) {
if keyName.length > maxLen:
return keyName.substring(0, firstPartLen) + '...' + keyName.substring(firstPartLen + 3)
else:
return keyName
}
static getExpanderHeader(cellType) {
const CellComponent = `${cellType}`;
return (
<CellComponent
key={'meta-expander'}
className={'bottom-row run-table-container'}
style={{ width: '5px' }}
/>
);
}
/**
* Returns a table cell corresponding to a single metric value. The metric is assumed to be
* unbagged (marked to be displayed in its own column).
* @param metricKey The key of the desired metric
* @param metricsMap Object mapping metric keys to their latest values for a single run
* @param metricRanges Object mapping metric keys to objects of the form {min: ..., max: ...}
* containing min and max values of the metric across all visible runs.
* @param cellType Tag type (string like "div", "td", etc) of containing cell.
*/
static getUnbaggedMetricCell(metricKey, metricsMap, metricRanges, cellType) {
const className = 'left-border run-table-container';
const keyName = 'metric-' + metricKey;
const CellComponent = `${cellType}`;
if (metricsMap[metricKey]) {
const metric = metricsMap[metricKey].getValue();
const range = metricRanges[metricKey];
let fraction = 1.0;
if (range.max > range.min) {
fraction = (metric - range.min) / (range.max - range.min);
}
const percent = fraction * 100 + '%';
return (
<CellComponent className={className} key={keyName}>
{/* We need the extra div because metric-filler-bg is inline-block */}
<div>
<div className='metric-filler-bg'>
<div className='metric-filler-fg' style={{ width: percent }} />
<div className='metric-text'>{Utils.formatMetric(metric)}</div>
</div>
</div>
</CellComponent>
);
}
return <CellComponent className={className} key={keyName} />;
}
static getUnbaggedParamCell(paramKey, paramsMap, cellType) {
const CellComponent = `${cellType}`;
const className = 'left-border run-table-container';
const keyName = 'param-' + paramKey;
if (paramsMap[paramKey]) {
return (
<CellComponent className={className} key={keyName}>
<div>{paramsMap[paramKey].getValue()}</div>
</CellComponent>
);
} else {
return <CellComponent className={className} key={keyName} />;
}
}
static renderLinkedModelCell(modelVersion) {
const { name, version } = modelVersion;
return (
<div className='version-link'>
<img src={registryIcon} alt='MLflow Model Registry Icon' />
<span className='model-link-text'>
<a
href={Utils.getIframeCorrectedRoute(getModelVersionPageRoute(name, version))}
className='model-version-link'
title={`${name}, v${version}`}
style={{ verticalAlign: 'middle' }}
target='_blank'
>
<TrimmedText text={name} maxSize={10} className={'model-name'} />
<span>/{version} </span>
</a>
</span>
</div>
);
}
static getLinkedModelCell(associatedModelVersions, handleCellToggle) {
const className = 'left-border run-table-container';
if (associatedModelVersions && associatedModelVersions.length > 0) {
return (
<div className={className} key='linked=models'>
<ExpandableList
children={associatedModelVersions.map((version) => this.renderLinkedModelCell(version))}
showLines={1}
onToggle={handleCellToggle}
/>
</div>
);
} else {
return null;
}
}
static computeMetricRanges(metricsByRun) {
const ret = {};
metricsByRun.forEach((metrics) => {
metrics.forEach((metric) => {
if (!ret.hasOwnProperty(metric.key)) {
ret[metric.key] = {
min: Math.min(metric.value, metric.value * 0.7),
max: metric.value,
};
} else {
if (metric.value < ret[metric.key].min) {
ret[metric.key].min = Math.min(metric.value, metric.value * 0.7);
}
if (metric.value > ret[metric.key].max) {
ret[metric.key].max = metric.value;
}
}
});
});
return ret;
}
/**
* Turn a list of metrics to a map of metric key to metric.
*/
static toMetricsMap(metrics) {
const ret = {};
metrics.forEach((metric) => {
ret[metric.key] = metric;
});
return ret;
}
/**
* Turn a list of param to a map of metric key to metric.
*/
static toParamsMap(params) {
const ret = {};
params.forEach((param) => {
ret[param.key] = param;
});
return ret;
}
static isExpanderOpen(runsExpanded, runId) {
let expanderOpen = DEFAULT_EXPANDED_VALUE;
if (runsExpanded[runId] !== undefined) expanderOpen = runsExpanded[runId];
return expanderOpen;
}
static getExpander(hasExpander, expanderOpen, onExpandBound, runUuid, cellType) {
const CellComponent = `${cellType}`;
if (!hasExpander) {
return <CellComponent key={'Expander-' + runUuid} style={{ padding: 8 }}></CellComponent>;
}
if (expanderOpen) {
return (
<CellComponent onClick={onExpandBound} key={'Expander-' + runUuid} style={{ padding: 8 }}>
<i className='ExperimentView-expander far fa-minus-square' />
</CellComponent>
);
} else {
return (
<CellComponent onClick={onExpandBound} key={'Expander-' + runUuid} style={{ padding: 8 }}>
<i className='ExperimentView-expander far fa-plus-square' />
</CellComponent>
);
}
}
static getNestedRowRenderMetadata({ runInfos, tagsList, runsExpanded }) {
const runIdToIdx = {};
runInfos.forEach((r, idx) => {
runIdToIdx[r.run_uuid] = idx;
});
const treeNodes = runInfos.map((r) => new TreeNode(r.run_uuid));
tagsList.forEach((tags, idx) => {
const parentRunId = tags['mlflow.parentRunId'];
if (parentRunId) {
const parentRunIdx = runIdToIdx[parentRunId.value];
if (parentRunIdx !== undefined) {
treeNodes[idx].parent = treeNodes[parentRunIdx];
}
}
});
// Map of parentRunIds to list of children runs (idx)
const parentIdToChildren = {};
treeNodes.forEach((t, idx) => {
const root = t.findRoot();
if (root !== undefined && root.value !== t.value) {
const old = parentIdToChildren[root.value];
let newList;
if (old) {
old.push(idx);
newList = old;
} else {
newList = [idx];
}
parentIdToChildren[root.value] = newList;
}
});
const parentRows = _.flatMap([...Array(runInfos.length).keys()], (idx) => {
if (treeNodes[idx].isCycle() || !treeNodes[idx].isRoot()) return [];
const runId = runInfos[idx].run_uuid;
let hasExpander = false;
let childrenIds = undefined;
if (parentIdToChildren[runId]) {
hasExpander = true;
childrenIds = parentIdToChildren[runId].map((cIdx) => runInfos[cIdx].run_uuid);
}
return [
{
idx,
isParent: true,
hasExpander,
expanderOpen: ExperimentViewUtil.isExpanderOpen(runsExpanded, runId),
childrenIds,
runId,
},
];
});
const mergedRows = [];
parentRows.forEach((r) => {
const { runId } = r;
mergedRows.push(r);
const childrenIdxs = parentIdToChildren[runId];
if (childrenIdxs) {
if (ExperimentViewUtil.isExpanderOpen(runsExpanded, runId)) {
const childrenRows = childrenIdxs.map((idx) => {
return { idx, isParent: false, hasExpander: false };
});
mergedRows.push(...childrenRows);
}
}
});
return mergedRows.slice(0);
}
static getRowRenderMetadata({ runInfos, tagsList, runsExpanded, nestChildren }) {
if (nestChildren) {
return this.getNestedRowRenderMetadata({ runInfos, tagsList, runsExpanded });
} else {
return [...Array(runInfos.length).keys()].map((idx) => ({
idx,
isParent: true,
hasExpander: false,
runId: runInfos[idx].run_uuid,
}));
}
}
static getRows({ runInfos, tagsList, runsExpanded, getRow }) {
const mergedRows = ExperimentViewUtil.getRowRenderMetadata({
runInfos,
tagsList,
runsExpanded,
});
return mergedRows.map((rowMetadata) => getRow(rowMetadata));
}
static renderRows(rows) {
return rows.map((row) => {
const style = row.isChild ? { backgroundColor: '#fafafa' } : {};
return (
<tr key={row.key} style={style} className='ExperimentView-row'>
{row.contents}
</tr>
);
});
}
static disableLoadMoreButton({ numRunsFromLatestSearch }) {
if (numRunsFromLatestSearch === null) {
// numRunsFromLatestSearch is null by default, so we should not disable the button
return false;
}
return numRunsFromLatestSearch < SEARCH_MAX_RESULTS;
}
/**
* Obtain the categorized columns (params, metrics & tags) for which the values
* in them have only a single value (or are undefined). For attribute columns,
* obtain the columns for which every value is undefined.
*/
static getCategorizedUncheckedKeysDiffView({
categorizedUncheckedKeys,
paramKeyList,
metricKeyList,
runInfos,
paramsList,
metricsList,
tagsList,
}) {
const attributeColumnsToTags = {
// Leave the User and Source columns out of consideration because they normally have values.
[ATTRIBUTE_COLUMN_LABELS.RUN_NAME]: Utils.runNameTag,
[ATTRIBUTE_COLUMN_LABELS.VERSION]: Utils.gitCommitTag,
[ATTRIBUTE_COLUMN_LABELS.MODELS]: Utils.loggedModelsTag,
};
const attributeKeyList = Object.keys(attributeColumnsToTags);
const tagKeyList = Utils.getVisibleTagKeyList(tagsList);
let attributeColumnsToUncheck = _.difference(
attributeKeyList,
categorizedUncheckedKeys[COLUMN_TYPES.ATTRIBUTES],
);
let paramColumnsToUncheck = _.difference(
paramKeyList,
categorizedUncheckedKeys[COLUMN_TYPES.PARAMS],
);
let metricColumnsToUncheck = _.difference(
metricKeyList,
categorizedUncheckedKeys[COLUMN_TYPES.METRICS],
);
let tagColumnsToUncheck = _.difference(tagKeyList, categorizedUncheckedKeys[COLUMN_TYPES.TAGS]);
const dropDiffColumns = (columns, prevRow, currRow) => {
// What each argument represents:
// | a | b | c | d | e | <- columns
// | --- | --- | --- | --- | --- |
// | - | 1 | - | 1 | 1 | <- prevRow
// | - | - | 1 | 1 | 2 | <- currRow
// | ? | ? | ? | ? | ? |
//
// a, d: may be a diff column, we need to check the next row
// b, c, e: is a diff column, we don't need to check the next row
return columns.filter((col) => {
const prevValue = prevRow[col];
const currValue = currRow[col];
if (!prevValue && !currValue) {
// Case a
return true;
} else if (!prevValue || !currValue) {
// Case b & c
return false;
} else if (prevValue.getValue() === currValue.getValue()) {
// Case d
return true;
} else {
// Case e
return false;
}
});
};
for (const [index] of runInfos.entries()) {
// Drop non-empty attribute columns
attributeColumnsToUncheck = attributeColumnsToUncheck.filter(
(col) => !(attributeColumnsToTags[col] in tagsList[index]),
);
if (index === 0) {
continue;
}
// The following operations need to be skipped in the first iteration.
paramColumnsToUncheck = dropDiffColumns(
paramColumnsToUncheck,
ExperimentViewUtil.toParamsMap(paramsList[index - 1]),
ExperimentViewUtil.toParamsMap(paramsList[index]),
);
metricColumnsToUncheck = dropDiffColumns(
metricColumnsToUncheck,
ExperimentViewUtil.toMetricsMap(metricsList[index - 1]),
ExperimentViewUtil.toMetricsMap(metricsList[index]),
);
tagColumnsToUncheck = dropDiffColumns(
tagColumnsToUncheck,
tagsList[index - 1],
tagsList[index],
);
// Short-circuit loop if there are no more columns to take a look at
if (
attributeColumnsToUncheck.length === 0 &&
paramColumnsToUncheck.length === 0 &&
metricColumnsToUncheck.length === 0 &&
tagColumnsToUncheck.length === 0
) {
break;
}
}
return {
[COLUMN_TYPES.ATTRIBUTES]: _.concat(
categorizedUncheckedKeys[COLUMN_TYPES.ATTRIBUTES],
attributeColumnsToUncheck,
),
[COLUMN_TYPES.PARAMS]: _.concat(
categorizedUncheckedKeys[COLUMN_TYPES.PARAMS],
paramColumnsToUncheck,
),
[COLUMN_TYPES.METRICS]: _.concat(
categorizedUncheckedKeys[COLUMN_TYPES.METRICS],
metricColumnsToUncheck,
),
[COLUMN_TYPES.TAGS]: _.concat(
categorizedUncheckedKeys[COLUMN_TYPES.TAGS],
tagColumnsToUncheck,
),
};
}
/**
* Get the categorized unchecked keys that were in place before hitting the diff switch
* with state changes in between also reflected
* @param preSwitchCategorizedUncheckedKeys the keys that were unchecked before diff-view
* switch was turned on
* @param postSwitchCategorizedUncheckedKeys the keys that were unchecked by turning the
* diff-view switch on
* @param currCategorizedUncheckedKeys currently unchecked keys (possibly includes keys
* that were checked or unchecked while being in the diff view)
*/
static getRestoredCategorizedUncheckedKeys({
preSwitchCategorizedUncheckedKeys,
postSwitchCategorizedUncheckedKeys,
currCategorizedUncheckedKeys,
}) {
const restoredUncheckedKeys = (column_type) => {
// keys that the user checked while being in diff view
const userCheckedKeys = _.difference(
postSwitchCategorizedUncheckedKeys[column_type],
currCategorizedUncheckedKeys[column_type],
);
// keys that the user unchecked while being in diff view
const userUncheckedKeys = _.difference(
currCategorizedUncheckedKeys[column_type],
postSwitchCategorizedUncheckedKeys[column_type],
);
return _.uniq(
_.without(
_.concat(preSwitchCategorizedUncheckedKeys[column_type], userUncheckedKeys),
...userCheckedKeys,
),
);
};
return {
[COLUMN_TYPES.ATTRIBUTES]: restoredUncheckedKeys(COLUMN_TYPES.ATTRIBUTES),
[COLUMN_TYPES.PARAMS]: restoredUncheckedKeys(COLUMN_TYPES.PARAMS),
[COLUMN_TYPES.METRICS]: restoredUncheckedKeys(COLUMN_TYPES.METRICS),
[COLUMN_TYPES.TAGS]: restoredUncheckedKeys(COLUMN_TYPES.TAGS),
};
}
}
export class TreeNode {
constructor(value) {
this.value = value;
this.parent = undefined;
}
/**
* Returns the root node. If there is a cycle it will return undefined;
*/
findRoot() {
const visited = new Set([this.value]);
let current = this;
while (current.parent !== undefined) {
if (visited.has(current.parent.value)) {
return undefined;
}
visited.add(current.value);
current = current.parent;
}
return current;
}
isRoot() {
return this.findRoot().value === this.value;
}
isCycle() {
return this.findRoot() === undefined;
}
}