diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ac6c7293..501fe91a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali ## Unreleased +- Performance + - (min & max)Inclusive values stored in `sh:or` are now also retrieved - Style - Map now outlines shapes on hover, instead of changing their colors - Maintenance diff --git a/app/domain/data.ts b/app/domain/data.ts index 034393846..5ca577f4b 100644 --- a/app/domain/data.ts +++ b/app/domain/data.ts @@ -78,7 +78,6 @@ export const parseRDFLiteral = (value: Literal): T => { case "string": case "boolean": return v as T; - // return v === "true" ? true : false; case "float": case "integer": case "long": @@ -96,13 +95,6 @@ export const parseRDFLiteral = (value: Literal): T => { case "unsignedShort": case "unsignedByte": return +v as T; - // TODO: Figure out how to preserve granularity of date (maybe include interval?) - // case "date": - // case "time": - // case "dateTime": - // case "gYear": - // case "gYearMonth": - // return new Date(v); default: return v as T; } diff --git a/app/rdf/queries.ts b/app/rdf/queries.ts index c55ea0b7b..e3e442ca5 100644 --- a/app/rdf/queries.ts +++ b/app/rdf/queries.ts @@ -220,19 +220,48 @@ export const getCubeDimensionValues = async ({ }): Promise => { const { dimension, cube, locale, data } = rdimension; - if ( - typeof dimension.minInclusive !== "undefined" && - typeof dimension.maxInclusive !== "undefined" && - data.dataKind !== "Time" && - data.scaleType !== "Ordinal" - ) { - const min = parseObservationValue({ value: dimension.minInclusive }) ?? 0; - const max = parseObservationValue({ value: dimension.maxInclusive }) ?? 0; - - return [ - { value: min, label: `${min}` }, - { value: max, label: `${max}` }, - ]; + if (data.dataKind !== "Time" && data.scaleType !== "Ordinal") { + if ( + typeof dimension.minInclusive !== "undefined" && + typeof dimension.maxInclusive !== "undefined" + ) { + const min = parseObservationValue({ value: dimension.minInclusive }) ?? 0; + const max = parseObservationValue({ value: dimension.maxInclusive }) ?? 0; + + return [ + { value: min, label: `${min}` }, + { value: max, label: `${max}` }, + ]; + } + + // Try to get min/max values from a list of values. + let listItemPointer = dimension.out(ns.sh.or); + + while ( + listItemPointer.out(ns.rdf.rest).value && + // Only try until we reach the end of the list. + !listItemPointer.out(ns.rdf.rest).term?.equals(ns.rdf.nil) + ) { + const item = listItemPointer.out(ns.rdf.first); + const itemMin = item.out(ns.sh.minInclusive); + const itemMax = item.out(ns.sh.maxInclusive); + + if ( + typeof itemMin.value !== "undefined" && + typeof itemMax.value !== "undefined" + ) { + const min = +itemMin.value; + const max = +itemMax.value; + + return [ + { value: min, label: `${min}` }, + { value: max, label: `${max}` }, + ]; + } + + // Move to next list item. + listItemPointer = listItemPointer.out(ns.rdf.rest); + } } if (shouldLoadMinMaxValues(rdimension)) {