Skip to content

Commit

Permalink
Merge pull request #1031 from visualize-admin/perf/only-fetch-necessa…
Browse files Browse the repository at this point in the history
…ry-components

perf: Only fetch necessary components
  • Loading branch information
bprusinowski authored May 15, 2023
2 parents d036dc6 + ad91746 commit 9892449
Show file tree
Hide file tree
Showing 25 changed files with 326 additions and 86 deletions.
12 changes: 9 additions & 3 deletions app/charts/area/chart-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { memo } from "react";

import { Areas } from "@/charts/area/areas";
import { AreaChart } from "@/charts/area/areas-state";
import { ChartLoadingWrapper } from "@/charts/chart-loading-wrapper";
import { AxisHeightLinear } from "@/charts/shared/axis-height-linear";
import { AxisTime, AxisTimeDomain } from "@/charts/shared/axis-width-time";
import { BrushTime } from "@/charts/shared/brush";
import { getChartConfigComponentIris } from "@/charts/shared/chart-helpers";
import { ChartContainer, ChartSvg } from "@/charts/shared/containers";
import { Ruler } from "@/charts/shared/interaction/ruler";
import { Tooltip } from "@/charts/shared/interaction/tooltip";
Expand All @@ -24,20 +26,23 @@ import {
} from "@/graphql/query-hooks";
import { useLocale } from "@/locales/use-locale";

import { ChartLoadingWrapper } from "../chart-loading-wrapper";

export const ChartAreasVisualization = ({
dataSetIri,
dataSource,
chartConfig,
queryFilters,
published,
}: {
dataSetIri: string;
dataSource: DataSource;
chartConfig: AreaConfig;
queryFilters: QueryFilters;
published: boolean;
}) => {
const locale = useLocale();
const componentIrisToFilterBy = published
? getChartConfigComponentIris(chartConfig)
: undefined;
const [metadataQuery] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand All @@ -51,6 +56,7 @@ export const ChartAreasVisualization = ({
iri: dataSetIri,
sourceType: dataSource.type,
sourceUrl: dataSource.url,
componentIris: componentIrisToFilterBy,
locale,
},
});
Expand All @@ -60,7 +66,7 @@ export const ChartAreasVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
dimensions: null,
componentIris: componentIrisToFilterBy,
filters: queryFilters,
},
});
Expand Down
12 changes: 9 additions & 3 deletions app/charts/column/chart-column.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { memo } from "react";

import { ChartLoadingWrapper } from "@/charts/chart-loading-wrapper";
import {
ColumnsGrouped,
ErrorWhiskers as ErrorWhiskersGrouped,
Expand All @@ -16,6 +17,7 @@ import {
AxisWidthBandDomain,
} from "@/charts/shared/axis-width-band";
import { BrushTime } from "@/charts/shared/brush";
import { getChartConfigComponentIris } from "@/charts/shared/chart-helpers";
import { ChartContainer, ChartSvg } from "@/charts/shared/containers";
import { Tooltip } from "@/charts/shared/interaction/tooltip";
import { LegendColor } from "@/charts/shared/legend-color";
Expand All @@ -34,20 +36,23 @@ import {
} from "@/graphql/query-hooks";
import { useLocale } from "@/locales/use-locale";

import { ChartLoadingWrapper } from "../chart-loading-wrapper";

export const ChartColumnsVisualization = ({
dataSetIri,
dataSource,
chartConfig,
queryFilters,
published,
}: {
dataSetIri: string;
dataSource: DataSource;
chartConfig: ColumnConfig;
queryFilters: QueryFilters;
published: boolean;
}) => {
const locale = useLocale();
const componentIrisToFilterBy = published
? getChartConfigComponentIris(chartConfig)
: undefined;
const [metadataQuery] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand All @@ -62,6 +67,7 @@ export const ChartColumnsVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
componentIris: componentIrisToFilterBy,
},
});
const [observationsQuery] = useDataCubeObservationsQuery({
Expand All @@ -70,7 +76,7 @@ export const ChartColumnsVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
dimensions: null,
componentIris: componentIrisToFilterBy,
filters: queryFilters,
},
});
Expand Down
12 changes: 9 additions & 3 deletions app/charts/line/chart-lines.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { memo } from "react";

import { ChartLoadingWrapper } from "@/charts/chart-loading-wrapper";
import { Lines } from "@/charts/line/lines";
import { LineChart } from "@/charts/line/lines-state";
import { AxisHeightLinear } from "@/charts/shared/axis-height-linear";
import { AxisTime, AxisTimeDomain } from "@/charts/shared/axis-width-time";
import { BrushTime } from "@/charts/shared/brush";
import { getChartConfigComponentIris } from "@/charts/shared/chart-helpers";
import { ChartContainer, ChartSvg } from "@/charts/shared/containers";
import { HoverDotMultiple } from "@/charts/shared/interaction/hover-dots-multiple";
import { Ruler } from "@/charts/shared/interaction/ruler";
Expand All @@ -25,20 +27,23 @@ import {
} from "@/graphql/query-hooks";
import { useLocale } from "@/locales/use-locale";

import { ChartLoadingWrapper } from "../chart-loading-wrapper";

export const ChartLinesVisualization = ({
dataSetIri,
dataSource,
chartConfig,
queryFilters,
published,
}: {
dataSetIri: string;
dataSource: DataSource;
chartConfig: LineConfig;
queryFilters: QueryFilters;
published: boolean;
}) => {
const locale = useLocale();
const componentIrisToFilterBy = published
? getChartConfigComponentIris(chartConfig)
: undefined;
const [metadataQuery] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand All @@ -53,6 +58,7 @@ export const ChartLinesVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
componentIris: componentIrisToFilterBy,
},
});
const [observationsQuery] = useDataCubeObservationsQuery({
Expand All @@ -61,7 +67,7 @@ export const ChartLinesVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
dimensions: null,
componentIris: componentIrisToFilterBy,
filters: queryFilters,
},
});
Expand Down
15 changes: 10 additions & 5 deletions app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import keyBy from "lodash/keyBy";
import { useMemo } from "react";
import { mesh as topojsonMesh } from "topojson-client";

import { ChartLoadingWrapper } from "@/charts/chart-loading-wrapper";
import { prepareTopojson } from "@/charts/map/helpers";
import { MapComponent } from "@/charts/map/map";
import { MapLegend } from "@/charts/map/map-legend";
import { MapChart } from "@/charts/map/map-state";
import { MapTooltip } from "@/charts/map/map-tooltip";
import { getChartConfigComponentIris } from "@/charts/shared/chart-helpers";
import { ChartContainer } from "@/charts/shared/containers";
import {
BaseLayer,
Expand Down Expand Up @@ -34,24 +37,25 @@ import {
} from "@/graphql/query-hooks";
import { useLocale } from "@/locales/use-locale";

import { ChartLoadingWrapper } from "../chart-loading-wrapper";

import { prepareTopojson } from "./helpers";

export const ChartMapVisualization = ({
dataSetIri,
dataSource,
chartConfig,
queryFilters,
published,
}: {
dataSetIri: string;
dataSource: DataSource;
chartConfig: MapConfig;
queryFilters: QueryFilters;
published: boolean;
}) => {
const locale = useLocale();
const areaDimensionIri = chartConfig.fields.areaLayer?.componentIri || "";
const symbolDimensionIri = chartConfig.fields.symbolLayer?.componentIri || "";
const componentIrisToFilterBy = published
? getChartConfigComponentIris(chartConfig)
: undefined;
const [metadataQuery] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand All @@ -66,6 +70,7 @@ export const ChartMapVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
componentIris: componentIrisToFilterBy,
},
});
const [observationsQuery] = useDataCubeObservationsQuery({
Expand All @@ -74,7 +79,7 @@ export const ChartMapVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
dimensions: null, // FIXME: Try to load less dimensions
componentIris: componentIrisToFilterBy,
filters: queryFilters,
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/charts/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export const MapComponent = () => {
setMap(null);
}}
onLoad={(e) => {
setMap(e.target);
setMap(e.target as mapboxgl.Map);
currentBBox.current = e.target.getBounds().toArray() as BBox;

/**
Expand Down
6 changes: 2 additions & 4 deletions app/charts/map/ref.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Map } from "mapbox-gl";

/**
* We need to access the map from the map controls. Until we have a good solution
* for sibling components, we use a global non-observable ref.
*/
let map: Map | null = null;
let map: mapboxgl.Map | null = null;

const getMap = () => {
return map;
};

const setMap = (d: Map | null) => {
const setMap = (d: mapboxgl.Map | null) => {
map = d;
};

Expand Down
9 changes: 8 additions & 1 deletion app/charts/pie/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { memo } from "react";
import { ChartLoadingWrapper } from "@/charts/chart-loading-wrapper";
import { Pie } from "@/charts/pie/pie";
import { PieChart } from "@/charts/pie/pie-state";
import { getChartConfigComponentIris } from "@/charts/shared/chart-helpers";
import { ChartContainer, ChartSvg } from "@/charts/shared/containers";
import { Tooltip } from "@/charts/shared/interaction/tooltip";
import { LegendColor } from "@/charts/shared/legend-color";
Expand All @@ -27,13 +28,18 @@ export const ChartPieVisualization = ({
dataSource,
chartConfig,
queryFilters,
published,
}: {
dataSetIri: string;
dataSource: DataSource;
chartConfig: PieConfig;
queryFilters: QueryFilters;
published: boolean;
}) => {
const locale = useLocale();
const componentIrisToFilterBy = published
? getChartConfigComponentIris(chartConfig)
: undefined;
const [metadataQuery] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand All @@ -48,6 +54,7 @@ export const ChartPieVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
componentIris: componentIrisToFilterBy,
},
});
const [observationsQuery] = useDataCubeObservationsQuery({
Expand All @@ -56,7 +63,7 @@ export const ChartPieVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
dimensions: null,
componentIris: componentIrisToFilterBy,
filters: queryFilters,
},
});
Expand Down
12 changes: 9 additions & 3 deletions app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { memo } from "react";

import { ChartLoadingWrapper } from "@/charts/chart-loading-wrapper";
import { Scatterplot } from "@/charts/scatterplot/scatterplot-simple";
import { ScatterplotChart } from "@/charts/scatterplot/scatterplot-state";
import {
Expand All @@ -10,6 +11,7 @@ import {
AxisWidthLinear,
AxisWidthLinearDomain,
} from "@/charts/shared/axis-width-linear";
import { getChartConfigComponentIris } from "@/charts/shared/chart-helpers";
import { ChartContainer, ChartSvg } from "@/charts/shared/containers";
import { Tooltip } from "@/charts/shared/interaction/tooltip";
import { LegendColor } from "@/charts/shared/legend-color";
Expand All @@ -29,20 +31,23 @@ import {
} from "@/graphql/query-hooks";
import { useLocale } from "@/locales/use-locale";

import { ChartLoadingWrapper } from "../chart-loading-wrapper";

export const ChartScatterplotVisualization = ({
dataSetIri,
dataSource,
chartConfig,
queryFilters,
published,
}: {
dataSetIri: string;
dataSource: DataSource;
chartConfig: ScatterPlotConfig;
queryFilters: QueryFilters;
published: boolean;
}) => {
const locale = useLocale();
const componentIrisToFilterBy = published
? getChartConfigComponentIris(chartConfig)
: undefined;
const [metadataQuery] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand All @@ -57,6 +62,7 @@ export const ChartScatterplotVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
componentIris: componentIrisToFilterBy,
},
});
const [observationsQuery] = useDataCubeObservationsQuery({
Expand All @@ -65,7 +71,7 @@ export const ChartScatterplotVisualization = ({
sourceType: dataSource.type,
sourceUrl: dataSource.url,
locale,
dimensions: null,
componentIris: componentIrisToFilterBy,
filters: queryFilters,
},
});
Expand Down
Loading

1 comment on commit 9892449

@vercel
Copy link

@vercel vercel bot commented on 9892449 May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-ixt1.vercel.app
visualization-tool-git-main-ixt1.vercel.app
visualization-tool-alpha.vercel.app

Please sign in to comment.