CartoDB / toolkit

JS library to interact with CARTO APIs in a simple way
https://toolkit-wheat.now.sh
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

Add prototype of requesting metadata for a field #88

Closed manmorjim closed 4 years ago

VictorVelarde commented 4 years ago

Nice start @manmorjim

Some general thoughts (sorry for the "parrafada")

the approach

In carto-js you just can ask a 'flexible query' for a source with dataviews (as for example in https://carto.com/developers/carto-js/examples/#example-formula-widget) but in VL the 'metadata' is strictly tied to the viz. It is internal also, and if you want to have some metadata for a field you must include it in the viz (let's say, "the styles"). In VL it has no interface as the one we're building now (but you can access some of it with functions like globalMin, globalMax....)... I like the carto-js flexibility / simplicity on this (but the performance in VL is bigger).

metadata interface

Regarding the Metadata definition, I think we should use a class, not an interface, and give it a bit more of 'content' / methods (that could wrap different requests or hold static values).

IMO we should probably end with a Metadata like:

metadata
    (a) global-related methods
    (b) field-related methods

What we need now to advance on styling is specially the (b) part, but this way we consider the whole context

I see something like this:

const fieldMetadata = aCARTOSource.metadata.getField(fieldName)

// which could return a FieldInfo object like...

{
 type: 'number, // a string or type with: 'number', 'string', 'date'
  // list of fields depending on the type... 
  min: 0,
  max: 100,
  avg: 50,
  sum: 300
}

In a DOSource I think that we have conceptually just one DOVariable per DOSource (thus 1 field), so maybe we could simplify and have just a aDOSource.metadata.getField() (without the field name).

field info

alasarr commented 4 years ago

It makes sense to me and we've these stats for every dataset in DO, so 😄