okfn/openspending — Issue #435: Provide common interface for all view widgets
Author: pudo
Created: 2012-02-28 15:19:22+00:00
State: open

At the moment, instantiation and state serialisation for view widgets (explorer, treemap, bubbles) is inconsistent, which means hard-coding custom to each visualisation in OpenSpending (see okfn/openspending.plugin.treemap for an example).

We should have a front-end interface class defining how we expect view widgets to behave.

Current proposal:

```coffee
class OpenSpending.IViewWidget
# Parameters:
# element: a DOM node in which to instantiate the widget
# context: a JSON object defining the OpenSpending context (see details below) [optional]
# state: a JSON serialisation of the state of the widget
constructor: (element, context={}, state={}) ->
throw "Not Implemented"

# Serialize the current widget state to a JSON object
serialize: () ->
throw "Not Implemented"
```

The `state` parameter to the constructor is entirely "schemaless", and is simply whatever the `serialize` method spits out.

The exact format of the `context` parameter remains to be decided upon, but should probably provide some information to the widget about, e.g. which dataset is being viewed, which dimension page the user is on, and so on.