 spec = {
   selector: '.cont'
   size:
-    width: 600
+    width:  800
     height: 600
   dataSpec:
     from: data
     dimensions:
+      Time:   { type: 'continuous', bin: 'second' }
       Letter: { type: 'categorical' }
       Number: { type: 'ordinal' }
     metrics:
+      Const:  { agg: 'const' }
       Count:  { agg: 'count' }
-      Walk:   { agg: 'avg' }
+      Walk:   { agg: 'average' }
   plot:
     type: 'facet'
+    method: 'vertical'
+    mapping: { area: 'Const' }
     split: 'Letter'
     scale:
-      x: { type: 'linear', column: 'Time' }
-    plot:
-      type: 'points'
-      mapping:
-        x: 'Time'
-        y: 'Walk'
-        color: 'Letter'
-      scale:
-        y: { type: 'linear', column: 'Walk' }
-        color: { type: 'color', column: 'Letter' }
+      x: { type: 'linear', from: 'Time' }
+    # plot:
+    #   split: 'Time'
+    #   type: 'point'
+    #   mapping:
+    #     x: 'Time'
+    #     y: 'Walk'
+    #     color: 'Letter'
+    #   scale:
+    #     y: { type: 'linear', from: 'Walk' }
+    #     color: { type: 'color', from: 'Letter' }
 }
 
 #facet.plot spec
-facet.makeData spec
-
-
-
+console.log '-----------'
+console.log facet.makeData(spec)
+console.log '-----------'
+
+testCarData = [
+  { make: 'Honda',  model: 'Civic',   price: 10000 }
+  { make: 'Honda',  model: 'Civic',   price: 10100 }
+  { make: 'Honda',  model: 'Element', price: 13000 }
+  { make: 'Toyota', model: 'Corrola', price: 11000 }
+  { make: 'Toyota', model: 'Corrola', price: 11100 }
+  { make: 'BMW',    model: 'M3',      price: 51000 }
+  { make: 'BMW',    model: 'M5',      price: 61000 }
+]
+
+console.log facet.data(testCarData).query {
+  dimensions:
+    'Make': { type: 'categorical' }
+    'Model': { type: 'categorical' }
+  metrics:
+    'Total Price': { agg: 'sum', column: 'price' }
+    'Avg Price': { agg: 'average', column: 'price' }
+    'Count': { agg: 'count' }
+  splits: [
+    { split: 'Make',  apply: ['Count', 'Total Price', 'Avg Price'] }
+    { split: 'Model', apply: ['Count', 'Total Price', 'Avg Price'] }
+  ]
+}
+
+# what is the most common model of car for each manufacturer
+# carSales.split('Mfr', [], 'alphbetic').split('Model', 'count', 'sort desc limit 1')
+# carSales.split('Mfr', Model_most_popular, 'alphbetic')
+

# Dimension = {row} -> String
# Metric = {row} -> Number
# [Metric] = {row} -> [Number]

aggregartion = {
  sum: (values) ->
    s = 0
    s += v for v in values
    return s

  average: (values) ->
    s = 0
    s += v for v in values
    return s / values.length
}

sortedUniq = (arr) ->
  u = []

  ###

  plots = {
    facet: (cont, dataCtx, {split, scale, mapping, plot}) ->
      fsplit = acc(split)
      scale or= {}

      dataFn = (d,i) ->
        { data, scaleFn, size } = dataCtx.call(this,d,i)
        scaleFn = copy(scaleFn)

        buckets = data.map (d) -> d.$split[split]

        if scale.x
          scaleFn.x = facet.scale(scale.x, data)

        if scale.y
          scaleFn.y = facet.scale(scale.y, data, true)

        if scale.color
          scaleFn.color = facet.scale(scale.color, data)

        return cross {
          d: data.$split
          s: [scaleFn]
          e: [{ width: size.width, height: size.height, num: buckets.length, fsplit }]
        }

      cont.datum(dataFn)
      sel = cont.selectAll('g').data((d) -> d)
      sel.enter().append('g')

      sel.exit().remove()
      sel
        .attr('transform', (d) -> s = d.s.vertical; "translate(0, #{s(d.e.fsplit(d.d)) * d.e.height})")

      if plot
        plot = [plot] unless plot.splice
        for p in plot
          doPlot(
            sel
            (d) -> { data:d.d.$ident, scaleFn:d.s, size: { width: d.e.width, height: d.e.height/d.e.num }}
            p
          )

      return

    # ------------------------------------------------------------------------------------
    points: (cont, dataCtx, {mapping, scale, plot}) ->
