Skip to content

Up to date react and babel modules. #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ dist/
example/dist
example/dist_es5
npm-debug.log
lib
.idea
177 changes: 177 additions & 0 deletions lib/axis/axis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _d3Axis = require('d3-axis');

var _d3Axis2 = _interopRequireDefault(_d3Axis);

var _d3Selection = require('d3-selection');

var _d3Selection2 = _interopRequireDefault(_d3Selection);

var _reactFauxDom = require('react-faux-dom');

var _reactFauxDom2 = _interopRequireDefault(_reactFauxDom);

var _scale = require('../utils/scale');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Axis = function (_Component) {
_inherits(Axis, _Component);

function Axis(props) {
_classCallCheck(this, Axis);

return _possibleConstructorReturn(this, (Axis.__proto__ || Object.getPrototypeOf(Axis)).call(this, props));
}

_createClass(Axis, [{
key: '_mkTickAxis',
value: function _mkTickAxis() {
var _props = this.props,
type = _props.type,
tickOrient = _props.tickOrient,
tickFormat = _props.tickFormat,
tickPadding = _props.tickPadding,
tickSizeInner = _props.tickSizeInner,
tickSizeOuter = _props.tickSizeOuter,
ticks = _props.ticks,
tickValues = _props.tickValues;


var func = _d3Axis2.default;

if (tickOrient === 'left') {
func = func.axisLeft(this._mkScale(this.props));
} else if (tickOrient === 'right') {
func = func.axisRight(this._mkScale(this.props));
} else if (tickOrient === 'top') {
func = func.axisTop(this._mkScale(this.props));
} else if (tickOrient === 'bottom') {
func = func.axisBottom(this._mkScale(this.props));
}

if (tickFormat) func.tickFormat(tickFormat);

if (tickPadding) func.tickPadding(tickPadding);

if (tickSizeOuter) func.tickSizeOuter(tickSizeOuter);

if (tickSizeInner) func.tickSizeInner(tickSizeInner);

if (tickValues) func.tickValues(tickValues);

if (ticks) func.ticks.apply(null, ticks);

return func;
}
}, {
key: '_mkScale',
value: function _mkScale() {
var newScale;

if (this.props.scale === 'ordinal') newScale = 'band';else newScale = this.props.scale;

var func = (0, _scale.scale)(Object.assign({}, this.props, { scale: newScale }));

return func;
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
showAxis = _props2.showAxis,
gridAxisClassName = _props2.gridAxisClassName,
axisClassName = _props2.axisClassName,
type = _props2.type,
style = _props2.style,
axisStyling = _props2.axisStyling,
gridStyleClassName = _props2.gridStyleClassName;


var axisGroup = _reactFauxDom2.default.createElement('g');

if (type === 'x') var axisClasses = axisClassName + ' axis x';else if (type === 'y') var axisClasses = axisClassName + ' axis y';else if (type === 'gridx' || type === 'gridy') var axisClasses = gridAxisClassName + ' grid-axis';

axisGroup.setAttribute('class', axisClasses);

var axisDom = _d3Selection2.default.select(axisGroup);

axisDom.call(this._mkTickAxis());

if (!showAxis) {
axisDom.selectAll(".grid-axis .tick text").style("opacity", "0");

if (type === 'gridx' || type === 'gridy') {
// hide domain in grids
axisDom.selectAll(".grid-axis .domain").style("opacity", "0");
}
}

// apply user defined axis path style (path refers to x-axis line)if provided or else default
if (axisStyling && axisStyling.pathClassName) {
var axisPath = axisDom.selectAll('.axis path');
axisPath.attr("class", axisStyling.pathClassName);
} else axisDom.selectAll('.axis path').style('fill', 'none').style('stroke', '#000').style('shape-rendering', 'crispEdges').style('display', 'none'

// apply user defined style for axis tick line if provided or else default
);if (axisStyling && axisStyling.ticksClassName) {
var axisLine = axisDom.selectAll('.axis line');
axisLine.attr("class", axisStyling.ticksClassName);
} else axisDom.selectAll('.axis line').style('fill', 'none').style('stroke', '#000').style('shape-rendering', 'crispEdges');

// apply user defined style for grid axes if provided or else default
if (gridStyleClassName) {
var grids = axisDom.selectAll('.grid-axis line');
grids.attr("class", gridStyleClassName);
} else axisDom.selectAll('.grid-axis line').style('opacity', .2).style('fill', 'none').style('stroke', '#000').style('stroke-width', '1.5px'

// Axis tick labels style
);var axisText = axisDom.selectAll('.axis text');
if (style) {
for (var key in style) {
axisText.style(key, style[key]);
}
}
// user defined style for axis labels
else if (axisStyling && axisStyling.textClassName) {
axisText.attr("class", axisStyling.textClassName);
}

return axisDom.node().toReact();
}
}]);

return Axis;
}(_react.Component);

Axis.defaultProps = {
range: null,
rangeRoundBands: null,
domain: null,
tickFormat: null,
tickOrient: null
};
Axis.PropTypes = {
showAxis: _react.PropTypes.bool,
type: _react.PropTypes.string,
orient: _react.PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
tickOrient: _react.PropTypes.oneOf(['top', 'bottom', 'left', 'right'])
};
exports.default = Axis;
119 changes: 119 additions & 0 deletions lib/axis/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _d3Selection = require('d3-selection');

var _d3Selection2 = _interopRequireDefault(_d3Selection);

var _reactFauxDom = require('react-faux-dom');

var _reactFauxDom2 = _interopRequireDefault(_reactFauxDom);

var _commonProps = require('../commonProps');

var _commonProps2 = _interopRequireDefault(_commonProps);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Label = function (_Component) {
_inherits(Label, _Component);

function Label(props) {
_classCallCheck(this, Label);

return _possibleConstructorReturn(this, (Label.__proto__ || Object.getPrototypeOf(Label)).call(this, props));
}

_createClass(Label, [{
key: '_mkLabel',
value: function _mkLabel(dom) {
var _props = this.props,
height = _props.height,
width = _props.width,
margins = _props.margins,
labelOffset = _props.labelOffset,
labelTitle = _props.labelTitle,
labelPosition = _props.labelPosition,
vTransform = _props.vTransform,
hTransform = _props.hTransform,
textAnchor = _props.textAnchor;


var labelDom = _d3Selection2.default.select(dom);
var fixWidth = width - margins.left - margins.right;
var fixHeight = height - margins.top - margins.bottom;

if (labelPosition === 'top') {

labelDom.attr('transform', hTransform).attr('y', -labelOffset).attr('x', fixWidth / 2).style('text-anchor', textAnchor).text(labelTitle);
} else if (labelPosition === 'bottom') {

labelDom.attr('transform', hTransform).attr('y', +labelOffset).attr('x', fixWidth / 2).style('text-anchor', textAnchor).text(labelTitle);
} else if (labelPosition === 'left') {

labelDom.attr('transform', vTransform).attr('y', -labelOffset).attr('x', -fixHeight / 2).style('text-anchor', textAnchor).text(labelTitle);
} else if (labelPosition === 'right') {

labelDom.attr('transform', vTransform).attr('y', +labelOffset).attr('x', -fixHeight / 2).style('text-anchor', textAnchor).text(labelTitle);
}

return labelDom;
}
}, {
key: 'render',
value: function render() {
var labelClassName = this.props.labelClassName;


var labelText = _reactFauxDom2.default.createElement('text');
var labelClasses = labelClassName + ' label';
labelText.setAttribute('class', labelClasses);

var labelDom = this._mkLabel(labelText);

return labelDom.node().toReact();
}
}]);

return Label;
}(_react.Component);

Label.defaultProps = _extends({
hTransform: 'rotate(0)',
vTransform: 'rotate(270)',
labelTitle: 'label title',
labelPosition: 'bottom',
labelOffset: 40,
textAnchor: 'middle',
labelClassName: 'react-d3-core__label'
}, _commonProps2.default);
Label.propTypes = {
height: _react.PropTypes.number.isRequired,
width: _react.PropTypes.number.isRequired,
margins: _react.PropTypes.object.isRequired,
hTransform: _react.PropTypes.string,
vTransform: _react.PropTypes.string,
labelTitle: _react.PropTypes.string,
labelPosition: _react.PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
labelOffset: _react.PropTypes.number,
textAnchor: _react.PropTypes.string,
labelClassName: _react.PropTypes.string
};
exports.default = Label;
Loading