Repository: vega/vega-lite (ts)

Issue:
Should we add `order` property to `encDef.sort`?
Currently Vega-lite’s `encDef.sort` looks exactly like vega Scale's `DataRef.sort`, which only contains `aggr` and `op` properties while the `order` field is deprecated as same mechanism can be achieved by using `reverse` property of the scale.  

However, in vega-lite’s encoding definition, `sort` is another top-level object, not a part of `scale`.  If we do not have `order` property.  Specifying descending sort would require specifying both `sort` and `scale` like the following Barley example, which is kind of miss the point for extracting `sort` from `scale`. 

```js
{
      data: {url: 'data/barley.json'},
      marktype: 'point',
      encoding: {
        x: {type: 'Q',name: 'yield'},
        y: {
          name: 'variety',
          type: 'O',
          sort: {field: 'yield', op: 'median'},
          __scale: {reverse: true}__
        },
        row: {
          type: 'O',
          name: 'site',
          sort: {field: 'yield', op: 'median'},
          __scale: {reverse: true}__
        },
        color: {type: 'N',name: 'year'}
      }
    }
``` 

By having `order` property, the spec can be a bit nicer:

```
{
  data: {url: 'data/barley.json'},
  marktype: 'point',
  encoding: {
    x: {type: 'Q',name: 'yield'},
    y: {
      name: 'variety',
      type: 'O',
      sort: {field: 'yield', op: ‘median’, __order:’desc'__}
    },
    row: {
      type: 'O',
      name: 'site',
      sort: {field: 'yield', op: 'median', __order:’desc’__},
    },
    color: {type: 'N',name: 'year'}
  }
}
```


Pull request description:
Change default values for sort and stack
- Make encoding definition `sort=‘ascending’` by default  — closes #663.
- No longer add `’-‘` to `sortby` in the output `stack` transform by default 

Patch:
diff --git a/gallery/examples.js b/gallery/examples.js
index 7a0dba7aa..a027d8152 100644
--- a/gallery/examples.js
+++ b/gallery/examples.js
@@ -165,7 +165,7 @@ var EXAMPLES = [
       'data': {'url': 'data/cars.json'}
     }
   },{
-    title: 'Stacked Bar Chart',
+    title: 'Horizontal Stacked Bar Chart',
     spec: {
       'marktype': 'bar',
       'encoding': {
@@ -175,6 +175,17 @@ var EXAMPLES = [
       },
       'data': {'url': 'data/barley.json'}
     }
+  },{
+    title: 'Vertical Stacked Bar Chart',
+    spec: {
+      'marktype': 'bar',
+      'encoding': {
+        'y': {'name': 'yield','type': 'Q','aggregate': 'sum'},
+        'x': {'name': 'variety','type': 'N'},
+        'color': {'name': 'site', 'type': 'N'}
+      },
+      'data': {'url': 'data/barley.json'}
+    }
   },{
     title: '1D Stack Bar Chart',
     spec: {
diff --git a/src/compiler/stack.js b/src/compiler/stack.js
index af4f26e2d..45ed4e66b 100644
--- a/src/compiler/stack.js
+++ b/src/compiler/stack.js
@@ -17,7 +17,7 @@ function stacking(encoding, mdef, stack) {
     type: 'stack',
     groupby: [encoding.fieldRef(groupby)],
     field: encoding.fieldRef(field),
-    sortby: [(stack.properties.reverse ? '' : '-') + encoding.fieldRef(stack.stack)],
+    sortby: [(stack.properties.reverse ? '-' : '') + encoding.fieldRef(stack.stack)],
     output: {start: startField, end: endField}
   };
 
diff --git a/src/schema/schema.js b/src/schema/schema.js
index 9772d4cb7..578eea232 100644
--- a/src/schema/schema.js
+++ b/src/schema/schema.js
@@ -226,12 +226,12 @@ var sortMixin = {
   type: 'object',
   properties: {
     sort: {
-      default: undefined,
+      default: 'ascending',
       supportedTypes: toMap([N, O]),
       oneOf: [
         {
           type: 'string',
-          enum: ['ascending', 'descending']
+          enum: ['ascending', 'descending', 'unsorted']
         },
         { // sort by aggregation of another field
           type: 'object',


Test patch:
diff --git a/test/compiler/scale.spec.js b/test/compiler/scale.spec.js
index 983e2d8c7..87cc6d149 100644
--- a/test/compiler/scale.spec.js
+++ b/test/compiler/scale.spec.js
@@ -193,7 +193,8 @@ describe('vl.compile.scale', function() {
         expect(vlscale.domain(encoding, 'y', 'ordinal'))
           .to.eql({
             data: RAW,
-            field: 'origin'
+            field: 'origin',
+            sort: true
           });
       });
     });