Skip to content

[Vega] Add ability to open links in Vega in new window#216200

Merged
andrimal merged 8 commits intoelastic:mainfrom
andrimal:feat/70745
Apr 14, 2025
Merged

[Vega] Add ability to open links in Vega in new window#216200
andrimal merged 8 commits intoelastic:mainfrom
andrimal:feat/70745

Conversation

@andrimal
Copy link
Contributor

@andrimal andrimal commented Mar 27, 2025

Summary

Fix #70745

Enables the option to open the clickable mark links of a Vega Visualization in a new tab.

To achieve this functionality:

  • use the usermeta.embedOptions.loader property in the vega chart spec to pass the "target": "_blank" configuration:
"usermeta": {
    "embedOptions": {
      "loader": {"target": "_blank"}
    }
  }

Link opens in a new tab:
Kapture 2025-03-31 at 20 44 35

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
@andrimal andrimal added Feature:Vega Vega visualizations Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// labels Mar 27, 2025
@dej611
Copy link
Contributor

dej611 commented Mar 31, 2025

Vega spec to test:

{
  $schema: https://vega.github.io/schema/vega-lite/v5.json
  data: {
    url: {
      %context%: true
      %timefield%: @timestamp
      index: kibana_sample_data_logs
      body: {
        aggs: {
          countries: {
            terms: {
              field: geo.dest
              size: 25
            }
            aggs: {
              hours: {
                histogram: {
                  field: hour_of_day
                  interval: 1
                }
                aggs: {
                  unique: {
                    cardinality: {
                      field: clientip
                    }
                  }
                }
              }
            }
          }
        }
        size: 0
      }
    }
    format: {property: "aggregations.countries.buckets"}
  }
  
  transform: [
    {
      flatten: ["hours.buckets"],
      as: ["buckets"]
    },
    {
      filter: "datum.buckets.unique.value > 0"
    },
    {
    "calculate": "'https://www.iso.org/obp/ui/#iso:code:3166:' + datum.key", "as": "url"
    }
  ]

  mark: {
    type: rect
    tooltip: {
      expr: "{\"Unique Visitors\": datum.buckets.unique.value,\"geo.src\": datum.key,\"Hour\": datum.buckets.key}"
    }
    href: {
      expr: datum.url
    }
  }


  encoding: {
    x: {
      field: buckets.key
      type: nominal
      scale: {
        domain: {
          expr: "sequence(0, 24)"
        }
      }
      axis: {
        title: false
        labelAngle: 0
      }
    }
    y: {
      field: key
      type: nominal
      sort: {
        field: -buckets.unique.value
      }
      axis: {title: false}
    }
    color: {
      field: buckets.unique.value
      type: quantitative
      axis: {title: false}
      scale: {
        scheme: blues
      }
    }
  }
  "usermeta": {
    "embedOptions": {
      "loader": {"target": "_blank"}
    }
  }
}
@andrimal andrimal added release_note:enhancement backport This PR is a backport of another PR v8.19.0 v9.1.0 backport:version Backport to applied version labels and removed backport This PR is a backport of another PR labels Mar 31, 2025
@andrimal andrimal marked this pull request as ready for review April 14, 2025 07:45
@andrimal andrimal requested a review from a team as a code owner April 14, 2025 07:45
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@andrimal
Copy link
Contributor Author

/ci

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
visTypeVega 2.0MB 2.0MB +190.0B

History

@andrimal andrimal changed the title [Vega] Pass the usermeta loader options to the vegaLoader Apr 14, 2025
@andrimal andrimal merged commit f8e688f into elastic:main Apr 14, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14448551264

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 14, 2025
## Summary

Fix elastic#70745

Enables the option to open the clickable mark links of a Vega
Visualization in a new tab.

To achieve this functionality:
- use the `usermeta.embedOptions.loader` property in the vega chart spec
to pass the `"target": "_blank"` configuration:
```javascript
"usermeta": {
    "embedOptions": {
      "loader": {"target": "_blank"}
    }
  }
```

Link opens in a new tab:
![Kapture 2025-03-31 at 20 44
35](https://github.com/user-attachments/assets/bd4f9495-28d7-4a27-89a9-dcb9fb8913dc)

### Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
(cherry picked from commit f8e688f)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 14, 2025
#218132)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Vega] Add ability to open links in Vega in new window
(#216200)](#216200)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Andreana
Malama","email":"72010092+andrimal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-14T14:42:32Z","message":"[Vega]
Add ability to open links in Vega in new window (#216200)\n\n##
Summary\n\nFix #70745 \n\nEnables the option to open the clickable mark
links of a Vega\nVisualization in a new tab.\n\nTo achieve this
functionality: \n- use the `usermeta.embedOptions.loader` property in
the vega chart spec\nto pass the `\"target\": \"_blank\"`
configuration:\n```javascript\n\"usermeta\": {\n \"embedOptions\": {\n
\"loader\": {\"target\": \"_blank\"}\n }\n }\n``` \n\nLink opens in a
new tab:\n![Kapture 2025-03-31 at 20
44\n35](https://github.com/user-attachments/assets/bd4f9495-28d7-4a27-89a9-dcb9fb8913dc)\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] The PR
description includes the appropriate Release Notes section,\nand the
correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by:
Marco Liberati
<dej611@users.noreply.github.com>","sha":"f8e688f88135bf7675cfd0c6dfb918e23b6ebbb8","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Feature:Vega","Team:Visualizations","backport:version","v9.1.0","v8.19.0"],"title":"[Vega]
Add ability to open links in Vega in new
window","number":216200,"url":"https://github.com/elastic/kibana/pull/216200","mergeCommit":{"message":"[Vega]
Add ability to open links in Vega in new window (#216200)\n\n##
Summary\n\nFix #70745 \n\nEnables the option to open the clickable mark
links of a Vega\nVisualization in a new tab.\n\nTo achieve this
functionality: \n- use the `usermeta.embedOptions.loader` property in
the vega chart spec\nto pass the `\"target\": \"_blank\"`
configuration:\n```javascript\n\"usermeta\": {\n \"embedOptions\": {\n
\"loader\": {\"target\": \"_blank\"}\n }\n }\n``` \n\nLink opens in a
new tab:\n![Kapture 2025-03-31 at 20
44\n35](https://github.com/user-attachments/assets/bd4f9495-28d7-4a27-89a9-dcb9fb8913dc)\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] The PR
description includes the appropriate Release Notes section,\nand the
correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by:
Marco Liberati
<dej611@users.noreply.github.com>","sha":"f8e688f88135bf7675cfd0c6dfb918e23b6ebbb8"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216200","number":216200,"mergeCommit":{"message":"[Vega]
Add ability to open links in Vega in new window (#216200)\n\n##
Summary\n\nFix #70745 \n\nEnables the option to open the clickable mark
links of a Vega\nVisualization in a new tab.\n\nTo achieve this
functionality: \n- use the `usermeta.embedOptions.loader` property in
the vega chart spec\nto pass the `\"target\": \"_blank\"`
configuration:\n```javascript\n\"usermeta\": {\n \"embedOptions\": {\n
\"loader\": {\"target\": \"_blank\"}\n }\n }\n``` \n\nLink opens in a
new tab:\n![Kapture 2025-03-31 at 20
44\n35](https://github.com/user-attachments/assets/bd4f9495-28d7-4a27-89a9-dcb9fb8913dc)\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers
should verify this PR satisfies this list as well.\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] The PR
description includes the appropriate Release Notes section,\nand the
correct `release_note:*` label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by:
Marco Liberati
<dej611@users.noreply.github.com>","sha":"f8e688f88135bf7675cfd0c6dfb918e23b6ebbb8"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Andreana Malama <72010092+andrimal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:Vega Vega visualizations release_note:enhancement Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v8.19.0 v9.1.0

4 participants