99 * OF ANY KIND, either express or implied. See the License for the specific language
1010 * governing permissions and limitations under the License.
1111 */
12- import { FILTERED_TABLE } from '@spectrum-charts/constants' ;
12+ import { ANNOTATION_PADDING , FILTERED_TABLE } from '@spectrum-charts/constants' ;
1313
1414import {
1515 getAnnotationMarks ,
@@ -41,32 +41,32 @@ describe('getAnnotationMarks()', () => {
4141
4242describe ( 'getMinBandwidth()' , ( ) => {
4343 test ( 'should be 48 if bar is vertical' , ( ) => {
44- expect ( getMinBandwidth ( 'vertical' ) ) . toEqual ( 48 ) ;
44+ expect ( getMinBandwidth ( 'vertical' , ANNOTATION_PADDING ) ) . toEqual ( 48 ) ;
4545 } ) ;
4646 test ( 'should be fontsize + 2*padding if bar is horizontal' , ( ) => {
47- expect ( getMinBandwidth ( 'horizontal' ) ) . toEqual ( 20 ) ;
47+ expect ( getMinBandwidth ( 'horizontal' , ANNOTATION_PADDING ) ) . toEqual ( 20 ) ;
4848 } ) ;
4949} ) ;
5050
5151describe ( 'getAnnotationXEncode()' , ( ) => {
5252 test ( 'should use xc and width if width is defined' , ( ) => {
53- const xEncode = getAnnotationXEncode ( 100 ) ;
53+ const xEncode = getAnnotationXEncode ( ANNOTATION_PADDING , 100 ) ;
5454 expect ( xEncode ) . toHaveProperty ( 'xc' ) ;
5555 expect ( xEncode ) . toHaveProperty ( 'width' ) ;
5656 } ) ;
5757 test ( 'should use x and x2 if width is not defined' , ( ) => {
58- const xEncode = getAnnotationXEncode ( ) ;
58+ const xEncode = getAnnotationXEncode ( ANNOTATION_PADDING ) ;
5959 expect ( xEncode ) . toHaveProperty ( 'x' ) ;
6060 expect ( xEncode ) . toHaveProperty ( 'x2' ) ;
6161 } ) ;
6262} ) ;
6363
6464describe ( 'getAnnotationWidth()' , ( ) => {
6565 test ( 'should return hardcoded signal if width is defined' , ( ) => {
66- expect ( getAnnotationWidth ( 'textLabel' , { width : 100 } ) ) . toEqual ( { value : 100 } ) ;
66+ expect ( getAnnotationWidth ( 'textLabel' , ANNOTATION_PADDING , { width : 100 } ) ) . toEqual ( { value : 100 } ) ;
6767 } ) ;
6868 test ( 'should return signal that gets the label width if width is not defined' , ( ) => {
69- const width = getAnnotationWidth ( 'textLabel' ) ;
69+ const width = getAnnotationWidth ( 'textLabel' , ANNOTATION_PADDING ) ;
7070 expect ( width ) . toHaveProperty ( 'signal' ) ;
7171
7272 expect ( ( width as { signal : string } ) . signal ) . toContain ( 'getLabelWidth(datum.textLabel,' ) ;
@@ -75,17 +75,17 @@ describe('getAnnotationWidth()', () => {
7575
7676describe ( 'getAnnotationPositionOffset()' , ( ) => {
7777 test ( 'returns 12.5 for vertical orientation' , ( ) => {
78- expect ( getAnnotationPositionOffset ( defaultBarOptions , { value : 12345 } ) ) . toEqual ( '12.5' ) ;
78+ expect ( getAnnotationPositionOffset ( defaultBarOptions , { value : 12345 } , ANNOTATION_PADDING ) ) . toEqual ( '12.5' ) ;
7979 } ) ;
8080
8181 test ( 'returns provided value / 2 + 2.5 when value is set and orientation is not vertical' , ( ) => {
82- expect ( getAnnotationPositionOffset ( { ...defaultBarOptions , orientation : 'horizontal' } , { value : 50 } ) ) . toEqual (
82+ expect ( getAnnotationPositionOffset ( { ...defaultBarOptions , orientation : 'horizontal' } , { value : 50 } , ANNOTATION_PADDING ) ) . toEqual (
8383 '27.5'
8484 ) ;
8585 } ) ;
8686
8787 test ( 'returns the signal string wrapped with parens when signal is set and orientation is not vertical' , ( ) => {
88- expect ( getAnnotationPositionOffset ( { ...defaultBarOptions , orientation : 'horizontal' } , { signal : 'foo' } ) ) . toEqual (
88+ expect ( getAnnotationPositionOffset ( { ...defaultBarOptions , orientation : 'horizontal' } , { signal : 'foo' } , ANNOTATION_PADDING ) ) . toEqual (
8989 '((foo) / 2 + 2.5)'
9090 ) ;
9191 } ) ;
@@ -95,7 +95,7 @@ describe('getAnnotationMetricAxisPosition()', () => {
9595 const defaultAnnotationWidth = { value : 22 } ;
9696
9797 test ( "defaultBarOptions, should return '${value}1' field" , ( ) => {
98- expect ( getAnnotationMetricAxisPosition ( defaultBarOptions , defaultAnnotationWidth ) ) . toStrictEqual ( [
98+ expect ( getAnnotationMetricAxisPosition ( defaultBarOptions , defaultAnnotationWidth , ANNOTATION_PADDING ) ) . toStrictEqual ( [
9999 {
100100 signal : `max(scale('yLinear', datum.${ defaultBarOptions . metric } 1), scale('yLinear', 0) + 12.5)` ,
101101 test : `datum.${ defaultBarOptions . metric } 1 < 0` ,
@@ -105,7 +105,7 @@ describe('getAnnotationMetricAxisPosition()', () => {
105105 } ) ;
106106 test ( 'horizontal orientation, should return with xLinear scale and min/max properties flipped' , ( ) => {
107107 expect (
108- getAnnotationMetricAxisPosition ( { ...defaultBarOptions , orientation : 'horizontal' } , defaultAnnotationWidth )
108+ getAnnotationMetricAxisPosition ( { ...defaultBarOptions , orientation : 'horizontal' } , defaultAnnotationWidth , ANNOTATION_PADDING )
109109 ) . toStrictEqual ( [
110110 {
111111 test : `datum.${ defaultBarOptions . metric } 1 < 0` ,
@@ -115,7 +115,7 @@ describe('getAnnotationMetricAxisPosition()', () => {
115115 ] ) ;
116116 } ) ;
117117 test ( "stacked with seconday scale, should return '${value}1' field" , ( ) => {
118- expect ( getAnnotationMetricAxisPosition ( defaultBarOptionsWithSecondayColor , defaultAnnotationWidth ) ) . toStrictEqual ( [
118+ expect ( getAnnotationMetricAxisPosition ( defaultBarOptionsWithSecondayColor , defaultAnnotationWidth , ANNOTATION_PADDING ) ) . toStrictEqual ( [
119119 {
120120 signal : `max(scale('yLinear', datum.${ defaultBarOptions . metric } 1), scale('yLinear', 0) + 12.5)` ,
121121 test : `datum.${ defaultBarOptions . metric } 1 < 0` ,
@@ -125,7 +125,7 @@ describe('getAnnotationMetricAxisPosition()', () => {
125125 } ) ;
126126 test ( "dodged without secondary scale, should return 'value' field" , ( ) => {
127127 expect (
128- getAnnotationMetricAxisPosition ( { ...defaultBarOptions , type : 'dodged' } , defaultAnnotationWidth )
128+ getAnnotationMetricAxisPosition ( { ...defaultBarOptions , type : 'dodged' } , defaultAnnotationWidth , ANNOTATION_PADDING )
129129 ) . toStrictEqual ( [
130130 {
131131 signal : `max(scale('yLinear', datum.${ defaultBarOptions . metric } ), scale('yLinear', 0) + 12.5)` ,
@@ -135,7 +135,7 @@ describe('getAnnotationMetricAxisPosition()', () => {
135135 ] ) ;
136136 } ) ;
137137 test ( "dodged with secondary scale, should return '${value}1' field" , ( ) => {
138- expect ( getAnnotationMetricAxisPosition ( defaultBarOptionsWithSecondayColor , defaultAnnotationWidth ) ) . toStrictEqual ( [
138+ expect ( getAnnotationMetricAxisPosition ( defaultBarOptionsWithSecondayColor , defaultAnnotationWidth , ANNOTATION_PADDING ) ) . toStrictEqual ( [
139139 {
140140 signal : `max(scale('yLinear', datum.${ defaultBarOptions . metric } 1), scale('yLinear', 0) + 12.5)` ,
141141 test : `datum.${ defaultBarOptions . metric } 1 < 0` ,
0 commit comments