File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
src/components/VerticalBars Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ .ydb-bars {
2+ display : flex ;
3+ flex-direction : row ;
4+ align-items : flex-end ;
5+
6+ height : 20px ;
7+
8+ & __value {
9+ display : flex ;
10+
11+ width : 6px ;
12+ min-height : 3px ;
13+ margin-right : 2px ;
14+
15+ background-color : var (--yc-color-infographics-info-heavy );
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ import cn from 'bem-cn-lite' ;
2+ import { useMemo } from 'react' ;
3+
4+ import './VerticalBars.scss' ;
5+
6+ const b = cn ( 'ydb-bars' ) ;
7+
8+ const calculateValuesInPercents = ( values : number [ ] ) => {
9+ const max = Math . max ( ...values ) ;
10+
11+ if ( ! max ) {
12+ return values ;
13+ }
14+
15+ const res = [ ] ;
16+
17+ for ( const value of values ) {
18+ res . push ( ( value / max ) * 100 ) ;
19+ }
20+
21+ return res ;
22+ } ;
23+
24+ interface VerticalBarsProps {
25+ values : number [ ] ;
26+ }
27+
28+ export const VerticalBars = ( { values} : VerticalBarsProps ) => {
29+ const preparedValues = useMemo ( ( ) => calculateValuesInPercents ( values ) , [ values ] ) ;
30+
31+ const getBars = ( ) => {
32+ return preparedValues . map ( ( value , index ) => {
33+ return < div key = { index } style = { { height : `${ value } %` } } className = { b ( 'value' ) } /> ;
34+ } ) ;
35+ } ;
36+
37+ return < div className = { b ( ) } > { getBars ( ) } </ div > ;
38+ } ;
Original file line number Diff line number Diff line change 1+ export * from './VerticalBars' ;
You can’t perform that action at this time.
0 commit comments