Skip to content

Commit

Permalink
feat: Only load values for non measure dimension and non standard err…
Browse files Browse the repository at this point in the history
…or dimension
  • Loading branch information
ptbrowne committed Feb 18, 2022
1 parent ef8f131 commit a68810b
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/charts/area/chart-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ChartAreasVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
dimensions: null, // FIXME: Try to load less dimensions
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/bar/chart-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const ChartBarsVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [chartConfig.fields.x.componentIri], // FIXME: Other fields may also be measures
dimensions: null, // FIXME: Try to load less dimensions
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/column/chart-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ChartColumnsVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
dimensions: null,
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/line/chart-lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ChartLinesVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
dimensions: null, // FIXME: Try to load less dimensions
filters: queryFilters,
},
});
Expand Down
5 changes: 1 addition & 4 deletions app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ export const ChartMapVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [
chartConfig.fields.areaLayer.measureIri,
chartConfig.fields.symbolLayer.measureIri,
],
dimensions: null, // FIXME: Try to load less dimensions
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/pie/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const ChartPieVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
dimensions: null,
filters: queryFilters,
},
});
Expand Down
5 changes: 1 addition & 4 deletions app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ export const ChartScatterplotVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [
chartConfig.fields.x.componentIri,
chartConfig.fields.y.componentIri,
], // FIXME: Other fields may also be measures
dimensions: null, // FIXME: Other fields may also be measures
filters: queryFilters,
},
});
Expand Down
8 changes: 1 addition & 7 deletions app/charts/table/chart-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ export const ChartTableVisualization = ({
}) => {
const locale = useLocale();

const measures = Object.keys(chartConfig.fields).filter(
(key) =>
chartConfig.fields[key].componentType === "Measure" &&
!chartConfig.fields[key].isHidden
);

const [{ data, fetching, error }] = useDataCubeObservationsQuery({
variables: {
locale,
iri: dataSetIri,
measures,
dimensions: null,
filters: chartConfig.filters,
},
});
Expand Down
28 changes: 3 additions & 25 deletions app/components/data-download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import { saveAs } from "file-saver";
import { memo, ReactNode, useMemo } from "react";
import { Box, Button, Link } from "theme-ui";
import { useQueryFilters } from "../charts/shared/chart-helpers";
import {
ChartConfig,
ChartFields,
isMapConfig,
isTableConfig,
} from "../configurator";
import { ChartConfig, ChartFields } from "../configurator";
import { Observation } from "../domain/data";
import {
DimensionMetaDataFragment,
Expand All @@ -30,24 +25,7 @@ export const DataDownload = memo(
chartConfig: ChartConfig;
}) => {
const locale = useLocale();
const measures = useMemo(
() =>
"y" in chartConfig.fields
? [chartConfig.fields.y.componentIri]
: isTableConfig(chartConfig)
? Object.values(chartConfig.fields).flatMap((f) =>
f.componentType === "Measure" && !f.isHidden
? [f.componentIri]
: []
)
: isMapConfig(chartConfig)
? [
chartConfig.fields.areaLayer.measureIri,
chartConfig.fields.symbolLayer.measureIri,
]
: [],
[chartConfig]
);

const filters = useQueryFilters({
chartConfig,
});
Expand All @@ -56,7 +34,7 @@ export const DataDownload = memo(
variables: {
locale,
iri: dataSetIri,
measures, // FIXME: Other fields may also be measures
dimensions: null, // FIXME: Other fields may also be measures
filters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/configurator/components/chart-options-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const ChartOptionsSelector = ({
variables: {
locale,
iri: state.dataSet,
measures,
dimensions: null,
filters: state.chartConfig.filters,
},
});
Expand Down
13 changes: 13 additions & 0 deletions app/domain/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NominalDimension,
OrdinalDimension,
} from "../graphql/query-hooks";
import { ResolvedDimension } from "../graphql/shared-types";

export type RawObservationValue = Literal | NamedNode;

Expand Down Expand Up @@ -202,3 +203,15 @@ export const isGeoShapesDimension = (
): dimension is GeoShapesDimension => {
return dimension?.__typename === "GeoShapesDimension";
};

export const isStandardErrorResolvedDimension = (dim: ResolvedDimension) => {
return dim.data?.related.some((x) => x.type === "StandardError");
};

export const shouldValuesBeLoadedForResolvedDimension = (
dim: ResolvedDimension
) => {
return !(
dim.data.isMeasureDimension || isStandardErrorResolvedDimension(dim)
);
};
9 changes: 8 additions & 1 deletion app/rdf/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { descending, group, index } from "d3";
import { Maybe } from "graphql-tools";
import {
Cube,
CubeDimension,
Expand All @@ -14,6 +15,7 @@ import {
DimensionValue,
Observation,
parseObservationValue,
shouldValuesBeLoadedForResolvedDimension,
} from "../domain/data";
import { SPARQL_EDITOR, SPARQL_ENDPOINT } from "../domain/env";
import { DataCubeSearchFilter, DataCubeTheme } from "../graphql/query-hooks";
Expand Down Expand Up @@ -250,9 +252,10 @@ export const createCubeDimensionValuesLoader =
};

export const getCubeDimensionValues = async (
{ dimension, cube, locale, data }: ResolvedDimension,
rdimension: ResolvedDimension,
filters?: Filters
): Promise<DimensionValue[]> => {
const { dimension, cube, locale, data } = rdimension;
if (
typeof dimension.minInclusive !== "undefined" &&
typeof dimension.maxInclusive !== "undefined" &&
Expand All @@ -267,6 +270,10 @@ export const getCubeDimensionValues = async (
];
}

if (!shouldValuesBeLoadedForResolvedDimension(rdimension)) {
return [];
}

return await getCubeDimensionValuesWithLabels({
dimension,
cube,
Expand Down
2 changes: 1 addition & 1 deletion app/utils/dimension-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const useHierarchicalDimensionValuesQuery = ({
variables: {
iri: dataSetIri,
locale,
measures: path,
dimensions: path,
},
});

Expand Down

0 comments on commit a68810b

Please sign in to comment.