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

maintain ordinal axis sort on redraw #279

Open
wants to merge 18 commits into
base: dev-v1.11.7
Choose a base branch
from
1,660 changes: 882 additions & 778 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
Loading