 define (require) ->
   _ = require 'underscore'
   $ = require 'jquery'
+  Q = require 'q'
+  Html = require 'html'
   modules = require 'modules'
   http = require 'http'
 

        target: name
        datapoints: _.sortBy points, ([v, t]) -> t

    data_url: ({time_series, start, end, aggregation, group}) ->
      base_url = settings.get 'base_url'
      if not base_url?

      start ?= '1d-ago'
      m = _.map time_series, opentsdb.to_metric_string
      params = {start, end, m, ascii: true}
      "#{base_url}/q?#{$.param params, true}"

    tsd: (params) ->
      http.get(opentsdb.data_url(params), dataType: 'text')
      .then(
        (txt) -> opentsdb.parse_text_response txt, params.group
        # TODO error handling
        (response) -> Q.reject opentsdb.parse_error_response response
      )
