Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VisBuilder] Add Capability to generate dynamic vega #7288

Merged
merged 9 commits into from
Jul 23, 2024

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Jul 17, 2024

Description

In this PR, we add the capability for Visbuilder to generate dynamic Vega and Vega-Lite specifications based on user settings and aggregation configurations. Some hightlighs:

  • developed functions buildVegaSpecViaVega and buildVegaSpecViaVegaLite that can create either Vega or Vega-Lite specifications depending on the complexity of the visualization.
  • added VegaSpec and VegaLiteSpec interfaces to provide better type checking
  • broken down the specification building into smaller, reusable components (like buildEncoding, buildMark, buildLegend, buildTooltip) to make the code more maintainable and easier to extend.
  • added flattenDataHandler to prepare and transform data for use in Vega visualizations

Note: In this current implementation, we directly utilize the existing visualization and style configurations from Visbuilder. This approach maintains consistency with the current feature set and minimizes changes in this pull request. For future enhancements, we plan to introduce dedicated Vega-specific properties within both the visualization and style slices. This will allow us to accommodate new Vega-related settings and provide more granular control over Vega visualizations without affecting the existing Visbuilder functionality.

Issues Resolved (Partially)

#7067

Screenshot

2024-07-17_10-27-24.mp4

Testing the changes

Changelog

  • feat: [VisBuilder] Add Capability to generate dynamic vega

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 77.10280% with 49 lines in your changes missing coverage. Please review.

Project coverage is 67.69%. Comparing base (6551af7) to head (9249067).
Report is 2 commits behind head on main.

Files Patch % Lines
...lder/public/visualizations/vega/components/mark.ts 72.72% 5 Missing and 4 partials ⚠️
...public/visualizations/common/expression_helpers.ts 0.00% 8 Missing ⚠️
...uilder/public/visualizations/vega/utils/helpers.ts 77.77% 3 Missing and 5 partials ⚠️
...er/public/visualizations/vega/vega_spec_factory.ts 16.66% 5 Missing ⚠️
...r/public/visualizations/vega/components/tooltip.ts 69.23% 1 Missing and 3 partials ⚠️
...blic/visualizations/vega/vega_lite_spec_builder.ts 71.42% 1 Missing and 3 partials ⚠️
...uilder/public/application/components/workspace.tsx 0.00% 2 Missing ⚠️
...ilder/public/embeddable/vis_builder_embeddable.tsx 0.00% 2 Missing ⚠️
.../public/visualizations/vega/components/encoding.ts 85.71% 0 Missing and 2 partials ⚠️
...er/public/visualizations/vega/vega_spec_builder.ts 86.66% 1 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7288      +/-   ##
==========================================
+ Coverage   67.62%   67.69%   +0.07%     
==========================================
  Files        3584     3595      +11     
  Lines       72205    72404     +199     
  Branches    11818    11867      +49     
==========================================
+ Hits        48826    49014     +188     
+ Misses      20391    20385       -6     
- Partials     2988     3005      +17     
Flag Coverage Δ
Linux_1 33.40% <77.10%> (+0.24%) ⬆️
Linux_2 55.53% <ø> (ø)
Linux_3 44.48% <ø> (?)
Linux_4 34.05% <ø> (?)
Windows_1 33.42% <77.10%> (+0.24%) ⬆️
Windows_2 55.48% <ø> (ø)
Windows_3 44.50% <ø> (ø)
Windows_4 34.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

* update file and functions names
* fix type errors
* fix area chart

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
* @param {any} formats - The formatting information for axes.
* @returns {VegaScale[]} The Vega scale configurations.
*/
export const buildVegaScales = (dimensions: any, formats: any): VegaScale[] => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function doesn't seem to be using formats parameter. This parameter can be cleaned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update. thx.

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
* @returns {string} The corresponding Vega data type
*/
export const mapFieldTypeToVegaType = (fieldType) => {
const typeMap = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can use an enum to define the typeMap and add it to the constants file

opensearch-changeset-bot bot added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Jul 22, 2024

// Build the base Vega-Lite specification
const baseSpec: VegaLiteSpec = {
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can store it as a constant so it would be easier to modify it in future if required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will polish in a follow up PR.

$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
data: { values: transformedData },
mark: buildMarkForVegaLite(vegaType),
encoding: buildVegaLiteEncoding(dimensions, formats),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We are calling buildVegaLiteEncoding(dimensions, formats) three times separately in the function , we can store the value in first call and use it across places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will polish in a follow up PR.

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
opensearch-changeset-bot bot added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Jul 22, 2024
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
LDrago27
LDrago27 previously approved these changes Jul 22, 2024
@ashwin-pc ashwin-pc merged commit faaa45c into opensearch-project:main Jul 23, 2024
68 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 23, 2024
* [VisBuilder] Add Capability to generate dynamic vega

In this PR, we add the capability for Visbuilder to generate dynamic Vega and Vega-Lite
specifications based on user settings and aggregation configurations.

* developed functions buildVegaSpecViaVega and buildVegaSpecViaVegaLite
that can create either Vega or Vega-Lite specifications depending on the complexity
of the visualization.
* added VegaSpec and VegaLiteSpec interfaces to provide better type checking
* broken down the specification building into smaller, reusable components
(like buildEncoding, buildMark, buildLegend, buildTooltip) to make the code
more maintainable and easier to extend.
* added flattenDataHandler to prepare and transform data for use in Vega visualizations

Issue Resolve
#7067

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* fix PR comments

* update file and functions names
* fix type errors
* fix area chart

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* add unit tests

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* enable embeddable for useVega

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* remove buildVegaScales due to split it to smaller modules

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* fix date for vega

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* fix test

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* Changeset file for PR #7288 created/updated

---------

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit faaa45c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 23, 2024
* [VisBuilder] Add Capability to generate dynamic vega

In this PR, we add the capability for Visbuilder to generate dynamic Vega and Vega-Lite
specifications based on user settings and aggregation configurations.

* developed functions buildVegaSpecViaVega and buildVegaSpecViaVegaLite
that can create either Vega or Vega-Lite specifications depending on the complexity
of the visualization.
* added VegaSpec and VegaLiteSpec interfaces to provide better type checking
* broken down the specification building into smaller, reusable components
(like buildEncoding, buildMark, buildLegend, buildTooltip) to make the code
more maintainable and easier to extend.
* added flattenDataHandler to prepare and transform data for use in Vega visualizations

Issue Resolve
#7067

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* fix PR comments

* update file and functions names
* fix type errors
* fix area chart

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* add unit tests

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* enable embeddable for useVega

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* remove buildVegaScales due to split it to smaller modules

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* fix date for vega

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* fix test

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* Changeset file for PR #7288 created/updated

---------

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit faaa45c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ananzh pushed a commit that referenced this pull request Jul 23, 2024
* [VisBuilder] Add Capability to generate dynamic vega

In this PR, we add the capability for Visbuilder to generate dynamic Vega and Vega-Lite
specifications based on user settings and aggregation configurations.

* developed functions buildVegaSpecViaVega and buildVegaSpecViaVegaLite
that can create either Vega or Vega-Lite specifications depending on the complexity
of the visualization.
* added VegaSpec and VegaLiteSpec interfaces to provide better type checking
* broken down the specification building into smaller, reusable components
(like buildEncoding, buildMark, buildLegend, buildTooltip) to make the code
more maintainable and easier to extend.
* added flattenDataHandler to prepare and transform data for use in Vega visualizations

Issue Resolve
#7067


---------



(cherry picked from commit faaa45c)

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
ananzh pushed a commit that referenced this pull request Jul 23, 2024
* [VisBuilder] Add Capability to generate dynamic vega

In this PR, we add the capability for Visbuilder to generate dynamic Vega and Vega-Lite
specifications based on user settings and aggregation configurations.

* developed functions buildVegaSpecViaVega and buildVegaSpecViaVegaLite
that can create either Vega or Vega-Lite specifications depending on the complexity
of the visualization.
* added VegaSpec and VegaLiteSpec interfaces to provide better type checking
* broken down the specification building into smaller, reusable components
(like buildEncoding, buildMark, buildLegend, buildTooltip) to make the code
more maintainable and easier to extend.
* added flattenDataHandler to prepare and transform data for use in Vega visualizations

Issue Resolve
#7067


---------



(cherry picked from commit faaa45c)

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants