@genspectrum/dashboard-components 0.18.1 → 0.18.2

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.
@@ -3,13 +3,11 @@ import { type FunctionComponent } from 'preact';
3
3
  import { useMemo, useState } from 'preact/hooks';
4
4
 
5
5
  import { type MutationOverTimeDataMap } from './MutationOverTimeData';
6
- import {
7
- type MutationOverTimeMutationValue,
8
- MUTATIONS_OVER_TIME_MIN_PROPORTION,
9
- } from '../../query/queryMutationsOverTime';
6
+ import { MutationsOverTimeGridTooltip } from './mutations-over-time-grid-tooltip';
7
+ import { type MutationOverTimeMutationValue } from '../../query/queryMutationsOverTime';
10
8
  import { type SequenceType } from '../../types';
11
9
  import { type Deletion, type Substitution } from '../../utils/mutations';
12
- import { type Temporal, type TemporalClass, toTemporalClass, YearMonthDayClass } from '../../utils/temporalClass';
10
+ import { type Temporal } from '../../utils/temporalClass';
13
11
  import { AnnotatedMutation } from '../components/annotated-mutation';
14
12
  import { type ColorScale, getColorWithinScale, getTextColorForScale } from '../components/color-scale-selector';
15
13
  import Tooltip, { type TooltipPosition } from '../components/tooltip';
@@ -181,24 +179,14 @@ const ProportionCell: FunctionComponent<{
181
179
  tooltipPosition: TooltipPosition;
182
180
  colorScale: ColorScale;
183
181
  }> = ({ value, mutation, date, tooltipPosition, colorScale }) => {
184
- const dateClass = toTemporalClass(date);
185
-
186
- const tooltipContent = (
187
- <div>
188
- <p>
189
- <span className='font-bold'>{dateClass.englishName()}</span>
190
- </p>
191
- <p>({timeIntervalDisplay(dateClass)})</p>
192
- <p>{mutation.code}</p>
193
- <TooltipValueDescription value={value} />
194
- </div>
195
- );
196
-
197
182
  const proportion = value?.type === 'belowThreshold' ? 0 : value?.proportion;
198
183
 
199
184
  return (
200
185
  <div className={'py-1 w-full h-full'}>
201
- <Tooltip content={tooltipContent} position={tooltipPosition}>
186
+ <Tooltip
187
+ content={<MutationsOverTimeGridTooltip mutation={mutation} date={date} value={value} />}
188
+ position={tooltipPosition}
189
+ >
202
190
  <div
203
191
  style={{
204
192
  backgroundColor: getColorWithinScale(proportion, colorScale),
@@ -217,63 +205,4 @@ const ProportionCell: FunctionComponent<{
217
205
  );
218
206
  };
219
207
 
220
- const TooltipValueDescription: FunctionComponent<{ value: MutationOverTimeMutationValue }> = ({ value }) => {
221
- if (value === null) {
222
- return <p>No data</p>;
223
- }
224
-
225
- const proportion =
226
- value.type === 'belowThreshold'
227
- ? `<${formatProportion(MUTATIONS_OVER_TIME_MIN_PROPORTION)}`
228
- : formatProportion(value.proportion);
229
-
230
- return (
231
- <>
232
- <p>Proportion: {proportion}</p>
233
- <TooltipValueCountsDescription value={value} />
234
- </>
235
- );
236
- };
237
-
238
- const TooltipValueCountsDescription: FunctionComponent<{
239
- value: NonNullable<MutationOverTimeMutationValue>;
240
- }> = ({ value }) => {
241
- switch (value.type) {
242
- case 'wastewaterValue':
243
- return;
244
- case 'belowThreshold':
245
- return (
246
- <>
247
- <p>{value.totalCount} samples are in the timeframe</p>
248
- <p>none or less than {formatProportion(MUTATIONS_OVER_TIME_MIN_PROPORTION)} have the mutation</p>
249
- </>
250
- );
251
- case 'value':
252
- return (
253
- <>
254
- <p>{value.totalCount} samples are in the timeframe</p>
255
- <p>
256
- {totalCountWithCoverage(value.count, value.proportion)} have coverage, of those {value.count}{' '}
257
- have the mutation
258
- </p>
259
- </>
260
- );
261
- }
262
- };
263
-
264
- function totalCountWithCoverage(count: number, proportion: number) {
265
- if (count === 0) {
266
- return 0;
267
- }
268
- return Math.round(count / proportion);
269
- }
270
-
271
- const timeIntervalDisplay = (date: TemporalClass) => {
272
- if (date instanceof YearMonthDayClass) {
273
- return date.toString();
274
- }
275
-
276
- return `${date.firstDay.toString()} - ${date.lastDay.toString()}`;
277
- };
278
-
279
208
  export default MutationsOverTimeGrid;
@@ -98,7 +98,7 @@ export const TestRenderAttributesInHtmlInsteadOfUsingPropertyExpression: StoryOb
98
98
  <gs-date-range-filter
99
99
  .dateRangeOptions=${args.dateRangeOptions}
100
100
  earliestDate="${args.earliestDate}"
101
- value="${args.value}"
101
+ value="${args.value ?? 'null'}"
102
102
  width="${args.width}"
103
103
  lapisDateField="${args.lapisDateField}"
104
104
  placeholder="${args.placeholder}"
@@ -38,12 +38,14 @@ import { PreactLitAdapter } from '../PreactLitAdapter';
38
38
  * Use this event, when you want to use the filter directly as a LAPIS filter.
39
39
  *
40
40
  *
41
- * @fires {CustomEvent<{ string | {dateFrom: string, dateTo: string}}>} gs-date-range-option-changed
41
+ * @fires {CustomEvent<string | {dateFrom: string, dateTo: string} | null>} gs-date-range-option-changed
42
42
  * Fired when:
43
43
  * - The select field is changed,
44
44
  * - A date is selected in either of the date pickers,
45
- * - A date was typed into either of the date input fields, and the input field loses focus ("on blur").
46
- * Contains the selected dateRangeOption or when users select custom values it contains the selected dates.
45
+ * - A date was typed into either of the date input fields, and the input field loses focus ("on blur"),
46
+ * - The user deletes the current value by clicking the 'x' button.
47
+ * Contains the selected dateRangeOption or when users select custom values it contains the selected dates
48
+ * or `null` when the input was deleted.
47
49
  *
48
50
  * Use this event, when you want to control this component in your JS application.
49
51
  * You can supply the `detail` of this event to the `value` attribute of this component.
@@ -80,7 +82,7 @@ export class DateRangeFilterComponent extends PreactLitAdapter {
80
82
  @property({
81
83
  converter: (value) => {
82
84
  if (value === null) {
83
- return undefined;
85
+ return null;
84
86
  }
85
87
  try {
86
88
  const result = JSON.parse(value) as unknown;
@@ -93,7 +95,7 @@ export class DateRangeFilterComponent extends PreactLitAdapter {
93
95
  }
94
96
  },
95
97
  })
96
- value: string | { dateFrom?: string; dateTo?: string } | undefined = undefined;
98
+ value: string | { dateFrom?: string; dateTo?: string } | null = null;
97
99
 
98
100
  /**
99
101
  * The width of the component.