11import React , { Component } from 'react'
22import { CONSTANTS } from '../../Utility/config.js' ;
3-
3+ import ShowValue from './ShowValue.js' ;
4+ import './style.css'
45class Canvas extends Component {
56
67 constructor ( props ) {
@@ -9,20 +10,33 @@ class Canvas extends Component {
910
1011
1112 render ( ) {
12- const { generatedArray } = this . props ;
13+ const { generatedArray, showHeight, defaultBarColor } = this . props ;
14+
1315 const arrayLength = generatedArray . length ;
1416 const MARGIN = CONSTANTS . margin ;
1517 const SCREEN_WIDTH = window . innerWidth ;
1618 const BAR_WIDTH = Math . floor ( ( SCREEN_WIDTH - ( MARGIN * arrayLength ) ) / arrayLength ) ;
1719 const MARGIN_BTW_CANVAS_OPTIONS = 122 ;
1820 const CANVAS_HEIGHT = window . innerHeight - CONSTANTS . OFFSET + MARGIN_BTW_CANVAS_OPTIONS + "px" ;
21+ const FONT_SIZE = Math . floor ( BAR_WIDTH * 0.4 ) ;
1922
23+ const PINK = "#ff595e" ;
24+ const PURPLE = "#6a4c93" ;
25+
26+ console . log ( defaultBarColor )
2027
2128 return (
22- < div className = { `w-full flex justify-center dark:bg-lightGray` } style = { { minHeight :CANVAS_HEIGHT } } >
29+ < div className = { `w-full flex justify-center dark:bg-lightGray relative` } style = { { minHeight :CANVAS_HEIGHT } } >
30+
2331 < div className = "flex items-end" >
2432 { generatedArray . map ( ( element ) => {
25- return < div id = { `${ element } ` } key = { Math . random ( ) } style = { { height : element + 'px' , width : BAR_WIDTH + 'px' , backgroundColor : this . props . barColor } } className = { `array-bars m-[1px] rounded-t-md` } />
33+ return (
34+ < div id = { `${ element } ` } font-size = { FONT_SIZE } data = { `${ ( BAR_WIDTH > 25 && element > FONT_SIZE + 16 && showHeight ) ? element : '' } ` } length = "40px" key = { Math . random ( ) } style = { { "--bar-font-size" :FONT_SIZE + "px" , height : element + 'px' , width : BAR_WIDTH + 'px' , backgroundColor : this . props . barColor } }
35+ className = { `array-bars m-[1px] rounded-t-md relative ${ ( defaultBarColor !== PINK && defaultBarColor !== PURPLE && defaultBarColor !== 'black' ) ? "after:text-gray-700" : "after:text-white" } ` } >
36+ { /* {(BAR_WIDTH > 38 && element > FONT_SIZE+16) && <p className={`text-center font-bold text-gray-800`} style={{fontSize: FONT_SIZE+"px"}}>{element}</p> } */ }
37+ </ div >
38+ )
39+
2640 } ) }
2741 </ div >
2842 </ div >
0 commit comments