@genspectrum/dashboard-components 0.9.0 → 0.9.1

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.
@@ -1649,8 +1649,8 @@ const getMutationTypesSelectorLabel = (displayedMutationTypes) => {
1649
1649
  return type.label;
1650
1650
  }).join(", ");
1651
1651
  };
1652
- const NoDataDisplay = () => {
1653
- return /* @__PURE__ */ u$1("div", { className: "h-full w-full rounded-md border-2 border-gray-100 p-2 flex items-center justify-center", children: /* @__PURE__ */ u$1("div", { children: "No data available." }) });
1652
+ const NoDataDisplay = ({ message = "No data available." }) => {
1653
+ return /* @__PURE__ */ u$1("div", { className: "h-full w-full rounded-md border-2 border-gray-100 p-2 flex items-center justify-center", children: /* @__PURE__ */ u$1("div", { children: message }) });
1654
1654
  };
1655
1655
  const MinMaxRangeSlider = ({
1656
1656
  min,
@@ -5129,9 +5129,9 @@ input.tab:checked + .tab-content,
5129
5129
  .peer:hover ~ .peer-hover\\:visible {
5130
5130
  visibility: visible;
5131
5131
  }
5132
- @container (min-width: 30rem) {
5132
+ @container (min-width: 2rem) {
5133
5133
 
5134
- .\\@\\[30rem\\]\\:visible {
5134
+ .\\@\\[2rem\\]\\:visible {
5135
5135
  visibility: visible;
5136
5136
  }
5137
5137
  }
@@ -7760,6 +7760,11 @@ const tooltip = () => {
7760
7760
  }
7761
7761
  };
7762
7762
  };
7763
+ class NotEnoughDataToComputeFitError extends Error {
7764
+ constructor() {
7765
+ super("Not enough data to compute computeFit");
7766
+ }
7767
+ }
7763
7768
  async function queryRelativeGrowthAdvantage(numerator, denominator, generationTime, lapis, lapisDateField, signal) {
7764
7769
  const fetchNumerator = new FetchAggregatedOperator(numerator, [lapisDateField]);
7765
7770
  const fetchDenominator = new FetchAggregatedOperator(denominator, [lapisDateField]);
@@ -7796,27 +7801,7 @@ async function queryRelativeGrowthAdvantage(numerator, denominator, generationTi
7796
7801
  requestData.k.push(numeratorCounts.get(d2.date) ?? 0);
7797
7802
  }
7798
7803
  });
7799
- const requestPayload = {
7800
- config: {
7801
- alpha: 0.95,
7802
- generationTime,
7803
- initialCasesVariant: 1,
7804
- initialCasesWildtype: 1,
7805
- reproductionNumberWildtype: 1,
7806
- tStart: 0,
7807
- tEnd: maxDate.minus(minDate)
7808
- },
7809
- data: requestData
7810
- };
7811
- const response = await fetch("https://cov-spectrum.org/api/v2/computed/model/chen2021Fitness", {
7812
- method: "POST",
7813
- headers: {
7814
- "Content-Type": "application/json"
7815
- },
7816
- body: JSON.stringify(requestPayload),
7817
- signal
7818
- });
7819
- const responseData = await response.json();
7804
+ const responseData = await computeFit(generationTime, maxDate, minDate, requestData, signal);
7820
7805
  const transformed = {
7821
7806
  ...responseData,
7822
7807
  estimatedProportions: {
@@ -7832,6 +7817,40 @@ async function queryRelativeGrowthAdvantage(numerator, denominator, generationTi
7832
7817
  observedProportions
7833
7818
  };
7834
7819
  }
7820
+ async function computeFit(generationTime, maxDate, minDate, requestData, signal) {
7821
+ const requestPayload = {
7822
+ config: {
7823
+ alpha: 0.95,
7824
+ generationTime,
7825
+ initialCasesVariant: 1,
7826
+ initialCasesWildtype: 1,
7827
+ reproductionNumberWildtype: 1,
7828
+ tStart: 0,
7829
+ tEnd: maxDate.minus(minDate)
7830
+ },
7831
+ data: requestData
7832
+ };
7833
+ let response;
7834
+ try {
7835
+ response = await fetch("https://cov-spectrum.org/api/v2/computed/model/chen2021Fitness", {
7836
+ method: "POST",
7837
+ headers: {
7838
+ "Content-Type": "application/json"
7839
+ },
7840
+ body: JSON.stringify(requestPayload),
7841
+ signal
7842
+ });
7843
+ } catch {
7844
+ throw new UserFacingError(
7845
+ "Failed to compute relative growth advantage",
7846
+ "Could not connect to the server that computes the relative growth advantage. Please try again later."
7847
+ );
7848
+ }
7849
+ if (!response.ok) {
7850
+ throw new NotEnoughDataToComputeFitError();
7851
+ }
7852
+ return await response.json();
7853
+ }
7835
7854
  function toYearMonthDay(d2) {
7836
7855
  const temporalCache = TemporalCache.getInstance();
7837
7856
  return {
@@ -7856,6 +7875,9 @@ const RelativeGrowthAdvantageInner = (componentProps) => {
7856
7875
  return /* @__PURE__ */ u$1(LoadingDisplay, {});
7857
7876
  }
7858
7877
  if (error !== null) {
7878
+ if (error instanceof NotEnoughDataToComputeFitError) {
7879
+ return /* @__PURE__ */ u$1(NoDataDisplay, { message: "It was not possible to estimate the relative growth advantage due to insufficient data in the specified filter." });
7880
+ }
7859
7881
  throw error;
7860
7882
  }
7861
7883
  if (data === null) {
@@ -8818,7 +8840,6 @@ const MutationsOverTimeGrid = ({ data, colorScale }) => {
8818
8840
  gridTemplateRows: `repeat(${shownMutations.length}, 24px)`,
8819
8841
  gridTemplateColumns: `${MUTATION_CELL_WIDTH_REM}rem repeat(${dates.length}, minmax(0.05rem, 1fr))`
8820
8842
  },
8821
- className: "@container",
8822
8843
  children: shownMutations.map((mutation, rowIndex) => {
8823
8844
  return /* @__PURE__ */ u$1(Fragment, { children: [
8824
8845
  /* @__PURE__ */ u$1(
@@ -8895,8 +8916,8 @@ const ProportionCell = ({ value, mutation, date, tooltipPosition, colorScale })
8895
8916
  backgroundColor: getColorWithingScale(value.proportion, colorScale),
8896
8917
  color: getTextColorForScale(value.proportion, colorScale)
8897
8918
  },
8898
- className: `w-full h-full text-center hover:font-bold text-xs group`,
8899
- children: /* @__PURE__ */ u$1("span", { className: "invisible @[30rem]:visible", children: formatProportion(value.proportion, 0) })
8919
+ className: `w-full h-full text-center hover:font-bold text-xs group @container`,
8920
+ children: /* @__PURE__ */ u$1("span", { className: "invisible @[2rem]:visible", children: formatProportion(value.proportion, 0) })
8900
8921
  }
8901
8922
  ) }) });
8902
8923
  };