elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.61k stars 8.22k forks source link

[Vega] Use Kibana dashboard time filter context anywhere in Vega / Vega-lite spec #20872

Open andrassy opened 6 years ago

andrassy commented 6 years ago

In a similar way to referencing %timefilter% in the ES query part of a vega spec, you should be able to access the elements (min / max) of the %timefilter% anywhere within a vega spec.

An example would be to constrain the domain....

"scale":{ "domain":[{ %timefilter%: "min" },{ %timefilter%: "max" }] }

See also discussion https://discuss.elastic.co/t/vega-lite-how-to-clip-bars-that-extend-beyond-view-range/137808/2

nyurik commented 6 years ago

Thanks, this is a very good feature to havey There are really two features:

andrassy commented 6 years ago

Further to this, I think the { %timefilter%: "min" } syntax should be supported inside script_fields of an es query (currently only aggs and query parts). This might be more low-hanging than the full feature request here?

nyurik commented 6 years ago

@andrassy agree, I wasn't aware of the scripted params feature, which makes it much easier. I will add it above.

hongphuc95 commented 5 years ago

@andrassy Would you mind sharing your script field for the timepicker ? I tried to set the boundaries in Vega by adding "domain":[{ %timefilter%: "min" },{ %timefilter%: "max" }] but it doesn't work.

jshvrsn commented 5 years ago

@nyurik, any idea if/when the PR for this might get merged? It would be incredibly helpful to us to be able to set the scale to match the time filter. Thx!

andrassy commented 5 years ago

@hongphuc95 there is a branch and PR containing the change -> https://github.com/elastic/kibana/pull/21145.

It's a bit stale and the CI tests were failing (and I couldn't figure out why). If anyone want to pick this up / check if it's still an issue that would be awesome!

epol commented 5 years ago

Any update on how to set the axis scale to the timefilter bound? Thanks!

passing commented 3 years ago

here's a workaround to construct a scale that uses the timepicker settings as the domain range

  data: [
    {
      name: timerangeRawData
      url: {
        index: logstash-indices // replace with an index existing in your cluster
        body: {
          size: 0,
          aggs: {
            timefilter: {
              global: {}
              meta: {
                timefilter: {
                  min: {%timefilter%: "min"}
                  max: {%timefilter%: "max"},
                }
              }
            }
          }
        }
      }
      format: {property: "aggregations.timefilter.meta.timefilter"}
    }
  ]

  "scales": [
    {
      "name": "x",
      "type": "time",
      "domain": {
        "fields": [
          {"data": "timerangeRawData", "field": "min"},
          {"data": "timerangeRawData", "field": "max"}
        ]
      },
      "range": "width"
    }
  ]

EDIT: improved based on https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191/2