Skip to content

Commit

Permalink
Updated code to use because constraintResults have been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
goetzrrGit committed Dec 5, 2023
1 parent 23bc7a5 commit 89bc3c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
29 changes: 16 additions & 13 deletions src/components/timeline/TimelineHistogram.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { brushX, type BrushSelection, type D3BrushEvent } from 'd3-brush';
import type { ScaleTime } from 'd3-scale';
import { select, type Selection } from 'd3-selection';
import { isEmpty } from 'lodash-es';
import { createEventDispatcher } from 'svelte';
import type { ActivityDirective } from '../../types/activity';
import type { ConstraintResult } from '../../types/constraint';
Expand Down Expand Up @@ -222,21 +223,23 @@
// Compute constraint violations histogram
constraintViolationsToRender = [];
constraintResults.forEach(constraintResult => {
constraintResult.violations.forEach(violation => {
violation.windows.forEach(window => {
if (xScaleMax !== null) {
const xStart = xScaleMax(window.start);
const xEnd = xScaleMax(window.end);
const clampedStart = xStart < 0 ? 0 : xStart;
const clampedEnd = xEnd > drawWidth ? drawWidth : xEnd;
const width = clampedEnd - clampedStart;
const clampedWidth = width <= 0 ? 5 : width;
constraintViolationsToRender.push({ width: clampedWidth, x: clampedStart });
}
constraintResults
.filter(result => !isEmpty(result))
.forEach(constraintResult => {
constraintResult.violations.forEach(violation => {
violation.windows.forEach(window => {
if (xScaleMax !== null) {
const xStart = xScaleMax(window.start);
const xEnd = xScaleMax(window.end);
const clampedStart = xStart < 0 ? 0 : xStart;
const clampedEnd = xEnd > drawWidth ? drawWidth : xEnd;
const width = clampedEnd - clampedStart;
const clampedWidth = width <= 0 ? 5 : width;
constraintViolationsToRender.push({ width: clampedWidth, x: clampedStart });
}
});
});
});
});
}
function brushed({ selection }: D3BrushEvent<number[]>) {
Expand Down
18 changes: 13 additions & 5 deletions src/components/timeline/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

<script lang="ts">
import { select } from 'd3-selection';
import { find } from 'lodash-es';
import { constraintResponseMap } from '../../stores/constraints';
import type { ActivityDirective } from '../../types/activity';
import type { ConstraintResult } from '../../types/constraint';
import type { ConstraintResponse, ConstraintResult } from '../../types/constraint';
import type { Span } from '../../types/simulation';
import type { LinePoint, MouseOver, Point, XRangePoint } from '../../types/timeline';
import { getDoyTime } from '../../utilities/time';
Expand Down Expand Up @@ -179,14 +181,20 @@
}
function textForConstraintViolation(constraintViolation: ConstraintResult): string {
const { constraintName } = constraintViolation;
return `
const matchResponse: ConstraintResponse = find(
Object.values(constraintResponseMap),
(response: ConstraintResponse) => response.results === constraintViolation,
);
return matchResponse
? `
<div>
Constraint Violation
<br>
Name: ${constraintName}
Name: ${matchResponse.constraintName}
</div>
`;
`
: '';
}
function textForLinePoint(point: LinePoint): string {
Expand Down

0 comments on commit 89bc3c7

Please sign in to comment.