@@ -13,6 +13,7 @@ var Axes = require('@src/plots/cartesian/axes');
13
13
var Fx = require ( '@src/components/fx' ) ;
14
14
var supplyLayoutDefaults = require ( '@src/plots/cartesian/layout_defaults' ) ;
15
15
var BADNUM = require ( '@src/constants/numerical' ) . BADNUM ;
16
+ var ONEDAY = require ( '@src/constants/numerical' ) . ONEDAY ;
16
17
17
18
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
18
19
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -4011,6 +4012,208 @@ describe('Test axes', function() {
4011
4012
. then ( done ) ;
4012
4013
} ) ;
4013
4014
} ) ;
4015
+
4016
+ describe ( '*breaks*' , function ( ) {
4017
+ describe ( 'during doCalcdata' , function ( ) {
4018
+ var gd ;
4019
+
4020
+ function _calc ( trace , layout ) {
4021
+ gd = { data : [ trace ] , layout : layout } ;
4022
+ supplyDefaults ( gd ) ;
4023
+ Plots . doCalcdata ( gd ) ;
4024
+ }
4025
+
4026
+ function _assert ( msg , exp ) {
4027
+ var cd = gd . calcdata [ 0 ] ;
4028
+ var xc = cd . map ( function ( cdi ) { return cdi . x ; } ) ;
4029
+ expect ( xc ) . withContext ( msg ) . toEqual ( exp ) ;
4030
+ }
4031
+
4032
+ it ( 'should discard coords within break bounds' , function ( ) {
4033
+ _calc ( {
4034
+ x : [ 0 , 10 , 50 , 90 , 100 , 150 , 190 , 200 ]
4035
+ } , {
4036
+ xaxis : {
4037
+ breaks : [
4038
+ { 'operation' : '()' , bounds : [ 10 , 90 ] } ,
4039
+ { 'operation' : '()' , bounds : [ 100 , 190 ] }
4040
+ ]
4041
+ }
4042
+ } ) ;
4043
+ _assert ( 'with operation:()' , [ 0 , 10 , BADNUM , 90 , 100 , BADNUM , 190 , 200 ] ) ;
4044
+
4045
+ _calc ( {
4046
+ x : [ 0 , 10 , 50 , 90 , 100 , 150 , 190 , 200 ]
4047
+ } , {
4048
+ xaxis : {
4049
+ breaks : [
4050
+ { operation : '[]' , bounds : [ 10 , 90 ] } ,
4051
+ { operation : '[]' , bounds : [ 100 , 190 ] }
4052
+ ]
4053
+ }
4054
+ } ) ;
4055
+ _assert ( 'with operation:[]' , [ 0 , BADNUM , BADNUM , BADNUM , BADNUM , BADNUM , BADNUM , 200 ] ) ;
4056
+
4057
+ _calc ( {
4058
+ x : [ 0 , 10 , 50 , 90 , 100 , 150 , 190 , 200 ]
4059
+ } , {
4060
+ xaxis : {
4061
+ breaks : [
4062
+ { operation : '[)' , bounds : [ 10 , 90 ] } ,
4063
+ { operation : '(]' , bounds : [ 100 , 190 ] }
4064
+ ]
4065
+ }
4066
+ } ) ;
4067
+ _assert ( 'with mixed operation values' , [ 0 , BADNUM , BADNUM , 90 , 100 , BADNUM , BADNUM , 200 ] ) ;
4068
+ } ) ;
4069
+
4070
+ it ( 'should discard coords within break bounds - date %w case' , function ( ) {
4071
+ var x = [
4072
+ // Thursday
4073
+ '2020-01-02 08:00' , '2020-01-02 16:00' ,
4074
+ // Friday
4075
+ '2020-01-03 08:00' , '2020-01-03 16:00' ,
4076
+ // Saturday
4077
+ '2020-01-04 08:00' , '2020-01-04 16:00' ,
4078
+ // Sunday
4079
+ '2020-01-05 08:00' , '2020-01-05 16:00' ,
4080
+ // Monday
4081
+ '2020-01-06 08:00' , '2020-01-06 16:00' ,
4082
+ // Tuesday
4083
+ '2020-01-07 08:00' , '2020-01-07 16:00'
4084
+ ] ;
4085
+
4086
+ var noWeekend = [
4087
+ 1577952000000 , 1577980800000 ,
4088
+ 1578038400000 , 1578067200000 ,
4089
+ BADNUM , BADNUM ,
4090
+ BADNUM , BADNUM ,
4091
+ 1578297600000 , 1578326400000 ,
4092
+ 1578384000000 , 1578412800000
4093
+ ] ;
4094
+
4095
+ _calc ( { x : x } , {
4096
+ xaxis : {
4097
+ breaks : [
4098
+ { pattern : '%w' , bounds : [ 6 , 0 ] , operation : '[]' }
4099
+ ]
4100
+ }
4101
+ } ) ;
4102
+ _assert ( '[6,0]' , noWeekend ) ;
4103
+
4104
+ _calc ( { x : x } , {
4105
+ xaxis : {
4106
+ breaks : [
4107
+ { pattern : '%w' , bounds : [ 5 , 1 ] , operation : '()' }
4108
+ ]
4109
+ }
4110
+ } ) ;
4111
+ _assert ( '(5,1)' , noWeekend ) ;
4112
+
4113
+ _calc ( { x : x } , {
4114
+ xaxis : {
4115
+ breaks : [
4116
+ { pattern : '%w' , bounds : [ 6 , 1 ] , operation : '[)' }
4117
+ ]
4118
+ }
4119
+ } ) ;
4120
+ _assert ( '[6,1)' , noWeekend ) ;
4121
+
4122
+ _calc ( { x : x } , {
4123
+ xaxis : {
4124
+ breaks : [
4125
+ { pattern : '%w' , bounds : [ 5 , 0 ] , operation : '(]' }
4126
+ ]
4127
+ }
4128
+ } ) ;
4129
+ _assert ( '(5,0]' , noWeekend ) ;
4130
+ } ) ;
4131
+
4132
+ it ( 'should discard coords within break bounds - date %H case' , function ( ) {
4133
+ _calc ( {
4134
+ x : [
4135
+ '2020-01-02 08:00' , '2020-01-02 20:00' ,
4136
+ '2020-01-03 08:00' , '2020-01-03 20:00' ,
4137
+ '2020-01-04 08:00' , '2020-01-04 20:00' ,
4138
+ '2020-01-05 08:00' , '2020-01-05 20:00' ,
4139
+ '2020-01-06 08:00' , '2020-01-06 20:00' ,
4140
+ '2020-01-07 08:00' , '2020-01-07 20:00'
4141
+ ]
4142
+ } , {
4143
+ xaxis : {
4144
+ breaks : [
4145
+ { pattern : '%H' , bounds : [ 17 , 8 ] }
4146
+ ]
4147
+ }
4148
+ } ) ;
4149
+ _assert ( 'with dflt operation' , [
4150
+ 1577952000000 , BADNUM ,
4151
+ 1578038400000 , BADNUM ,
4152
+ 1578124800000 , BADNUM ,
4153
+ 1578211200000 , BADNUM ,
4154
+ 1578297600000 , BADNUM ,
4155
+ 1578384000000 , BADNUM
4156
+ ] ) ;
4157
+ } ) ;
4158
+
4159
+ it ( 'should discard coords within [values[i], values[i] + dvalue] bounds' , function ( ) {
4160
+ var x = [
4161
+ // Thursday
4162
+ '2020-01-02 08:00' , '2020-01-02 16:00' ,
4163
+ // Friday
4164
+ '2020-01-03 08:00' , '2020-01-03 16:00' ,
4165
+ // Saturday
4166
+ '2020-01-04 08:00' , '2020-01-04 16:00' ,
4167
+ // Sunday
4168
+ '2020-01-05 08:00' , '2020-01-05 16:00' ,
4169
+ // Monday
4170
+ '2020-01-06 08:00' , '2020-01-06 16:00' ,
4171
+ // Tuesday
4172
+ '2020-01-07 08:00' , '2020-01-07 16:00'
4173
+ ] ;
4174
+
4175
+ _calc ( { x : x } , {
4176
+ xaxis : {
4177
+ breaks : [ { values : [ '2020-01-04' , '2020-01-05' ] , dvalue : ONEDAY } ] ,
4178
+ }
4179
+ } ) ;
4180
+ _assert ( 'two values' , [
4181
+ 1577952000000 , 1577980800000 ,
4182
+ 1578038400000 , 1578067200000 ,
4183
+ BADNUM , BADNUM ,
4184
+ BADNUM , BADNUM ,
4185
+ 1578297600000 , 1578326400000 ,
4186
+ 1578384000000 , 1578412800000
4187
+ ] ) ;
4188
+ } ) ;
4189
+
4190
+ it ( 'should discard coords equal to two consecutive open values bounds' , function ( ) {
4191
+ _calc ( {
4192
+ x : [ 1 , 2 , 3 , 4 , 5 ]
4193
+ } , {
4194
+ xaxis : {
4195
+ breaks : [ { values : [ 2 , 3 ] , dvalue : 1 , operation : '()' } ]
4196
+ }
4197
+ } ) ;
4198
+ _assert ( '' , [ 1 , 2 , BADNUM , 4 , 5 ] ) ;
4199
+ } ) ;
4200
+
4201
+ it ( 'should adapt coords generated from x0/dx about breaks' , function ( ) {
4202
+ _calc ( {
4203
+ x0 : 1 ,
4204
+ dx : 0.5 ,
4205
+ y : [ 1 , 3 , 5 , 2 , 4 ]
4206
+ } , {
4207
+ xaxis : {
4208
+ breaks : [
4209
+ { bounds : [ 2 , 3 ] }
4210
+ ]
4211
+ }
4212
+ } ) ;
4213
+ _assert ( 'generated x=2.5 gets masked' , [ 1 , 1.5 , 2 , BADNUM , 3 ] ) ;
4214
+ } ) ;
4215
+ } ) ;
4216
+ } ) ;
4014
4217
} ) ;
4015
4218
4016
4219
function getZoomInButton ( gd ) {
0 commit comments