Gapminder / tools-page

Gapminder tools page vanilla
8 stars 5 forks source link

Core: new feature. Add datasource.drilldown() and datasource.drillup() methods #252

Open angiehjort opened 2 years ago

angiehjort commented 2 years ago

suggested but possibly not optimal API, feel free to improve

marker.data.source.drilldown({dim: "geo", entity: "asia"}) // =>{country: ["chn", "ind", "idn" ..... ]}
marker.data.source.drilldown({dim: "geo", entity: "usa"}) // => null
marker.data.source.drilldown({dim: "geo", entity: ["landlocked"]}) // => {country: ["afg", "rwa",  .... ]}
marker.data.source.drilldown({dim: "geo", entity: ["usa", "landlocked"]}) // => {country: ["afg", "rwa",  .... ]} (same)
marker.data.source.drilldown({dim: "geo", entity: ["asia", "landlocked"]}) // => {country:  [chn", "ind", "afg", "rwa",  .... ] } 

// edge case which i'm unsure how it should be: if a complete entity set is requested it means all countries should be included

marker.data.source.drilldown({dim: "geo", entity: ["asia", "africa", "europe", "americas"]}) // => {country: "*"}

// it should be possible to get an empty array too, but i don't think we have an example in our datasets
marker.data.source.drillup({dim: "geo", entity: "usa"}) // => {world_4region: americas, landlocked: coastline, religion: christian ...}

suggested but possibly not optimal solution, feel free to improve

  1. this is not always an essential operation, so don't do it if no component requests is

  2. search entity domains and sets concepts for concept property drill_up. for example: in open-numbers -compatible datasets we have country.drill_up = "[""world_6region"", ""income_groups"", ""landlocked"", ""g77_and_oecd_countries"", ""main_religion_2008"", ""world_4region"", ""unicef_region"", ""un_sdg_ldc"", ""un_sdg_region""]"

  3. build drillup and drilldown maps for each dim in parent.space which is an entity domain or set, in our case it will be just "geo" or "country". inside each dim a map for each entity, inside each entity a set of drilldowns

  4. request and cache entity data that would allow filling the drillup and drilldown maps

  5. Use JS maps to avoid searching in loops, probably use JS set to avoid duplicates in the output like in drilldowns for ["asia", "landlocked"]

  6. ASYNC: the result depends on concept readiness and possibly also on conceptCatalog to assess if a random set of entities is a complete entity set. then it needs to do its own entity request probably, so it is also async. is it possible to connect it somehow with the existing entity request? should it wrap the result in a promise? or should it have an own readiness observable flag?

angiehjort commented 2 years ago

change of specs for more uniform results: .drilldown({dim: "geo", entity: "usa"}) // =>{country: ["usa"]}

(entity is a drilldown of itself if it is on the bottom level)

https://github.com/vizabi/core/commit/7e8ee65ffcb6c3e6e7a77f17f580dee6289d3145