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

Fix line to vega conversion bug #4554

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Saved Objects Management] Fix relationships header overflow ([#4070](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4070))
- Update main menu to display 'Dashboards' for consistency ([#4453](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4453))
- [Multiple DataSource] Retain the original sample data API ([#4526](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4526))
- Fix line to vega conversion bug ([#4554](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4554))

### 🚞 Infrastructure

Expand Down
1 change: 1 addition & 0 deletions release-notes/opensearch-dashboards.release-notes-2.9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- Update main menu to display 'Dashboards' for consistency ([#4453](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4453))
- [Multiple DataSource] Retain the original sample data API ([#4526](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4526))
- Remove `lmdb-store` to fix backport issue ([#4266](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4266))
- Fix line to vega conversion bug ([#4554](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4554))

### 🚞 Infrastructure

Expand Down
59 changes: 32 additions & 27 deletions src/plugins/vis_type_vega/public/expressions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,35 +198,40 @@
if (datatable.rows.length > 0 && dimensions.x !== null) {
const xAxisId = getXAxisId(dimensions, datatable.columns);
const xAxisTitle = cleanString(dimensions.x.label);
let seriesParamSkipCount = 0;
datatable.columns.forEach((column, index) => {
// Don't add a layer for x axis column
if (isXAxisColumn(column)) {
seriesParamSkipCount++;
// Don't add a layer for vis layer column
} else if (!isVisLayerColumn(column)) {
const currentSeriesParams = visParams.seriesParams[index - seriesParamSkipCount];
const currentValueAxis = valueAxis.get(currentSeriesParams.valueAxis.toString());
let tooltip: Array<{ field: string; type: string; title: string }> = [];
if (visParams.addTooltip) {
tooltip = [
{ field: xAxisId, type: 'temporal', title: xAxisTitle },
{ field: column.id, type: 'quantitative', title: column.name },
];
}
spec.layer.push({
mark: buildLayerMark(currentSeriesParams),
encoding: {
x: buildXAxis(xAxisTitle, xAxisId, visParams),
y: buildYAxis(column, currentValueAxis, visParams),
tooltip,
color: {
// This ensures all the different metrics have their own distinct and unique color
datum: column.name,
},
},
});
// Ignore columns that are for the x-axis and visLayers
if (isXAxisColumn(column) || isVisLayerColumn(column)) return;
// Get the series param id which is the 2nd value in the column id
// Example: 'col-1-3', the seriesParamId is 3. 'col-1-2-6', the seriesParamId is 2.
const seriesParamsId = column.id.split('-')[2];
const currentSeriesParams = visParams.seriesParams.find(
(param: { data: { id: string } }) => param?.data?.id === seriesParamsId

Check warning on line 208 in src/plugins/vis_type_vega/public/expressions/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_type_vega/public/expressions/helpers.ts#L206-L208

Added lines #L206 - L208 were not covered by tests
);
if (!currentSeriesParams) {
// eslint-disable-next-line no-console
console.error(`Failed to find matching series param for column of id: ${column.id}`);
return;

Check warning on line 213 in src/plugins/vis_type_vega/public/expressions/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_type_vega/public/expressions/helpers.ts#L212-L213

Added lines #L212 - L213 were not covered by tests
}
const currentValueAxis = valueAxis.get(currentSeriesParams.valueAxis.toString());
let tooltip: Array<{ field: string; type: string; title: string }> = [];

Check warning on line 216 in src/plugins/vis_type_vega/public/expressions/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_type_vega/public/expressions/helpers.ts#L215-L216

Added lines #L215 - L216 were not covered by tests
if (visParams.addTooltip) {
tooltip = [

Check warning on line 218 in src/plugins/vis_type_vega/public/expressions/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_type_vega/public/expressions/helpers.ts#L218

Added line #L218 was not covered by tests
{ field: xAxisId, type: 'temporal', title: xAxisTitle },
{ field: column.id, type: 'quantitative', title: column.name },
];
}
spec.layer.push({

Check warning on line 223 in src/plugins/vis_type_vega/public/expressions/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_type_vega/public/expressions/helpers.ts#L223

Added line #L223 was not covered by tests
mark: buildLayerMark(currentSeriesParams),
encoding: {
x: buildXAxis(xAxisTitle, xAxisId, visParams),
y: buildYAxis(column, currentValueAxis, visParams),
tooltip,
color: {
// This ensures all the different metrics have their own distinct and unique color
datum: column.name,
},
},
});
});
}

Expand Down
Loading