Skip to content

Add components for field summary statistics #5

Description

@tomwayson

The purpose of this issue is to think through some of the issues that will come up when trying to design stencil components that can be used both outside and inside the Hub Ember app.

Here's an example of the summary statistic card on a Hub site:

image

In the Hub, this is implemented as a single Ember component that is responsible for both fetching the summary data from the service, and also displaying the data in the page layout. The API (i.e. settings) for that card component are:

{
    "component": {
        "name": "summary-statistic-card",
        "settings": {
            "url": "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/Drug_Overdose_Death_Data/FeatureServer/0",
            "statFieldName": "Number_of_Deaths2015",
            "statFieldType": "esriFieldTypeDouble",
            "statType": "count",
            "statValueAlign": "left",
            "statValueColor": "#ff0000",
            "decimalPlaces": 2,
            "title": "Drug Overdose Deaths",
            "titleAlign": "left",
            "leadingText": "",
            "trailingText": "...",
            "trailingTextAlign": "left",
            "formatNumberGroupings": true,
            "showAsCurrency": false,
            "currencyCode": "USD",
            "where": "STATE like '%VA%'",
            "itemId": "add4efc0b4d543d8b98108f58457aa3c",
            "itemTitle": "Government Services",
            "layerId": 0,
            "layerName": "Museums"
        }
    },
    "width": 4
}

I propose that we split up the responsibilities of that single Ember component into two Stencil components:

  • <hub-field-statistic>: a high level provider component to fetch the data
  • <hub-statistic>: a lower-level presentational component to show the data.

At least the <hub-statistic> can be used in both the Ember app as well as externally.

Here's a first pass at the <hub-statistic> API (based on the above screenshot):

<hub-statistic
  value=1134
  color="#000"
  decimal-places=0
  name="NHV Confirmed Cases"
>
  <div slot="description">This Information is Updated Daily</div>
  <div slot="details">Source: <a rel="nofollow" href="https://covid-19-1-newhavenct.hub.arcgis.com/datasets/a085f0a76f6b44efbdd185bf40243688_1?showData=true">Cases_public</a></div>
</hub-statistic>

In addition to the attributes above, we'd need additional ones to be able to override the defaults:

  align="right"
  name-align="center"
  trailing-label="%"
  description-align="right"
  use-groupings=false
  currency="USD"

It feels like we should be using CSS (variables?) for at least the alignment, and perhaps the color. Though, color in particular is often specific to each instance of the component (i.e. red bad, green good).

I also wonder about using slots, or at least multiple slots, is right for description and details. I think so.

As for the <hub-field-statistic>, it would need these attributes:

<!-- NOTE: could pass layer-url instead of item-id and layer-id -->
<hub-field-statistic
  item-id="a085f0a76f6b44efbdd185bf40243688"
  layer-id="1"
  field="confirmed"
  statistic="max"
  where="name='NewHaven'"
></hub-field-statistic>

It would fetch the data and then render a <hub-statistic> with value={this.state.value}. It could also provide a default value for the details slot, (i.e. the "Source" link), but we'll need to handle a way to provide translations for "Source" and if we want to that link to point to the Hub site's dataset page (instead of the service URl or the AGO item page), then we'll need additional props (like site-url).

One annoyance is that in order to allow consumers to style the wrapped <hub-statistic> component, <hub-field-statistic> would have to expose and pass down basically all of the child component's props other than value (i.e. prop drilling). It's not ideal, but it's manageable.

In the Ember app we can get around that by using a provider component that yields just the data and then applying the display settings directly to the child component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions