Skip to content

Commit c87cda6

Browse files
committed
add jsamine tests for ticklabelposition defaults
1 parent fa0f3b2 commit c87cda6

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

test/jasmine/tests/axes_test.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,119 @@ describe('Test axes', function() {
573573
.toEqual(tinycolor.mix('#444', bgColor, frac).toRgbString());
574574
});
575575

576+
it('should default to a dark color for tickfont when plotting background is light', function() {
577+
layoutIn = {
578+
plot_bgcolor: 'lightblue',
579+
xaxis: {
580+
showgrid: true,
581+
ticklabelposition: 'inside'
582+
}
583+
};
584+
585+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
586+
expect(layoutOut.xaxis.tickfont.color).toEqual('#444');
587+
});
588+
589+
it('should default to a light color for tickfont when plotting background is dark', function() {
590+
layoutIn = {
591+
plot_bgcolor: 'darkblue',
592+
xaxis: {
593+
showgrid: true,
594+
ticklabelposition: 'inside'
595+
}
596+
};
597+
598+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
599+
expect(layoutOut.xaxis.tickfont.color).toEqual('#fff');
600+
});
601+
602+
it('should not coerce ticklabelposition on *multicategory* axes for now', function() {
603+
layoutIn = {
604+
xaxis: {type: 'multicategory'},
605+
yaxis: {type: 'multicategory'}
606+
};
607+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
608+
expect(layoutOut.xaxis.ticklabelposition).toBeUndefined();
609+
expect(layoutOut.yaxis.ticklabelposition).toBeUndefined();
610+
});
611+
612+
['category', 'linear', 'date'].forEach(function(type) {
613+
it('should coerce ticklabelposition on *' + type + '* axes', function() {
614+
layoutIn = {
615+
xaxis: {type: type},
616+
yaxis: {type: type}
617+
};
618+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
619+
expect(layoutOut.xaxis.ticklabelposition).toBe('outside');
620+
expect(layoutOut.yaxis.ticklabelposition).toBe('outside');
621+
});
622+
});
623+
624+
['category', 'linear', 'date'].forEach(function(type) {
625+
it('should be able to set ticklabelposition to *inside* on *' + type + '* axes', function() {
626+
layoutIn = {
627+
xaxis: {type: type, ticklabelposition: 'inside'},
628+
yaxis: {type: type, ticklabelposition: 'inside'}
629+
};
630+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
631+
expect(layoutOut.xaxis.ticklabelposition).toBe('inside');
632+
expect(layoutOut.yaxis.ticklabelposition).toBe('inside');
633+
});
634+
});
635+
636+
['inside left', 'inside right', 'outside left', 'outside right'].forEach(function(ticklabelposition) {
637+
['category', 'linear', 'date'].forEach(function(type) {
638+
it('should be able to set ticklabelposition to *' + ticklabelposition + '* on xaxis for *' + type + '* axes', function() {
639+
layoutIn = {
640+
xaxis: {type: type, ticklabelposition: ticklabelposition},
641+
yaxis: {type: type, ticklabelposition: ticklabelposition}
642+
};
643+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
644+
expect(layoutOut.xaxis.ticklabelposition).toBe(ticklabelposition);
645+
expect(layoutOut.yaxis.ticklabelposition).toBe('outside', ticklabelposition + ' is not a valid input on yaxis');
646+
});
647+
});
648+
});
649+
650+
['inside top', 'inside bottom', 'outside top', 'outside bottom'].forEach(function(ticklabelposition) {
651+
['category', 'linear', 'date'].forEach(function(type) {
652+
it('should be able to set ticklabelposition to *' + ticklabelposition + '* on yaxis for *' + type + '* axes', function() {
653+
layoutIn = {
654+
xaxis: {type: type, ticklabelposition: ticklabelposition},
655+
yaxis: {type: type, ticklabelposition: ticklabelposition}
656+
};
657+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
658+
expect(layoutOut.xaxis.ticklabelposition).toBe('outside', ticklabelposition + ' is not a valid input on yaxis');
659+
expect(layoutOut.yaxis.ticklabelposition).toBe(ticklabelposition);
660+
});
661+
});
662+
});
663+
664+
[
665+
'inside left', 'inside right', 'outside left', 'outside right',
666+
'inside top', 'inside bottom', 'outside top', 'outside bottom'
667+
].forEach(function(ticklabelposition) {
668+
it('should not be able to set ticklabelposition to *' + ticklabelposition + '* when ticklabelmode is *period*', function() {
669+
layoutIn = {
670+
xaxis: {type: 'date', ticklabelmode: 'period', ticklabelposition: ticklabelposition},
671+
yaxis: {type: 'date', ticklabelmode: 'period', ticklabelposition: ticklabelposition}
672+
};
673+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
674+
expect(layoutOut.xaxis.ticklabelposition).toBe('outside', ticklabelposition + ' is not a valid input with period mode');
675+
expect(layoutOut.yaxis.ticklabelposition).toBe('outside', ticklabelposition + ' is not a valid input with period mode');
676+
});
677+
});
678+
679+
it('should be able to set ticklabelposition to *inside* on yaxis when ticklabelmode is *period*', function() {
680+
layoutIn = {
681+
xaxis: {type: 'date', ticklabelmode: 'period', ticklabelposition: 'inside'},
682+
yaxis: {type: 'date', ticklabelmode: 'period', ticklabelposition: 'inside'}
683+
};
684+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
685+
expect(layoutOut.xaxis.ticklabelposition).toBe('inside');
686+
expect(layoutOut.yaxis.ticklabelposition).toBe('inside');
687+
});
688+
576689
it('should inherit calendar from the layout', function() {
577690
layoutOut.calendar = 'nepali';
578691
layoutIn = {

0 commit comments

Comments
 (0)