Skip to content

Commit

Permalink
Merge pull request #12 from pdgago/master
Browse files Browse the repository at this point in the history
xaxis bottom tick lines optional
  • Loading branch information
pdgago committed Jan 26, 2015
2 parents 6a5ede6 + 85545ec commit c6143ae
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 28 deletions.
31 changes: 22 additions & 9 deletions charicharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,16 @@ var p_axes = PClass.extend({
.attr('transform', 'translate(0,'+(this.opts.height+1)+')')
.call(model.axis);

model.el.selectAll('text')
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
if (this.opts.xaxis.bottom.tickLines) {
model.el.selectAll('text')
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
} else {
model.el.selectAll('text')
.attr('y', 4);
model.el.selectAll('line').remove();
}

// Append baseline
model.el.append('rect')
Expand Down Expand Up @@ -572,11 +578,17 @@ var p_axes = PClass.extend({
.attr('transform', h_getTranslate(0, this.opts.yaxis.textMarginTop));
}

this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('transform', h_getTranslate(0,4))
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
if (this.opts.xaxis.bottom.tickLines) {
this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('transform', h_getTranslate(0,4))
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
} else {
this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('y', 4);
this.$svg.selectAll('.xaxis.bottom .tick line').remove();
}

// yaxis full grid
if (this.opts.yaxis.fullGrid) {
Expand Down Expand Up @@ -1917,6 +1929,7 @@ Charicharts.Chart = CClass.extend({
bottom: {
enabled: true,
label: false,
tickLines: false,
ticks: null,
// TICKS EXAMPLE
// ['days', 2]
Expand Down
2 changes: 1 addition & 1 deletion charicharts.min.js

Large diffs are not rendered by default.

31 changes: 22 additions & 9 deletions demo/charicharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,16 @@ var p_axes = PClass.extend({
.attr('transform', 'translate(0,'+(this.opts.height+1)+')')
.call(model.axis);

model.el.selectAll('text')
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
if (this.opts.xaxis.bottom.tickLines) {
model.el.selectAll('text')
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
} else {
model.el.selectAll('text')
.attr('y', 4);
model.el.selectAll('line').remove();
}

// Append baseline
model.el.append('rect')
Expand Down Expand Up @@ -572,11 +578,17 @@ var p_axes = PClass.extend({
.attr('transform', h_getTranslate(0, this.opts.yaxis.textMarginTop));
}

this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('transform', h_getTranslate(0,4))
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
if (this.opts.xaxis.bottom.tickLines) {
this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('transform', h_getTranslate(0,4))
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
} else {
this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('y', 4);
this.$svg.selectAll('.xaxis.bottom .tick line').remove();
}

// yaxis full grid
if (this.opts.yaxis.fullGrid) {
Expand Down Expand Up @@ -1917,6 +1929,7 @@ Charicharts.Chart = CClass.extend({
bottom: {
enabled: true,
label: false,
tickLines: false,
ticks: null,
// TICKS EXAMPLE
// ['days', 2]
Expand Down
1 change: 1 addition & 0 deletions demo/simple-chart-area-range.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
scale: 'time',
fit: true,
bottom: {
tickLines: true,
tickFormat: function(d) {
return d.getHours();
}
Expand Down
1 change: 1 addition & 0 deletions src/constructors/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Charicharts.Chart = CClass.extend({
bottom: {
enabled: true,
label: false,
tickLines: false,
ticks: null,
// TICKS EXAMPLE
// ['days', 2]
Expand Down
30 changes: 21 additions & 9 deletions src/parts/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,16 @@ var p_axes = PClass.extend({
.attr('transform', 'translate(0,'+(this.opts.height+1)+')')
.call(model.axis);

model.el.selectAll('text')
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
if (this.opts.xaxis.bottom.tickLines) {
model.el.selectAll('text')
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
} else {
model.el.selectAll('text')
.attr('y', 4);
model.el.selectAll('line').remove();
}

// Append baseline
model.el.append('rect')
Expand Down Expand Up @@ -268,11 +274,17 @@ var p_axes = PClass.extend({
.attr('transform', h_getTranslate(0, this.opts.yaxis.textMarginTop));
}

this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('transform', h_getTranslate(0,4))
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
if (this.opts.xaxis.bottom.tickLines) {
this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('transform', h_getTranslate(0,4))
.attr('y', 0)
.attr('x', 6)
.style('text-anchor', 'start');
} else {
this.$svg.selectAll('.xaxis.bottom .tick text')
.attr('y', 4);
this.$svg.selectAll('.xaxis.bottom .tick line').remove();
}

// yaxis full grid
if (this.opts.yaxis.fullGrid) {
Expand Down

0 comments on commit c6143ae

Please sign in to comment.