Skip to content

Commit ab8839b

Browse files
committed
Fixed webpack minification issues and other importing issues.
1 parent bd2a057 commit ab8839b

17 files changed

+2755
-2751
lines changed

.babelrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"presets": ["es2015", "stage-0", "react"]
2+
"presets": [
3+
"@babel/preset-react",
4+
"@babel/preset-env"
5+
]
36
}

components/DrillDown.js

+288-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,289 @@
1-
import DrillDown from '../src/DrillDown';
1+
"use strict";
22

3-
module.exports = DrillDown;
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = void 0;
7+
8+
var _react = _interopRequireDefault(require("react"));
9+
10+
var _propTypes = _interopRequireDefault(require("prop-types"));
11+
12+
var _ReactFC = _interopRequireDefault(require("../lib/ReactFC"));
13+
14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
16+
function _extends() { _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; }; return _extends.apply(this, arguments); }
17+
18+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
19+
20+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21+
22+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
23+
24+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
25+
26+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
27+
28+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29+
30+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31+
32+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33+
34+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
35+
36+
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); } }
37+
38+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
39+
40+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
41+
42+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
43+
44+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45+
46+
var DrillDown =
47+
/*#__PURE__*/
48+
function (_React$Component) {
49+
_inherits(DrillDown, _React$Component);
50+
51+
_createClass(DrillDown, null, [{
52+
key: "fcRoot",
53+
// Resolve FusionCharts
54+
value: function fcRoot(core) {
55+
for (var _len = arguments.length, modules = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
56+
modules[_key - 1] = arguments[_key];
57+
}
58+
59+
_ReactFC.default.fcRoot.apply(_ReactFC.default, [core].concat(modules));
60+
}
61+
}]);
62+
63+
function DrillDown(props) {
64+
var _this$defButtonStyle;
65+
66+
var _this;
67+
68+
_classCallCheck(this, DrillDown);
69+
70+
_this = _possibleConstructorReturn(this, _getPrototypeOf(DrillDown).call(this, props));
71+
var btnConfig = props.btnConfig,
72+
btnStyle = props.btnStyle;
73+
_this.finalBtnConfig = Object.assign({}, DrillDown.defaultProps.btnConfig, btnConfig);
74+
75+
var _this$finalBtnConfig$ = _this.finalBtnConfig.placement.split('-');
76+
77+
var _this$finalBtnConfig$2 = _slicedToArray(_this$finalBtnConfig$, 2);
78+
79+
_this.positionV = _this$finalBtnConfig$2[0];
80+
_this.positionH = _this$finalBtnConfig$2[1];
81+
_this.state = {
82+
isBtnVisible: true,
83+
selectedChild: -1,
84+
isDrilledDown: false
85+
};
86+
/* Function Bindings */
87+
88+
_this.plotClicked = _this.plotClicked.bind(_assertThisInitialized(_assertThisInitialized(_this)));
89+
_this.onChildRendered = _this.onChildRendered.bind(_assertThisInitialized(_assertThisInitialized(_this)));
90+
_this.toggleParentBtnVisibility = _this.toggleParentBtnVisibility.bind(_assertThisInitialized(_assertThisInitialized(_this)));
91+
_this.onBtnClick = _this.onBtnClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
92+
/* Default styles */
93+
94+
_this.wrapperStyle = {
95+
position: 'relative',
96+
display: 'inline-block'
97+
};
98+
_this.defButtonStyle = (_this$defButtonStyle = {
99+
border: "1px solid ".concat(_this.finalBtnConfig.borderColor),
100+
backgroundColor: "".concat(_this.finalBtnConfig.backgroundColor),
101+
color: "".concat(_this.finalBtnConfig.color),
102+
fontFamily: "".concat(_this.finalBtnConfig.fontFamily),
103+
fontSize: "".concat(_this.finalBtnConfig.fontSize),
104+
padding: "".concat(_this.finalBtnConfig.padding),
105+
fontWeight: "".concat(_this.finalBtnConfig.fontWeight),
106+
position: 'absolute'
107+
}, _defineProperty(_this$defButtonStyle, _this.positionH, "".concat(_this.finalBtnConfig.margin)), _defineProperty(_this$defButtonStyle, _this.positionV, "".concat(_this.finalBtnConfig.margin)), _defineProperty(_this$defButtonStyle, "cursor", 'pointer'), _this$defButtonStyle);
108+
_this.finBtnStyle = typeof btnStyle === 'undefined' ? _this.defButtonStyle : btnStyle;
109+
return _this;
110+
}
111+
112+
_createClass(DrillDown, [{
113+
key: "determinePlotMapType",
114+
value: function determinePlotMapType(plotChildMap) {
115+
var isNumberFound = false;
116+
var isObjectFound = false;
117+
plotChildMap.forEach(function (val) {
118+
if (typeof val === 'undefined' || val === null) return;
119+
if (typeof val === 'number' && val > -1) isNumberFound = true;
120+
if (_typeof(val) === 'object') isObjectFound = true;
121+
});
122+
123+
if (isNumberFound && isObjectFound) {
124+
return 'invalid';
125+
}
126+
127+
if (isNumberFound) return 'number';
128+
if (isObjectFound) return 'object';
129+
return 'noop';
130+
}
131+
}, {
132+
key: "plotClicked",
133+
value: function plotClicked(e) {
134+
var index = e.data.index;
135+
var propChildren = Array.isArray(this.props.children) ? this.props.children : [this.props.children];
136+
var childrenLen = propChildren.length;
137+
var plotChildMap = this.props.plotChildMap;
138+
if (childrenLen === 0) return; // Further Optimization needed.
139+
140+
var mapType = this.determinePlotMapType(plotChildMap); // Case : Array of numbers
141+
142+
if (mapType === 'number') {
143+
var childPosition = plotChildMap[index];
144+
if (childPosition === null || typeof childPosition === 'undefined' || childPosition >= childrenLen || childPosition < 0) return;
145+
this.setState({
146+
selectedChild: childPosition,
147+
isDrilledDown: true
148+
});
149+
} // Case : Array of objects
150+
151+
152+
if (mapType === 'object') {
153+
for (var i = 0; i < childrenLen; i++) {
154+
if (typeof plotChildMap[i] === 'undefined' || plotChildMap[i] === null) continue;
155+
var _plotChildMap$i = plotChildMap[i],
156+
plotPosition = _plotChildMap$i.plotPosition,
157+
_childPosition = _plotChildMap$i.childPosition;
158+
159+
if (plotPosition === index && _childPosition !== null && typeof _childPosition !== 'undefined' && _childPosition < childrenLen && _childPosition > -1) {
160+
this.setState({
161+
selectedChild: _childPosition,
162+
isDrilledDown: true
163+
});
164+
return;
165+
}
166+
}
167+
} // Case : Heterogeneous
168+
169+
170+
if (mapType === 'invalid') {
171+
console.log('Invalid heterogeneous data: Please check proptypes for - plotChildMap');
172+
}
173+
}
174+
}, {
175+
key: "cloneReactFCChild",
176+
value: function cloneReactFCChild(reactFCElem, customProps) {
177+
return _react.default.cloneElement(reactFCElem, customProps);
178+
}
179+
}, {
180+
key: "onChildRendered",
181+
value: function onChildRendered() {
182+
if (this.props.toggleParentBtnVisibility) {
183+
this.props.toggleParentBtnVisibility(false);
184+
}
185+
}
186+
}, {
187+
key: "toggleParentBtnVisibility",
188+
value: function toggleParentBtnVisibility(isBtnVisible) {
189+
this.setState({
190+
isBtnVisible: isBtnVisible
191+
});
192+
}
193+
}, {
194+
key: "onBtnClick",
195+
value: function onBtnClick() {
196+
this.setState({
197+
isDrilledDown: false
198+
});
199+
200+
if (this.props.toggleParentBtnVisibility) {
201+
this.props.toggleParentBtnVisibility(true);
202+
}
203+
}
204+
}, {
205+
key: "render",
206+
value: function render() {
207+
var component;
208+
var _this$state = this.state,
209+
selectedChild = _this$state.selectedChild,
210+
isBtnVisible = _this$state.isBtnVisible;
211+
var _this$props = this.props,
212+
children = _this$props.children,
213+
width = _this$props.width,
214+
height = _this$props.height;
215+
var clonedElemConfig = {
216+
width: width,
217+
height: height,
218+
onRender: this.onChildRendered,
219+
toggleParentBtnVisibility: this.toggleParentBtnVisibility
220+
};
221+
222+
if (!this.state.isDrilledDown) {
223+
component = _react.default.createElement(_ReactFC.default, _extends({}, this.props, {
224+
"fcEvent-dataplotClick": this.plotClicked
225+
}));
226+
} else {
227+
var propChildren = Array.isArray(children) ? children : [children];
228+
component = _react.default.createElement("div", {
229+
style: this.wrapperStyle
230+
}, this.cloneReactFCChild(propChildren[selectedChild], clonedElemConfig), isBtnVisible ? _react.default.createElement("button", {
231+
style: this.finBtnStyle,
232+
onClick: this.onBtnClick
233+
}, this.finalBtnConfig.text) : null);
234+
}
235+
236+
return component;
237+
}
238+
}]);
239+
240+
return DrillDown;
241+
}(_react.default.Component);
242+
243+
DrillDown.defaultProps = {
244+
plotChildMap: [],
245+
btnConfig: {
246+
text: 'Back',
247+
color: '#000000',
248+
backgroundColor: '#F6F6F6',
249+
borderColor: '#000000',
250+
fontSize: '14px',
251+
fontWeight: 'bold',
252+
padding: '3px',
253+
fontFamily: 'Verdana, sans',
254+
placement: 'top-right',
255+
margin: '10px'
256+
},
257+
btnStyle: undefined,
258+
dataSource: {},
259+
dataFormat: 'json',
260+
type: '',
261+
height: '',
262+
width: ''
263+
};
264+
DrillDown.propTypes = {
265+
plotChildMap: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.shape({
266+
plotPosition: _propTypes.default.number,
267+
childPosition: _propTypes.default.number
268+
})), _propTypes.default.arrayOf(_propTypes.default.number)]),
269+
btnConfig: _propTypes.default.shape({
270+
text: _propTypes.default.string,
271+
color: _propTypes.default.string,
272+
backgroundColor: _propTypes.default.string,
273+
borderColor: _propTypes.default.string,
274+
fontSize: _propTypes.default.string,
275+
fontWeight: _propTypes.default.string,
276+
padding: _propTypes.default.string,
277+
fontFamily: _propTypes.default.string,
278+
placement: _propTypes.default.oneOf(['top-left', 'top-right', 'bottom-left', 'bottom-right']),
279+
margin: _propTypes.default.string
280+
}),
281+
btnStyle: _propTypes.default.object,
282+
dataSource: _propTypes.default.object,
283+
dataFormat: _propTypes.default.string,
284+
type: _propTypes.default.string,
285+
height: _propTypes.default.string,
286+
width: _propTypes.default.string
287+
};
288+
var _default = DrillDown;
289+
exports.default = _default;

0 commit comments

Comments
 (0)