visualize-admin / visualization-tool

The tool for visualizing Swiss Open Government Data. Project ownership: Federal Office for the Environment FOEN
https://visualize.admin.ch
BSD 3-Clause "New" or "Revised" License
29 stars 3 forks source link

Multiple error bars rendering when using the API #1580

Closed sam-e-ch closed 3 weeks ago

sam-e-ch commented 3 weeks ago

Describe the bug Thanks for addressing #1558, the error bars aren't in the top left anymore and the thousands of error messages are gone now. However, there still seems to be a problem with the error bars when using the API:

image

To Reproduce The setup is the same as in #1558, see this jsfiddle.

Expected behavior I expect there to only be one error bar per column, like when making a chart in visualize directly:

image

Additional context Maybe related, there seems to be a lot of overlapping <rect> in the DOM for each column, which only happens when using the API (note the same x value for every rect): image

bprusinowski commented 3 weeks ago

Hi @sam-e-ch, thanks for reporting the issue. I investigated, and it looks like a problem with the chart config, which has an empty filters property. When changing the config from issue #1558 to include it, the problem is not there anymore.

{
  version: "3.2.1",
  state: "CONFIGURING_CHART",
  dataSource: {
    type: "sparql",
    url: "https://lindas-cached.cluster.ldbar.ch/query",
  },
  layout: {
    type: "tab",
    meta: {
      title: {
        de: "",
        en: "",
        fr: "",
        it: "",
      },
      description: {
        de: "",
        en: "",
        fr: "",
        it: "",
      },
    },
  },
  chartConfigs: [
    {
      key: "zTuhSfYsiB7W",
      version: "3.2.0",
      meta: {
        title: {
          en: "",
          de: "",
          fr: "",
          it: "",
        },
        description: {
          en: "",
          de: "",
          fr: "",
          it: "",
        },
      },
      cubes: [
        {
          iri: "https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3",
          publishIri:
            "https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3",
          filters: {
            "https://environment.ld.admin.ch/foen/nfi/unitOfReference": {
              type: "single",
              value: "https://ld.admin.ch/country/CHE",
            },
            "https://environment.ld.admin.ch/foen/nfi/classificationUnit": {
              type: "single",
              value:
                "https://environment.ld.admin.ch/foen/nfi/ClassificationUnit/Total",
            },
            "https://environment.ld.admin.ch/foen/nfi/unitOfEvaluation": {
              type: "single",
              value:
                "https://environment.ld.admin.ch/foen/nfi/UnitOfEvaluation/2382",
            },
            "https://environment.ld.admin.ch/foen/nfi/grid": {
              type: "single",
              value: "https://environment.ld.admin.ch/foen/nfi/Grid/410",
            },
            "https://environment.ld.admin.ch/foen/nfi/evaluationType": {
              type: "single",
              value:
                "https://environment.ld.admin.ch/foen/nfi/EvaluationType/1",
            },
          },
        },
      ],
      chartType: "column",
      interactiveFiltersConfig: {
        legend: {
          active: false,
          componentIri: "",
        },
        timeRange: {
          active: false,
          componentIri: "https://environment.ld.admin.ch/foen/nfi/inventory",
          presets: {
            type: "range",
            from: "",
            to: "",
          },
        },
        dataFilters: {
          active: false,
          componentIris: [],
        },
        calculation: {
          active: false,
          type: "identity",
        },
      },
      fields: {
        x: {
          componentIri: "https://environment.ld.admin.ch/foen/nfi/inventory",
          sorting: {
            sortingType: "byAuto",
            sortingOrder: "asc",
          },
        },
        y: {
          componentIri: "https://environment.ld.admin.ch/foen/nfi/Topic/73r",
        },
      },
    },
  ],
  activeChartKey: "zTuhSfYsiB7W",
}

Generally, when it comes to the Preview via API feature, we assume that the config file is "correct" and don't do things like deriving the filters automatically if they are not there (which is the reason why the chart looks correctly when done through the website manually).

Let me know if this makes sense :)

sam-e-ch commented 3 weeks ago

Ah thanks! So if a filter is not set, it just renders all values on top of each other and that's why there are multiple error bars?

Maybe it could be helpful to extend the documentation at https://visualize.admin.ch/docs/charts/preview-via-api to describe the Chart config schema.

bprusinowski commented 3 weeks ago

Yes, exactly, basically we were showing ~4000 bars at once 😅

Thanks for the suggestion, I think this is an area where we can improve. I've added an appropriate issue (https://github.com/visualize-admin/visualization-tool/issues/1583) and we'll check internally how to proceed with it.

Let me know in case of any other questions :)