Skip to content

Commit

Permalink
[WIP][Vega] Implement context filter modification
Browse files Browse the repository at this point in the history
elastic#17210

Testing code (click button)

```
{
  "$schema": "https://vega.github.io/schema/vega/v3.json",
  "marks": [
    {
      "name": "myButton",
      "type": "rect",
      "encode": {
        "enter": {
          "xc": {"signal": "width/2"},
          "yc": {"signal": "height/2"},
          "width": {"signal": "width*0.8"},
          "height": {"signal": "height*0.8"},

          "cornerRadius": {"value": 6},
          "strokeWidth": {"value": 10}
        },
        "update": {
          "stroke": {"value": "gray"},
          "fill": {"value": "lightgray"}
        },
        "hover": {"fill": {"value": "gray"}}
      }
    }
  ],
  "signals": [
    {
      "name": "%ADD_FILTER%",
      "on": [
        {
          "events": "@mybutton:click",
          "update": "{field: 'SRC', value: 10, operator: 'IS'}"
        }
      ]
    }
  ]
}
```
  • Loading branch information
nyurik committed Apr 6, 2018
1 parent 1ecddb4 commit 28d87e0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"validate-npm-package-name": "2.2.2",
"vega-lib": "^3.2.1",
"vega-lite": "^2.3.1",
"vega-spec-injector": "^0.0.2",
"vega-schema-url-parser": "1.0.0",
"vision": "4.1.0",
"webpack": "3.6.0",
Expand Down
5 changes: 5 additions & 0 deletions src/core_plugins/vega/public/data_model/vega_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import hjson from 'hjson';
import { Utils } from './utils';
import { EmsFileParser } from './ems_file_parser';
import { UrlParser } from './url_parser';
import Vsi from 'vega-spec-injector';

const DEFAULT_SCHEMA = 'https://vega.github.io/schema/vega/v3.0.json';

Expand Down Expand Up @@ -80,6 +81,10 @@ export class VegaParser {
}

this._calcSizing();

const vsi = new Vsi(this._onWarning.bind(this));

vsi.addToList(this.spec, `signals`, ['%ADD_FILTER%']);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/core_plugins/vega/public/vega_view/vega_base_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ export class VegaBaseView {
return false;
}

setView(view) {
this._view = view;
if (view) {
view.addSignalListener('%ADD_FILTER%',
/**
* @param {string} sig signal name
* @param {object} value filter object to add
* @param {string} value.field name of the filter field
* @param {string|number} value.value the value of the filter
* @param {string} value.operator how value should be compared. "IS" by default.
*/
(/* sig, value */) => {



// TODO: add new filter


}
);
}
}

/**
* Set global debug variable to simplify vega debugging in console. Show info message first time
*/
Expand Down
4 changes: 2 additions & 2 deletions src/core_plugins/vega/public/vega_view/vega_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export class VegaView extends VegaBaseView {
if (this._parser.useHover) view.hover();

this._addDestroyHandler(() => {
this._view = null;
this.setView(null);
view.finalize();
});

await view.runAsync();
this._view = view;
this.setView(view);
}
}

0 comments on commit 28d87e0

Please sign in to comment.