Skip to content

Commit

Permalink
Fixing sort issue with area chart and adding tests (#6358)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellethomas authored Jan 25, 2019
1 parent 6b0ab21 commit 8100a8f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import readResponseBlob from '../../../utils/readResponseBlob';

export default () => describe('Area', () => {
const AREA_FORM_DATA = {
datasource: '2__table',
Expand Down Expand Up @@ -71,11 +73,12 @@ export default () => describe('Area', () => {
...AREA_FORM_DATA,
groupby: ['region'],
});

cy.get('.nv-area').should('have.length', 7);
});

it('should work with groupby and filter', () => {
verify({
cy.visitChartByParams(JSON.stringify({
...AREA_FORM_DATA,
groupby: ['region'],
adhoc_filters: [{
Expand All @@ -88,6 +91,18 @@ export default () => describe('Area', () => {
fromFormData: true,
filterOptionName: 'filter_txje2ikiv6_wxmn0qwd1xo',
}],
}));

cy.wait('@getJson').then(async (xhr) => {
cy.verifyResponseCodes(xhr);

const responseBody = await readResponseBlob(xhr.response.body);

// Make sure data is sorted correctly
const firstRow = responseBody.data[0].values;
const secondRow = responseBody.data[1].values;
expect(firstRow[firstRow.length - 1].y).to.be.greaterThan(secondRow[secondRow.length - 1].y);
cy.verifySliceContainer('svg');
});
cy.get('.nv-area').should('have.length', 2);
});
Expand Down
30 changes: 30 additions & 0 deletions superset/assets/cypress/integration/explore/visualizations/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,40 @@ export default () => describe('Line', () => {
metrics,
time_compare: ['1+year'],
comparison_type: 'values',
groupby: ['gender'],
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });

// Offset color should match original line color
cy.get('.nv-legend-text')
.contains('boy')
.siblings()
.first()
.should('have.attr', 'style')
.then((style) => {
cy.get('.nv-legend-text')
.contains('boy, 1 year offset')
.siblings()
.first()
.should('have.attr', 'style')
.and('eq', style);
});

cy.get('.nv-legend-text')
.contains('girl')
.siblings()
.first()
.should('have.attr', 'style')
.then((style) => {
cy.get('.nv-legend-text')
.contains('girl, 1 year offset')
.siblings()
.first()
.should('have.attr', 'style')
.and('eq', style);
});
});

it('Test line chart with time shift yoy', () => {
Expand Down
4 changes: 3 additions & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,9 @@ def get_data(self, df):
self.to_series(
diff, classed='time-shift-{}'.format(i), title_suffix=label))

return sorted(chart_data, key=lambda x: tuple(x['key']))
if not self.sort_series:
chart_data = sorted(chart_data, key=lambda x: tuple(x['key']))
return chart_data


class MultiLineViz(NVD3Viz):
Expand Down

0 comments on commit 8100a8f

Please sign in to comment.