Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dataset images #1262

Draft
wants to merge 2 commits into
base: ui-3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages_rs/nextclade-cli/src/dataset/dataset_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ pub fn dataset_individual_files_load(
rest_attrs: BTreeMap::default(),
other: serde_json::Value::default(),
},
image: None,
files: DatasetFiles {
reference: "".to_owned(),
pathogen_json: "".to_owned(),
Expand Down
34 changes: 28 additions & 6 deletions packages_rs/nextclade-web/src/components/Main/DatasetInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNil } from 'lodash'
import { darken } from 'polished'
import { darken, transparentize } from 'polished'
import React, { useMemo } from 'react'
import { Badge } from 'reactstrap'
import { useRecoilValue } from 'recoil'
Expand Down Expand Up @@ -194,7 +194,8 @@ export interface DatasetInfoCircleProps {
}

function DatasetInfoAutodetectProgressCircle({ dataset, showSuggestions }: DatasetInfoCircleProps) {
const { attributes, path } = dataset
const { t } = useTranslationSafe()
const { attributes, path, image } = dataset
const { name } = attributes

const circleBg = useMemo(() => darken(0.1)(colorHash(path, { saturation: 0.5, reverse: true })), [path])
Expand All @@ -219,12 +220,17 @@ function DatasetInfoAutodetectProgressCircle({ dataset, showSuggestions }: Datas
return { circleText: `0%`, percentage: 0, countText: `0 / ${numberAutodetectResults}` }
}, [showSuggestions, records, numberAutodetectResults, name.valueFriendly, name.value])

const circle = useMemo(() => {
if (image?.path) {
const title = image?.source ? t('Image credits: {{source}}', { source: image.source }) : undefined
return <CircleImage $bg={circleBg} $image={image.path} title={title} />
}
return <Circle $bg={circleBg}>{circleText}</Circle>
}, [circleBg, circleText, image?.path, image?.source, t])

return (
<>
<CircleBorder $percentage={percentage}>
<Circle $bg={circleBg}>{circleText}</Circle>
</CircleBorder>

<CircleBorder $percentage={percentage}>{circle}</CircleBorder>
<CountText>{countText}</CountText>
</>
)
Expand Down Expand Up @@ -257,6 +263,7 @@ const CircleBorder = styled.div.attrs<CircleBorderProps>((props) => ({
border-radius: 50%;
width: 75px;
height: 75px;
z-index: 10 !important;
`

const Circle = styled.div<{ $bg?: string; $fg?: string }>`
Expand All @@ -271,3 +278,18 @@ const Circle = styled.div<{ $bg?: string; $fg?: string }>`
height: 60px;
font-size: 1.2rem;
`

const CircleImage = styled.div<{ $bg?: string; $fg?: string; $image?: string }>`
background-image: ${(props) => `url(${props.$image})`};
background-color: ${(props) => props.$bg && transparentize(0.75)(props.$bg)};
background-blend-mode: overlay;
background-size: contain;
display: flex;
margin: auto;
justify-content: center;
align-items: center;
border-radius: 50%;
width: 60px;
height: 60px;
font-size: 1.2rem;
`
10 changes: 9 additions & 1 deletion packages_rs/nextclade-web/src/io/fetchDatasetsIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { head, mapValues, sortBy, sortedUniq } from 'lodash'
import semver from 'semver'
import { takeFirstMaybe } from 'src/helpers/takeFirstMaybe'
import urljoin from 'url-join'
import copy from 'fast-copy'

import { Dataset, DatasetFiles, DatasetsIndexJson, DatasetsIndexV2Json, MinimizerIndexVersion } from 'src/types'
import { axiosFetch } from 'src/io/axiosFetch'
Expand All @@ -27,10 +28,17 @@ export function fileUrlsToAbsolute(datasetServerUrl: string, dataset: Dataset):
const restFilesAbs = mapValues(dataset.files, (file) =>
file ? urljoin(datasetServerUrl, dataset.path, dataset.version?.tag ?? '', file) : undefined,
) as DatasetFiles

const files = {
...restFilesAbs,
}
return { ...dataset, files }

const image = copy(dataset.image)
if (image?.path) {
image.path = urljoin(datasetServerUrl, dataset.path, dataset.version?.tag ?? '', image.path)
}

return { ...dataset, files, image }
}

export function getLatestCompatibleEnabledDatasets(datasetServerUrl: string, datasetsIndexJson: DatasetsIndexV2Json) {
Expand Down
4 changes: 3 additions & 1 deletion packages_rs/nextclade/src/analyze/virus_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::analyze::pcr_primer_changes::PcrPrimer;
use crate::coord::position::AaRefPosition;
use crate::coord::range::AaRefRange;
use crate::gene::genotype::Genotype;
use crate::io::dataset::{DatasetAttributes, DatasetCompatibility, DatasetFiles, DatasetVersion};
use crate::io::dataset::{DatasetAttributes, DatasetCompatibility, DatasetFiles, DatasetImage, DatasetVersion};
use crate::io::fs::read_file_to_string;
use crate::io::json::json_parse;
use crate::io::schema_version::{SchemaVersion, SchemaVersionParams};
Expand All @@ -32,6 +32,8 @@ pub struct VirusProperties {

pub attributes: DatasetAttributes,

pub image: Option<DatasetImage>,

pub files: DatasetFiles,

#[serde(default = "bool_false")]
Expand Down
13 changes: 13 additions & 0 deletions packages_rs/nextclade/src/io/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub struct Dataset {

pub attributes: DatasetAttributes,

pub image: Option<DatasetImage>,

pub files: DatasetFiles,

#[serde(default, skip_serializing_if = "DatasetCapabilities::is_default")]
Expand Down Expand Up @@ -302,6 +304,17 @@ impl DatasetAttributeValue {
}
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct DatasetImage {
pub path: Option<String>,

pub source: Option<String>,

#[serde(flatten)]
pub other: serde_json::Value,
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct DatasetAttributes {
Expand Down