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 unit tests #275

Open
wants to merge 14 commits into
base: dev-v1.11.7
Choose a base branch
from
1,574 changes: 843 additions & 731 deletions build/webcharts.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/webcharts.min.js

Large diffs are not rendered by default.

152 changes: 102 additions & 50 deletions css/webcharts.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/*------------------------------------------------------------------------------------------------\
Small Multiple Layout
\------------------------------------------------------------------------------------------------*/

div.wc-layout.wc-small-multiples::after {
content: "";
clear: both;
display: block;
}

.wc-layout.wc-small-multiples > .wc-chart {
float: left;
padding: 0 2em 2em 0;
}

.wc-layout.wc-small-multiples > .wc-chart > .wc-chart-title {
display: block;
font-weight: bold;
text-align: center;
}
.wc-small-multiples .wc-chart > .legend {
display: none;
}

/*------------------------------------------------------------------------------------------------\
Charts
\------------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -70,42 +46,118 @@
fill: #555;
}

*[class*="wc-"] .legend {
width: 100%;
font-size: .9em;
padding: 0;
margin: 0;
display: inline-block;
.wc-chart .ordinal.axis .tick line,
.wc-chart .ordinal.axis path {
display: none;
}

*[class*="wc-"] .legend .legend-title {
font-weight: bold;
margin-right: 1em;
.wc-chart.gridlines .ordinal.axis .tick line {
display: block;
}

*[class*="wc-"] .legend .legend-item {
display: inline-block;
margin-right: 1em;
}
/**-------------------------------------------------------------------------------------------\
Legend
\-------------------------------------------------------------------------------------------**/

*[class*="wc-"] .legend .legend-item .legend-color-block {
position: relative;
top: .2em;
right: .25em;
display: inline-block;
}
*[class*="wc-"] .legend .legend-item .legend-mark-text {
font-weight: bold;
margin-right: .5em;
*[class*="wc-"] .legend {
width: 100%;
font-size: .9em;
padding: 0;
margin: 0;
display: inline-block;
}

*[class*="wc-"] .legend--left,
*[class*="wc-"] .legend--right {
display: block;
}

*[class*="wc-"] .legend--left {
float: left;
}

*[class*="wc-"] .legend--left > * {
float: left;
clear: left;
}

*[class*="wc-"] .legend--right {
float: right;
}

*[class*="wc-"] .legend--right > * {
float: right;
clear: right;
}

*[class*="wc-"] .legend--empty {
display: none;
}

*[class*="wc-"] .legend .legend-title {
display: inline;
font-weight: bold;
margin-right: 1em;
vertical-align: top;
}

*[class*="wc-"] .legend .legend-title:empty {
display: none;
}

*[class*="wc-"] .legend .legend-item {
display: inline-block;
list-style-type: none;
margin-right: 1em;
}

*[class*="wc-"] .legend .legend-item .legend-color-block {
position: relative;
top: .2em;
right: .25em;
display: inline-block;
}

*[class*="wc-"] .legend--right .legend-item .legend-color-block {
float: right;
left: .25em;
}

*[class*="wc-"] .legend .legend-item .legend-mark-text {
font-weight: bold;
margin-right: .5em;
}

*[class*="wc-"] .legend .legend-item .legend-label {
margin-left: 0.25em;
}

*[class*="wc-"] .legend--right .legend-item .legend-label {
margin-right: 0.25em;
}

/*------------------------------------------------------------------------------------------------\
Small multiples
\------------------------------------------------------------------------------------------------*/

div.wc-layout.wc-small-multiples::after {
content: "";
clear: both;
display: block;
}

.wc-chart .ordinal.axis .tick line,
.wc-chart .ordinal.axis path {
display: none;
.wc-layout.wc-small-multiples > .wc-chart {
float: left;
padding: 0 2em 2em 0;
}

.wc-chart.gridlines .ordinal.axis .tick line {
.wc-layout.wc-small-multiples > .wc-chart > .wc-chart-title {
display: block;
font-weight: bold;
text-align: center;
}
.wc-small-multiples .wc-chart > .legend {
display: none;
}

/*------------------------------------------------------------------------------------------------\
Expand Down
2 changes: 1 addition & 1 deletion css/webcharts.min.css

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test-controls": "mocha --timeout 5000 --require @babel/register --recursive ./test/controls/*.js",
"test-miscellaneous": "mocha --timeout 5000 --require @babel/register --recursive ./test/miscellaneous/*.js",
"test-multiply": "mocha --timeout 5000 --require @babel/register --recursive ./test/multiply/*.js",
"test-new": "mocha --require @babel/register ./test/testNewUnitTests.js",
"test-new": "mocha --require @babel/register ./test/testNew.js",
"test-page": "start chrome ./test-page/createChart/index.html && start chrome ./test-page/createTable/index.html && start chrome ./test-page/multiply/index.html",
"test-table": "mocha --timeout 5000 --require @babel/register --recursive ./test/table/*.js",
"watch": "rollup -c -w"
Expand Down
2 changes: 1 addition & 1 deletion src/chart/draw/consolidateData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function consolidateData(raw) {
? d
: filter.val instanceof Array
? filter.val.indexOf(d[filter.col]) > -1
: d[filter.col] === filter.val;
: d[filter.col] + '' === filter.val + '';
});
});
}
Expand Down
42 changes: 29 additions & 13 deletions src/chart/draw/consolidateData/setDefaults.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
export default function setDefaults() {
// x
this.config.x = this.config.x || {};
this.config.y = this.config.y || {};

this.config.x.label =
this.config.x.label !== undefined ? this.config.x.label : this.config.x.column;
this.config.x.sort = this.config.x.sort || 'alphabetical-ascending';
this.config.x.type = this.config.x.type || 'linear';
this.config.x.range_band = this.config.x.range_band || this.config.range_band;

// y
this.config.y = this.config.y || {};
this.config.y.label =
this.config.y.label !== undefined ? this.config.y.label : this.config.y.column;

this.config.x.sort = this.config.x.sort || 'alphabetical-ascending';
this.config.y.sort = this.config.y.sort || 'alphabetical-descending';

this.config.x.type = this.config.x.type || 'linear';
this.config.y.type = this.config.y.type || 'linear';

this.config.x.range_band = this.config.x.range_band || this.config.range_band;
this.config.y.range_band = this.config.y.range_band || this.config.range_band;

this.config.margin = this.config.margin || {};
// marks
this.config.marks = this.config.marks && this.config.marks.length ? this.config.marks : [{}];
this.config.marks.forEach(function(m, i) {
m.id = m.id ? m.id : 'mark' + (i + 1);
m.checkColumns = m.checkColumns !== false ? true : false;
});

//legend
this.config.legend = this.config.legend || {};
this.config.legend.label =
this.config.legend.label !== undefined ? this.config.legend.label : this.config.color_by;
this.config.legend.location =
this.config.legend.location !== undefined ? this.config.legend.location : 'bottom';
this.config.marks = this.config.marks && this.config.marks.length ? this.config.marks : [{}];
this.config.marks.forEach(function(m, i) {
m.id = m.id ? m.id : 'mark' + (i + 1);
});
this.config.legend.mark =
this.config.legend.mark !== undefined &&
typeof this.config.legend.mark === 'string' &&
['bar', 'square', 'circle', 'line'].includes(this.config.legend.mark.toLowerCase())
? this.config.legend.mark.toLowerCase().replace('bar', 'square')
: this.config.marks[0].type !== undefined &&
typeof this.config.marks[0].type === 'string' &&
['bar', 'circle', 'line'].includes(this.config.marks[0].type.toLowerCase())
? this.config.marks[0].type.toLowerCase().replace('bar', 'square')
: 'square';

// dimensions
this.config.margin = this.config.margin || {};

// miscellaneous
this.config.date_format = this.config.date_format || '%x';

this.config.padding = this.config.padding !== undefined ? this.config.padding : 0.3;
Expand Down
2 changes: 1 addition & 1 deletion src/chart/draw/consolidateData/transformData.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function transformData(raw, mark) {
? d
: e.val instanceof Array
? e.val.indexOf(d[e.col]) > -1
: d[e.col] === e.val;
: d[e.col] + '' === e.val.toString() + '';
});
});
//get domain for all non-All values of first filter
Expand Down
30 changes: 18 additions & 12 deletions src/chart/draw/consolidateData/transformData/makeNest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@ export default function makeNest(mark, entries, sublevel) {
if (sublevel) {
this_nest.key(d => d[sublevel]);
this_nest.sortKeys((a, b) => {
return this.config.x.type === 'time'
? ascending(new Date(a), new Date(b))
: this.config.x.order
? ascending(this.config.x.order.indexOf(a), this.config.x.order.indexOf(b))
: sublevel === this.config.color_by && this.config.legend.order
? ascending(
this.config.legend.order.indexOf(a),
this.config.legend.order.indexOf(b)
)
: this.config.x.type === 'ordinal' || this.config.y.type === 'ordinal'
? naturalSorter(a, b)
: ascending(+a, +b);
let sort;

if (this.config.x.type === 'time') {
sort = ascending(new Date(a), new Date(b));
} else if (this.config.x.order) {
sort = ascending(this.config.x.order.indexOf(a), this.config.x.order.indexOf(b));
} else if (sublevel === this.config.color_by && this.config.legend.order) {
sort = ascending(
this.config.legend.order.indexOf(a),
this.config.legend.order.indexOf(b)
);
} else if (this.config.x.type === 'ordinal' || this.config.y.type === 'ordinal') {
sort = naturalSorter(a, b);
} else {
sort = ascending(+a, +b);
}

return sort;
});
}
this_nest.rollup(r => {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/draw/setColorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function setColorScale() {
? config.color_dom.slice()
: set(data.map(m => m[config.color_by]))
.values()
.filter(f => f && f !== 'undefined');
.filter(f => f !== 'undefined');

if (config.legend.order)
colordom.sort((a, b) =>
Expand Down
4 changes: 2 additions & 2 deletions src/chart/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function init(data, test = false) {
this.initial_data = data;

let startup = data => {
//connect this chart and its controls, if any
// connect this chart and its controls, if any
if (this.controls) {
this.controls.targets.push(this);
if (!this.controls.ready) {
Expand All @@ -36,7 +36,7 @@ export default function init(data, test = false) {
}
}

//make sure container is visible (has height and width) before trying to initialize
// make sure container is visible (has height and width) before trying to initialize
var visible = select(this.div).property('offsetWidth') > 0 || test;
if (!visible) {
console.warn(
Expand Down
2 changes: 1 addition & 1 deletion src/chart/init/checkRequired.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function checkRequired(data) {
requiredVars.push('this.config.marks[' + i + '].split');
requiredCols.push(e.split);
}
if (e.values) {
if (e.values && e.checkColumns) {
for (const value in e.values) {
requiredVars.push('this.config.marks[' + i + "].values['" + value + "']");
requiredCols.push(value);
Expand Down
11 changes: 5 additions & 6 deletions src/chart/layout/addLegend.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export default function addLegend() {
//The legend is contained in the parent object of multiples so each multiple does not need its own legend.
if (!this.parent)
this.wrap
if (!this.parent) {
const legend = this.wrap
.append('ul')
.datum(() => null) // prevent data inheritance
.attr('class', 'legend')
.style('vertical-align', 'top')
.append('span')
.attr('class', 'legend-title');
.classed('legend', true);
const legend_title = legend.append('span').classed('legend-title', true);
}
}
Loading