forked from esnet/react-timeseries-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabel.js
99 lines (84 loc) · 2.37 KB
/
Label.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Renders a simple label surrounded by a box within in svg
*
* +----------------+
* | My label |
* | |
* +----------------+
*/
var Label = function Label(_ref) {
var label = _ref.label,
style = _ref.style,
align = _ref.align,
width = _ref.width,
height = _ref.height;
var textStyle = {
fontSize: 11,
textAnchor: "left",
fill: "#b0b0b0",
pointerEvents: "none"
};
var textStyleCentered = {
fontSize: 11,
textAnchor: "middle",
fill: "#bdbdbd",
pointerEvents: "none"
};
var tstyle = align === "center" ? textStyleCentered : textStyle;
var posx = align === "center" ? parseInt(width / 2, 10) : 10;
var text = _react2.default.createElement(
"text",
{ x: posx, y: 5, dy: "1.2em", style: tstyle },
label
);
var box = _react2.default.createElement("rect", { x: 0, y: 0, style: style, width: width, height: height });
return _react2.default.createElement(
"g",
null,
box,
text
);
}; /**
* Copyright (c) 2016, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt
* of any required approvals from the U.S. Dept. of Energy).
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
Label.defaultProps = {
align: "center",
width: 100,
height: 100,
pointerEvents: "none",
style: { fill: "#FEFEFE", stroke: "#DDD", opacity: 0.8 }
};
Label.propTypes = {
align: _react2.default.PropTypes.oneOf(["center", "left"]),
/**
* The label to render
*/
label: _react2.default.PropTypes.string.isRequired,
/**
* The style of the label. This is the inline CSS applied directly
* to the label box
*/
style: _react2.default.PropTypes.object, // eslint-disable-line
/**
* The width of the rectangle to render into
*/
width: _react2.default.PropTypes.number,
/**
* The height of the rectangle to render into
*/
height: _react2.default.PropTypes.number
};
exports.default = Label;