@@ -80,7 +80,13 @@ const NeoBarChart = (props: ChartProps) => {
80
80
const marginBottom = ( settings [ "marginBottom" ] ) ? settings [ "marginBottom" ] : 40 ;
81
81
const legend = ( settings [ "legend" ] ) ? settings [ "legend" ] : false ;
82
82
const labelRotation = ( settings [ "labelRotation" ] != undefined ) ? settings [ "labelRotation" ] : 45 ;
83
- const labelSkipSize = ( settings [ "barValues" ] ) ? 1 : 2000 ;
83
+
84
+ const labelSkipWidth = ( settings [ "labelSkipWidth" ] ) ? ( settings [ "labelSkipWidth" ] ) : 0 ;
85
+ const labelSkipHeight = ( settings [ "labelSkipHeight" ] ) ? ( settings [ "labelSkipHeight" ] ) : 0 ;
86
+ const enableLabel = ( settings [ "barValues" ] ) ? settings [ "barValues" ] : false ;
87
+ const positionLabel = ( settings [ "positionLabel" ] ) ? settings [ "positionLabel" ] : 'off' ;
88
+
89
+ const layout = ( settings [ "layout" ] ) ? settings [ "layout" ] : 'vertical' ;
84
90
const colorScheme = ( settings [ "colors" ] ) ? settings [ "colors" ] : 'set2' ;
85
91
const groupMode = ( settings [ "groupMode" ] ) ? settings [ "groupMode" ] : 'stacked' ;
86
92
const valueScale = ( settings [ "valueScale" ] ) ? settings [ "valueScale" ] : 'linear' ;
@@ -107,11 +113,69 @@ const NeoBarChart = (props: ChartProps) => {
107
113
return < NoDrawableDataErrorMessage />
108
114
}
109
115
116
+ const BarComponent = ( { bar, borderColor } ) => {
117
+ let shade = false ;
118
+ let darkTop = false ;
119
+ let includeIndex = false ;
120
+ let x = bar . width / 2 , y = bar . height / 2 , textAnchor = "middle" ;
121
+ if ( positionLabel == "top" )
122
+ if ( layout == "vertical" )
123
+ y = - 10 ;
124
+ else
125
+ x = bar . width + 10 ;
126
+ else if ( positionLabel == "bottom" )
127
+ if ( layout == "vertical" )
128
+ y = bar . height + 10 ;
129
+ else
130
+ x = - 10 ;
131
+
132
+ return (
133
+ < g transform = { `translate(${ bar . x } ,${ bar . y } )` } >
134
+ { shade ? < rect x = { - 3 } y = { 7 } width = { bar . width } height = { bar . height } fill = "rgba(0, 0, 0, .07)" /> : < > </ > }
135
+ < rect width = { bar . width } height = { bar . height } fill = { bar . color } />
136
+ { darkTop ? < rect
137
+ x = { bar . width - 5 }
138
+ width = { 5 }
139
+ height = { bar . height }
140
+ fill = { borderColor }
141
+ fillOpacity = { 0.2 }
142
+ /> : < > </ > }
143
+ { includeIndex ? < text
144
+ x = { bar . width - 16 }
145
+ y = { bar . height / 2 }
146
+ textAnchor = "end"
147
+ dominantBaseline = "central"
148
+ fill = "black"
149
+ style = { {
150
+ fontWeight : 900 ,
151
+ fontSize : 15 ,
152
+ } }
153
+ >
154
+ { bar . data . indexValue }
155
+ </ text > : < > </ > }
156
+ { enableLabel ? < text
157
+ x = { x }
158
+ y = { y }
159
+ textAnchor = { textAnchor }
160
+ dominantBaseline = "central"
161
+ fill = { borderColor }
162
+ style = { {
163
+ fontWeight : 400 ,
164
+ fontSize : 13 ,
165
+ } }
166
+ >
167
+ { bar . data . value }
168
+ </ text > : < > </ > }
169
+ </ g >
170
+ )
171
+ }
110
172
// TODO: Get rid of duplicate pie slice names...
111
173
174
+ const extraProperties = positionLabel == "off" ? { } : { barComponent : BarComponent } ;
112
175
return < ResponsiveBar
113
- layout = { settings . layout == "horizontal" ? 'horizontal' : 'vertical' }
176
+ layout = { layout }
114
177
groupMode = { groupMode == "stacked" ? 'stacked' : 'grouped' }
178
+ enableLabel = { enableLabel }
115
179
data = { data }
116
180
keys = { Object . keys ( keys ) }
117
181
indexBy = "index"
@@ -133,9 +197,10 @@ const NeoBarChart = (props: ChartProps) => {
133
197
tickPadding : 5 ,
134
198
tickRotation : 0 ,
135
199
} }
136
- labelSkipWidth = { labelSkipSize }
137
- labelSkipHeight = { labelSkipSize }
200
+ labelSkipWidth = { labelSkipWidth }
201
+ labelSkipHeight = { labelSkipHeight }
138
202
labelTextColor = { { from : 'color' , modifiers : [ [ 'darker' , 1.6 ] ] } }
203
+ { ...extraProperties }
139
204
legends = { ( legend ) ? [
140
205
{
141
206
dataFrom : 'keys' ,
0 commit comments