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

[SIP-5] Refactor nvd3 #5838

Merged
merged 44 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
15a337d
move into folder and scaffold adaptor
kristw Sep 5, 2018
b52adec
extract width and height
kristw Sep 5, 2018
c62b075
remove jquery
kristw Sep 5, 2018
697391a
extract showBrush
kristw Sep 5, 2018
ac2c4a7
extract lineInterpolation
kristw Sep 5, 2018
d187306
extract xAxisFormat and yAxisFormat
kristw Sep 5, 2018
59b9c22
extract annotationData
kristw Sep 5, 2018
f16deeb
extract xTicksLayout and colorScheme
kristw Sep 5, 2018
f5fafb2
extract showXXX
kristw Sep 5, 2018
7d330b7
extract x and y axis labels
kristw Sep 5, 2018
672234b
extract showminmax
kristw Sep 5, 2018
5bf69e6
extract pie chart props
kristw Sep 5, 2018
b907bee
extract area chart props
kristw Sep 5, 2018
0116d00
extract logscale and yAxisBounds
kristw Sep 5, 2018
eb23184
extract margin
kristw Sep 6, 2018
e0db6b7
extract bubble props x,y,size
kristw Sep 6, 2018
ea3e6ef
extract contribution, comparisonType and color_picker
kristw Sep 6, 2018
1dafe0f
remove the last fd.xxx
kristw Sep 6, 2018
ffdb7d4
remove unnecessary variables
kristw Sep 6, 2018
472338c
remove slice.container
kristw Sep 6, 2018
4c21492
fix unit test reference
kristw Sep 6, 2018
e998d22
Rewrite logic to compute max label lengths to use only d3, not jquery.
kristw Sep 6, 2018
595f40e
extract annotationLayers and no more slice.xxx in nvd3vis
kristw Sep 6, 2018
d233223
rename x, y, size to xField, yField, sizeField
kristw Sep 6, 2018
ae2c8bd
use arrow function
kristw Sep 6, 2018
98d5a6b
move tooltip function
kristw Sep 6, 2018
3416f02
extract helper functions into utils
kristw Sep 6, 2018
34f447b
remove unused argument
kristw Sep 6, 2018
1cd2394
fix height calculation and show bar labels
kristw Sep 6, 2018
ab4c7a0
rename function
kristw Sep 6, 2018
203f229
update unit test
kristw Sep 6, 2018
fce3ca2
organize tooltip generator
kristw Sep 6, 2018
3696ccc
update line_multi
kristw Sep 6, 2018
48540f5
Add proptypes for data
kristw Sep 6, 2018
be450fe
list proptypes for data
kristw Sep 6, 2018
73ebb13
extract tooltip function for bubble chart
kristw Sep 6, 2018
b28c08e
rename variables
kristw Sep 6, 2018
dfab7e3
remove console.log
kristw Sep 6, 2018
4c45f5f
enumerate vizTypes and pieLabelType
kristw Sep 13, 2018
a085593
merge master and resolved conflicts
kristw Sep 13, 2018
ed9fb95
parse maxBubble
kristw Sep 13, 2018
22435a9
use new color scale
kristw Sep 13, 2018
cde5136
fix import"
kristw Sep 13, 2018
58214bd
remove line
kristw Sep 14, 2018
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
7 changes: 0 additions & 7 deletions superset/assets/spec/javascripts/modules/utils_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, assert } from 'chai';
import {
tryNumify,
slugify,
formatSelectOptionsForRange,
d3format,
Expand All @@ -11,12 +10,6 @@ import {
} from '../../../src/modules/utils';

describe('utils', () => {
it('tryNumify works as expected', () => {
expect(tryNumify(5)).to.equal(5);
expect(tryNumify('5')).to.equal(5);
expect(tryNumify('5.1')).to.equal(5.1);
expect(tryNumify('a string')).to.equal('a string');
});
it('slugify slugifies', () => {
expect(slugify('My Neat Label! ')).to.equal('my-neat-label');
expect(slugify('Some Letters AnD a 5')).to.equal('some-letters-and-a-5');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai';

import { formatLabel } from '../../../src/visualizations/nvd3_vis';
import { formatLabel, tryNumify } from '../../../../src/visualizations/nvd3/utils';

describe('nvd3 viz', () => {
describe('nvd3/utils', () => {
const verboseMap = {
foo: 'Foo',
bar: 'Bar',
};
describe('formatLabel', () => {
describe('formatLabel()', () => {
it('formats simple labels', () => {
expect(formatLabel('foo')).to.equal('foo');
expect(formatLabel(['foo'])).to.equal('foo');
Expand All @@ -24,4 +24,12 @@ describe('nvd3 viz', () => {
expect(formatLabel(['foo', 'bar', 'baz', '2 hours offset'], verboseMap)).to.equal('Foo, Bar, baz, 2 hours offset');
});
});
describe('tryNumify()', () => {
it('tryNumify works as expected', () => {
expect(tryNumify(5)).to.equal(5);
expect(tryNumify('5')).to.equal(5);
expect(tryNumify('5.1')).to.equal(5.1);
expect(tryNumify('a string')).to.equal('a string');
});
});
});
34 changes: 0 additions & 34 deletions superset/assets/src/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,31 +206,6 @@ export function getDatasourceParameter(datasourceId, datasourceType) {
return `${datasourceId}__${datasourceType}`;
}

export function customizeToolTip(chart, xAxisFormatter, yAxisFormatters) {
chart.useInteractiveGuideline(true);
chart.interactiveLayer.tooltip.contentGenerator(function (d) {
const tooltipTitle = xAxisFormatter(d.value);
let tooltip = '';

tooltip += "<table><thead><tr><td colspan='3'>"
+ `<strong class='x-value'>${tooltipTitle}</strong>`
+ '</td></tr></thead><tbody>';

d.series.forEach((series, i) => {
const yAxisFormatter = yAxisFormatters[i];
const value = yAxisFormatter(series.value);
tooltip += "<tr><td class='legend-color-guide'>"
+ `<div style="background-color: ${series.color};"></div></td>`
+ `<td class='key'>${series.key}</td>`
+ `<td class='value'>${value}</td></tr>`;
});

tooltip += '</tbody></table>';

return tooltip;
});
}

export function initJQueryAjax() {
// Works in conjunction with a Flask-WTF token as described here:
// http://flask-wtf.readthedocs.io/en/stable/csrf.html#javascript-requests
Expand All @@ -246,15 +221,6 @@ export function initJQueryAjax() {
}
}

export function tryNumify(s) {
// Attempts casting to Number, returns string when failing
const n = Number(s);
if (isNaN(n)) {
return s;
}
return n;
}

export function getParam(name) {
/* eslint no-useless-escape: 0 */
const formattedName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/visualizations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const loadVis = promise =>
// deckgl visualizations don't use esModules, fix it?
return defaultExport.default || defaultExport;
});
const loadNvd3 = () => loadVis(import(/* webpackChunkName: "nvd3_vis" */ './nvd3_vis.js'));
const loadNvd3 = () => loadVis(import(/* webpackChunkName: "nvd3_vis" */ './nvd3/NVD3Vis.js'));

const vizMap = {
[VIZ_TYPES.area]: loadNvd3,
Expand Down Expand Up @@ -87,7 +87,7 @@ const vizMap = {
[VIZ_TYPES.iframe]: () => loadVis(import(/* webpackChunkName: "iframe" */ './iframe.js')),
[VIZ_TYPES.line]: loadNvd3,
[VIZ_TYPES.line_multi]: () =>
loadVis(import(/* webpackChunkName: "line_multi" */ './line_multi.js')),
loadVis(import(/* webpackChunkName: "line_multi" */ './nvd3/LineMulti.js')),
[VIZ_TYPES.time_pivot]: loadNvd3,
[VIZ_TYPES.mapbox]: () => loadVis(import(/* webpackChunkName: "mapbox" */ './MapBox/MapBox.jsx')),
[VIZ_TYPES.markup]: () => loadVis(import(/* webpackChunkName: "markup" */ './markup.js')),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import d3 from 'd3';

import nvd3Vis from './nvd3_vis';
import { getExploreLongUrl } from '../explore/exploreUtils';
import nvd3Vis from './NVD3Vis';
import { getExploreLongUrl } from '../../explore/exploreUtils';

export default function lineMulti(slice, payload) {
/*
Expand Down
Loading