1+ var Plotly = require ( '@lib/index' ) ;
12var Plots = require ( '@src/plots/plots' ) ;
23var Lib = require ( '@src/lib' ) ;
34
@@ -6,6 +7,8 @@ var Axes = PlotlyInternal.Axes;
67
78var Bar = require ( '@src/traces/bar' ) ;
89
10+ var createGraphDiv = require ( '../assets/create_graph_div' ) ;
11+ var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
912var customMatchers = require ( '../assets/custom_matchers' ) ;
1013
1114describe ( 'bar supplyDefaults' , function ( ) {
@@ -600,6 +603,80 @@ describe('Bar.setPositions', function() {
600603 } ) ;
601604} ) ;
602605
606+ describe ( 'A bar plot' , function ( ) {
607+ 'use strict' ;
608+
609+ beforeAll ( function ( ) {
610+ jasmine . addMatchers ( customMatchers ) ;
611+ } ) ;
612+
613+ afterEach ( destroyGraphDiv ) ;
614+
615+ it ( 'should be able to restyle' , function ( done ) {
616+ var gd = createGraphDiv ( ) ,
617+ mock = Lib . extendDeep ( { } , require ( '@mocks/bar_attrs_relative' ) ) ;
618+
619+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( function ( ) {
620+ var cd = gd . calcdata ;
621+ assertPointField ( cd , 'x' , [
622+ [ 1 , 2 , 3 , 4 ] , [ 1 , 2 , 3 , 4 ] ,
623+ [ 1 , 2 , 3 , 4 ] , [ 1 , 2 , 3 , 4 ] ] ) ;
624+ assertPointField ( cd , 'y' , [
625+ [ 1 , 2 , 3 , 4 ] , [ 4 , 4 , 4 , 4 ] ,
626+ [ - 1 , - 3 , - 2 , - 4 ] , [ 4 , - 4 , - 5 , - 6 ] ] ) ;
627+ assertPointField ( cd , 'b' , [
628+ [ 0 , 0 , 0 , 0 ] , [ 1 , 2 , 3 , 4 ] ,
629+ [ 0 , 0 , 0 , 0 ] , [ 4 , - 3 , - 2 , - 4 ] ] ) ;
630+ assertPointField ( cd , 's' , [
631+ [ 1 , 2 , 3 , 4 ] , [ 3 , 2 , 1 , 0 ] ,
632+ [ - 1 , - 3 , - 2 , - 4 ] , [ 0 , - 1 , - 3 , - 2 ] ] ) ;
633+ assertPointField ( cd , 'p' , [
634+ [ 1 , 2 , 3 , 4 ] , [ 1 , 2 , 3 , 4 ] ,
635+ [ 1 , 2 , 3 , 4 ] , [ 1 , 2 , 3 , 4 ] ] ) ;
636+ assertArrayField ( cd [ 0 ] [ 0 ] , 't.barwidth' , [ 1 , 0.8 , 0.6 , 0.4 ] ) ;
637+ assertArrayField ( cd [ 1 ] [ 0 ] , 't.barwidth' , [ 0.4 , 0.6 , 0.8 , 1 ] ) ;
638+ expect ( cd [ 2 ] [ 0 ] . t . barwidth ) . toBe ( 1 ) ;
639+ expect ( cd [ 3 ] [ 0 ] . t . barwidth ) . toBe ( 0.8 ) ;
640+ assertArrayField ( cd [ 0 ] [ 0 ] , 't.poffset' , [ - 0.5 , - 0.4 , - 0.3 , - 0.2 ] ) ;
641+ assertArrayField ( cd [ 1 ] [ 0 ] , 't.poffset' , [ - 0.2 , - 0.3 , - 0.4 , - 0.5 ] ) ;
642+ expect ( cd [ 2 ] [ 0 ] . t . poffset ) . toBe ( - 0.5 ) ;
643+ expect ( cd [ 3 ] [ 0 ] . t . poffset ) . toBe ( - 0.4 ) ;
644+ assertTraceField ( cd , 't.bargroupwidth' , [ 0.8 , 0.8 , 0.8 , 0.8 ] ) ;
645+
646+ return Plotly . restyle ( gd , 'offset' , 0 ) ;
647+ } ) . then ( function ( ) {
648+ var cd = gd . calcdata ;
649+ assertPointField ( cd , 'x' , [
650+ [ 1.5 , 2.4 , 3.3 , 4.2 ] , [ 1.2 , 2.3 , 3.4 , 4.5 ] ,
651+ [ 1.5 , 2.5 , 3.5 , 4.5 ] , [ 1.4 , 2.4 , 3.4 , 4.4 ] ] ) ;
652+ assertPointField ( cd , 'y' , [
653+ [ 1 , 2 , 3 , 4 ] , [ 4 , 4 , 4 , 4 ] ,
654+ [ - 1 , - 3 , - 2 , - 4 ] , [ 4 , - 4 , - 5 , - 6 ] ] ) ;
655+ assertPointField ( cd , 'b' , [
656+ [ 0 , 0 , 0 , 0 ] , [ 1 , 2 , 3 , 4 ] ,
657+ [ 0 , 0 , 0 , 0 ] , [ 4 , - 3 , - 2 , - 4 ] ] ) ;
658+ assertPointField ( cd , 's' , [
659+ [ 1 , 2 , 3 , 4 ] , [ 3 , 2 , 1 , 0 ] ,
660+ [ - 1 , - 3 , - 2 , - 4 ] , [ 0 , - 1 , - 3 , - 2 ] ] ) ;
661+ assertPointField ( cd , 'p' , [
662+ [ 1 , 2 , 3 , 4 ] , [ 1 , 2 , 3 , 4 ] ,
663+ [ 1 , 2 , 3 , 4 ] , [ 1 , 2 , 3 , 4 ] ] ) ;
664+ assertArrayField ( cd [ 0 ] [ 0 ] , 't.barwidth' , [ 1 , 0.8 , 0.6 , 0.4 ] ) ;
665+ assertArrayField ( cd [ 1 ] [ 0 ] , 't.barwidth' , [ 0.4 , 0.6 , 0.8 , 1 ] ) ;
666+ expect ( cd [ 2 ] [ 0 ] . t . barwidth ) . toBe ( 1 ) ;
667+ expect ( cd [ 3 ] [ 0 ] . t . barwidth ) . toBe ( 0.8 ) ;
668+ expect ( cd [ 0 ] [ 0 ] . t . poffset ) . toBe ( 0 ) ;
669+ expect ( cd [ 1 ] [ 0 ] . t . poffset ) . toBe ( 0 ) ;
670+ expect ( cd [ 2 ] [ 0 ] . t . poffset ) . toBe ( 0 ) ;
671+ expect ( cd [ 3 ] [ 0 ] . t . poffset ) . toBe ( 0 ) ;
672+ assertTraceField ( cd , 't.bargroupwidth' , [ 0.8 , 0.8 , 0.8 , 0.8 ] ) ;
673+
674+ done ( ) ;
675+ } ) ;
676+ } ) ;
677+ } ) ;
678+
679+
603680function mockBarPlot ( dataWithoutTraceType , layout ) {
604681 var traceTemplate = { type : 'bar' } ;
605682
0 commit comments