Skip to content

Commit 3e45c12

Browse files
committed
barchart label
1 parent eb49d42 commit 3e45c12

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

public/react-js/birdwatch.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,16 @@ var BirdWatch = BirdWatch || {};
519519
var percSlope = regression('linear', regressionData(this.state.percHist)).equation[0];
520520
var percArrDir = "RIGHT-UP";
521521
if (percSlope < 0) { percArrDir = "RIGHT-DOWN"; }
522+
var textX = w+135;
523+
var style = {fontWeight: 500, fill: "#EEE", textAnchor: "end"};
524+
if (w < 70) { style.fill="#999"; textX+=20; style.textAnchor="start"}
522525

523526
return React.DOM.g(null,
524-
React.DOM.text( {y:y +12, x:"117", stroke:"none", fill:"black", dy:".35em", textAnchor:"end"}, t),
527+
React.DOM.text( {y:y+12, x:"117", stroke:"none", fill:"black", dy:".35em", textAnchor:"end"}, t),
525528
Arrow( {dir:posArrDir, y:y, x:126} ),
526529
Arrow( {dir:percArrDir, y:y, x:140} ),
527530
React.DOM.rect( {y:y, x:"148", height:"15", width:w, stroke:"white", fill:"#428bca"}),
528-
React.DOM.text( {y:y +12, x:w+154, stroke:"none", fill:"black", dy:".35em", textAnchor:"start"}, val)
531+
React.DOM.text( {y:y+12, x:textX, stroke:"none", style:style, dy:".35em"} , val)
529532
)
530533
}
531534
});
@@ -536,7 +539,7 @@ var BirdWatch = BirdWatch || {};
536539
var bars = this.props.words.map(function (bar, i, arr) {
537540
if (!bar) return "";
538541
var y = i * 15;
539-
var w = bar.value / arr[0].value * (barChartElem.width() - 216);
542+
var w = bar.value / arr[0].value * (barChartElem.width() - 170);
540543
return Bar( {t:bar.key, y:y, w:w, key:bar.key, idx:i, val:bar.value, count:this.props.count} );
541544
}.bind(this));
542545
return React.DOM.svg( {width:"750", height:"6000"},

react-js/jsx/barchart.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ var BirdWatch = BirdWatch || {};
5656
var percSlope = regression('linear', regressionData(this.state.percHist)).equation[0];
5757
var percArrDir = "RIGHT-UP";
5858
if (percSlope < 0) { percArrDir = "RIGHT-DOWN"; }
59+
var textX = w+135;
60+
var style = {fontWeight: 500, fill: "#EEE", textAnchor: "end"};
61+
if (w < 70) { style.fill="#999"; textX+=20; style.textAnchor="start"}
5962

6063
return <g>
61-
<text y={y +12} x="117" stroke="none" fill="black" dy=".35em" textAnchor="end">{t}</text>
64+
<text y={y+12} x="117" stroke="none" fill="black" dy=".35em" textAnchor="end">{t}</text>
6265
<Arrow dir={posArrDir} y={y} x={126} />
6366
<Arrow dir={percArrDir} y={y} x={140} />
6467
<rect y={y} x="148" height="15" width={w} stroke="white" fill="#428bca"></rect>
65-
<text y={y +12} x={w+154} stroke="none" fill="black" dy=".35em" textAnchor="start">{val}</text>
68+
<text y={y+12} x={textX} stroke="none" style={style} dy=".35em" >{val}</text>
6669
</g>
6770
}
6871
});
@@ -73,7 +76,7 @@ var BirdWatch = BirdWatch || {};
7376
var bars = this.props.words.map(function (bar, i, arr) {
7477
if (!bar) return "";
7578
var y = i * 15;
76-
var w = bar.value / arr[0].value * (barChartElem.width() - 216);
79+
var w = bar.value / arr[0].value * (barChartElem.width() - 170);
7780
return <Bar t={bar.key} y={y} w={w} key={bar.key} idx={i} val={bar.value} count={this.props.count} />;
7881
}.bind(this));
7982
return <svg width="750" height="6000">

0 commit comments

Comments
 (0)