@@ -2,6 +2,7 @@ import React from 'react';
2
2
import { isNumber , round } from 'lodash' ;
3
3
import NoData from 'ui/components/Graphs/NoData' ;
4
4
import numeral from 'numeral' ;
5
+ import styled from 'styled-components' ;
5
6
import tooltipFactory from 'react-toolbox/lib/tooltip' ;
6
7
import { Link } from 'react-toolbox/lib/link' ;
7
8
import { getPercentage } from 'ui/utils/defaultTitles' ;
@@ -40,16 +41,34 @@ const resultsIconStyles = {
40
41
width : '40px' ,
41
42
} ;
42
43
43
- const renderCount = ( { color, count, tooltip, hasBenchmark } ) => (
44
+ const ContextLabel = styled . div ( ( ) => ( {
45
+ 'font-size' : '20p' ,
46
+ 'margin-bottom' : '5px' ,
47
+ 'margin-top' : '-10px' ,
48
+ 'white-space' : 'nowrap' ,
49
+ overflow : 'hidden' ,
50
+ 'text-overflow' : 'ellipsis'
51
+ } ) ) ;
52
+
53
+
54
+ const renderCount = ( { color, count, tooltip, hasBenchmark, hasContextLabel } ) => (
44
55
< TooltipLink
45
- style = { { color, height : hasBenchmark ? null : '100%' } }
56
+ style = { { color, height : hasBenchmark || hasContextLabel ? null : '100%' } }
46
57
label = { formatShortNumber ( count ) }
47
58
tooltip = { tooltip }
48
59
tooltipPosition = "top"
49
60
tooltipDelay = { 600 }
50
61
active />
51
62
) ;
52
63
64
+ const renderСontextLabel = ( { contextLabel, fontSize, color } ) => (
65
+ < ContextLabel
66
+ style = { { fontSize, color } }
67
+ key = "contextLabel" >
68
+ { contextLabel }
69
+ </ ContextLabel >
70
+ ) ;
71
+
53
72
const renderBenchmark = ( { percentage, model } ) => {
54
73
if ( percentage . result === 'N/A' ) {
55
74
return percentage . result ;
@@ -73,39 +92,42 @@ const renderBenchmark = ({ percentage, model }) => {
73
92
) ;
74
93
} ;
75
94
76
- const getCountFontsize = ( { height, width, hasBenchmark, maxSize } ) => {
77
- let fontSize = hasBenchmark ? `${ maxSize / 40 } ` : `${ maxSize / 20 } ` ;
78
- const tripHeight = hasBenchmark ? 220 : 150 ;
95
+ const getCountFontsize = ( { height, width, hasBenchmark, hasContextLabel , maxSize } ) => {
96
+ let fontSize = hasBenchmark || hasContextLabel ? `${ maxSize / 40 } ` : `${ maxSize / 20 } ` ;
97
+ const tripHeight = hasBenchmark || hasContextLabel ? 550 : 200 ;
79
98
if ( height < tripHeight ) {
80
- if ( ! hasBenchmark ) {
99
+ if ( ! hasBenchmark && ! hasContextLabel ) {
81
100
fontSize = width > 200 ? 4.5 : 3.5 ;
82
101
}
83
102
} else if ( width < 550 ) {
84
103
fontSize = width / 60 ;
104
+ console . log ( `fontSize: ${ fontSize } ` ) ;
85
105
}
86
106
if ( fontSize > 12 ) fontSize = 12 ;
87
107
return `${ fontSize } em` ;
88
108
} ;
89
109
90
110
const renderCounter = ( { color, results, model, height, width } ) => {
91
111
const maxSize = Math . min ( height , width ) ;
92
- const fontSize = ( width < 332 ) || ( maxSize < 245 ) ? '13px ' : '0.2em ' ;
112
+ const fontSize = ( width < 332 ) || ( maxSize < 245 ) ? '18px ' : '0.25em ' ;
93
113
const hasBenchmark = results . size > 1 ;
114
+ const hasContextLabel = model . get ( 'contextLabel' , '' ) !== '' ;
94
115
const benchmarkCount = hasBenchmark ? getBenchmarkResultCount ( results ) : null ;
95
116
const count = getResultCount ( results ) ;
96
117
const percentage = getPercentage ( count , benchmarkCount ) ;
97
118
98
119
const tooltip = hasBenchmark ? formatBenchmarkTooltip ( { count, benchmarkCount } ) : formatTooltip ( count ) ;
99
- const countFontsize = getCountFontsize ( { height, width, hasBenchmark, maxSize } ) ;
100
- const renderedCount = renderCount ( { color, count, tooltip, hasBenchmark } ) ;
120
+ const countFontsize = getCountFontsize ( { height, width, hasBenchmark, hasContextLabel , maxSize } ) ;
121
+ const renderedCount = renderCount ( { color, count, tooltip, hasBenchmark, hasContextLabel } ) ;
101
122
const renderedBenchmark = hasBenchmark ? renderBenchmark ( { percentage, model } ) : null ;
102
-
123
+ const renderedContextLabel = renderСontextLabel ( { contextLabel : model . get ( 'contextLabel' , '' ) , fontSize , color } ) ;
103
124
104
125
return (
105
126
< div style = { { height : '100%' } } >
106
127
< div
107
128
style = { { width, fontSize : countFontsize , height : '100%' , textAlign : 'center' } } >
108
- { renderedCount }
129
+ { renderedCount }
130
+ { renderedContextLabel }
109
131
< div
110
132
key = "benchmark"
111
133
style = { {
0 commit comments