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 897cc13
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 12 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: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
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: [chartConfig.fields.x.componentIri], // FIXME: Other fields may also be measures
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: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
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: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const ChartMapVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [
dimensions: [
chartConfig.fields.areaLayer.measureIri,
chartConfig.fields.symbolLayer.measureIri,
],
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: [chartConfig.fields.y.componentIri], // FIXME: Other fields may also be measures
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const ChartScatterplotVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures: [
dimensions: [
chartConfig.fields.x.componentIri,
chartConfig.fields.y.componentIri,
], // FIXME: Other fields may also be measures
Expand Down
2 changes: 1 addition & 1 deletion app/charts/table/chart-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const ChartTableVisualization = ({
variables: {
locale,
iri: dataSetIri,
measures,
dimensions: measures,
filters: chartConfig.filters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/components/data-download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const DataDownload = memo(
variables: {
locale,
iri: dataSetIri,
measures, // FIXME: Other fields may also be measures
dimensions: measures, // 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: measures,
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 897cc13

Please sign in to comment.