UNPKG

d3-react-component

Version:

A class-based React Componenet for D3 visualizations

1 lines 5.13 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("D3Chart",[],e):"object"==typeof exports?exports.D3Chart=e():t.D3Chart=e()}(global,(function(){return(()=>{"use strict";var t={179:(t,e,r)=>{r.r(e),r.d(e,{D3Chart:()=>y});const o=require("react");var n=r.n(o);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function p(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?a(Object(r),!0).forEach((function(e){u(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function u(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function f(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t,e){return!e||"object"!==i(e)&&"function"!=typeof e?d(t):e}function d(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var y=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}(u,t);var e,r,o,i,a=(o=u,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=h(o);if(i){var r=h(this).constructor;t=Reflect.construct(e,arguments,r)}else t=e.apply(this,arguments);return l(this,t)});function u(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(c(this,u),t=a.call(this,e),!window.d3)throw new Error("D3 is not loaded");return t.d3=window.d3,t.margin={top:0,right:0,bottom:0,left:0},(t.props.marginTop||t.props.topMargin)&&(t.margin.top=t.props.marginTop||t.props.topMargin),(t.props.marginRight||t.props.rightMargin)&&(t.margin.right=t.props.marginRight||t.props.rightMargin),(t.props.marginBottom||t.props.bottomMargin)&&(t.margin.bottom=t.props.marginBottom||t.props.bottomMargin),(t.props.marginLeft||t.props.leftMargin)&&(t.margin.left=t.props.marginLeft||t.props.leftMargin),t.totalWidth=t.props.width||500,t.totalHeight=t.props.height||500,t.width=t.totalWidth-t.margin.left-t.margin.right,t.height=t.totalHeight-t.margin.top-t.margin.bottom,t.id=e.id||t._id(),t.data=e.data?e.data:[],t._props=p({},e),delete t._props.data,delete t._props.chart,t.create=t.create.bind(d(t)),t.destroy=t.destroy.bind(d(t)),t._id=t._id.bind(d(t)),t._props.id=t._id(),t}return e=u,(r=[{key:"create",value:function(t){throw new TypeError("Children of D3Chart must have a create method")}},{key:"update",value:function(){throw new TypeError("Children of D3Chart must have an update method")}},{key:"destroy",value:function(){this.svg&&this.svg.remove()}},{key:"_id",value:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return"id_"+("x"==t?e:3&e|8).toString(16)}))}},{key:"componentDidMount",value:function(){this.create(this.canvas,this.data,this.props)}},{key:"shouldComponentUpdate",value:function(t,e){return this.data!==t.data&&(this.data=t.data,this.update(this.data)),!1}},{key:"componentWillUnmount",value:function(){this.destroy()}},{key:"_setRef",value:function(t){this.canvas=t}},{key:"render",value:function(){return n().createElement("div",{id:this.id,ref:this._setRef.bind(this),style:{width:this.width,height:this.height},className:"d3-canvas",role:"application"})}}])&&f(e.prototype,r),u}(n().Component)}},e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={exports:{}};return t[o](n,n.exports,r),n.exports}return r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r(179)})()}));