# Lazy Children (Tree example)

> WestCoast Charts 1.1.5, release, public Core release, on npm. HTML: https://westcoast-charts.com/gallery/tree/lazy-children/ · Index for agents: https://westcoast-charts.com/llms.txt

Nodes marked hasChildren: true load their children on first expand through plotOptions.tree.lazy.load (a Promise; simulated 600 ms latency here). A placeholder card with a spinner shows while loading; a failed load (Services fails once) shows a retry card. childrenLoad / childrenLoadError events.

- Chart type: `tree` (Tree)
- Collection: Tree · Tree
- Raw configuration: https://westcoast-charts.com/gallery-src/tree/lazy-children.js
- Standalone example: https://westcoast-charts.com/embed/samples/wcc/gallery/premium/tree/lazy-children.html

## Setup

```js
import WestCoastCharts from 'west-coast-charts'
import types from 'west-coast-charts/types'
import premium from 'west-coast-charts/premium'

WestCoastCharts.use(types).use(premium)
const WestCoastChartsPremium = premium
WestCoastCharts.setLicenseKey(LICENCE_KEY) // paid production licence; localhost evaluation needs no key
```

## Options

```js
const options = {
  chart: {
    height: 460,
    toolbar: {
      show: false
    },
    type: "tree",
    events: {
      childrenLoad: (e, ctx, o) => log('childrenLoad ' + o.node.name + ': ' + o.children.length + ' items'),
      childrenLoadError: (e, ctx, o) => log('childrenLoadError ' + o.node.name + ': ' + o.error.message + ' (click the card to retry)')
    }
  },
  series: [
    {
      data: [
        {
          name: "Catalogue",
          children: [
            {
              name: "Hardware",
              hasChildren: true
            },
            {
              name: "Software",
              hasChildren: true
            },
            {
              name: "Services",
              hasChildren: true
            }
          ]
        }
      ]
    }
  ],
  plotOptions: {
    tree: {
      orientation: "left-to-right",
      node: {
        template: "compact"
      },
      lazy: {
        load: (node) => new Promise((res, rej) => setTimeout(() => {
              if (node.name === 'Services' && fails-- > 0) return rej(new Error('timeout'))
              res([1, 2, 3, 4].map((i) => ({ name: node.name + ' ' + i, value: PG.int(10, 90), hasChildren: i === 1 })))
            }, PG.noAnim ? 0 : 600))
      }
    }
  },
  theme: {
    mode: "light",
    preset: "coastal"
  }
}

const chart = new WestCoastCharts(document.querySelector('#chart'), options)
await chart.render()
```

## Verify

- Text check (Library 1.1.5): load `west-coast-charts/agent/describe` and call `chart.describe({ format: "json" })` for the actual drawn state. The live reader is on this example’s HTML page.
- Command line (Public agent tools 0.2.3, tested with Library 1.1.5; available from the versioned GitHub release and npm, https://westcoast-charts.com/docs/cli/index.md): `wcc chart export tree-lazy-children.json --out tree-lazy-children.svg --with-table` (save the options above as JSON first)
