Skip to content

Commit

Permalink
perf: Retrieve (min|max)Inclusive values stored behind sh:or
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Oct 19, 2023
1 parent 830dec3 commit 25c562e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions app/domain/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export const parseRDFLiteral = <T = ObservationValue>(value: Literal): T => {
case "string":
case "boolean":
return v as T;
// return v === "true" ? true : false;
case "float":
case "integer":
case "long":
Expand All @@ -96,13 +95,6 @@ export const parseRDFLiteral = <T = ObservationValue>(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;
}
Expand Down
43 changes: 30 additions & 13 deletions app/rdf/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,36 @@ export const getCubeDimensionValues = async ({
}): Promise<DimensionValue[]> => {
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}` },
];
}

const firstPointer = dimension.out(ns.sh.or).out(ns.rdf.first);
const firstMin = firstPointer.out(ns.sh.minInclusive);
const firstMax = firstPointer.out(ns.sh.maxInclusive);

if (
typeof firstMin.value !== "undefined" &&
typeof firstMax.value !== "undefined"
) {
const min = +firstMin.value;
const max = +firstMax.value;

return [
{ value: min, label: `${min}` },
{ value: max, label: `${max}` },
];
}
}

if (shouldLoadMinMaxValues(rdimension)) {
Expand Down

0 comments on commit 25c562e

Please sign in to comment.