+eval("{var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [\n __webpack_require__(/*! jquery */ \"./node_modules/jquery/dist/jquery.js\"),\n __webpack_require__(/*! underscore */ \"./node_modules/underscore/modules/index-all.js\"),\n __webpack_require__(/*! plotly.js-dist */ \"./node_modules/plotly.js-dist/plotly.js\"),\n __webpack_require__(/*! api/SplunkVisualizationBase */ \"api/SplunkVisualizationBase\"),\n __webpack_require__(/*! api/SplunkVisualizationUtils */ \"api/SplunkVisualizationUtils\")\n // Add required assets to this list\n], __WEBPACK_AMD_DEFINE_RESULT__ = (function (\n $,\n _,\n Plotly,\n SplunkVisualizationBase,\n SplunkVisualizationUtils\n) {\n\n var MAX_MARKER_SZ = 50;\n var isDarkTheme = SplunkVisualizationUtils.getCurrentTheme &&\n SplunkVisualizationUtils.getCurrentTheme() === 'dark';\n\n return SplunkVisualizationBase.extend({\n\n initialize: function() {\n // Save this.$el for convenience\n this.$el = $(this.el);\n\n // Handle multiple Graphs\n this.__uniqueID = Math.floor(Math.random() * 100000);\n\n // Add a css selector class\n this.$el.attr('id', 'scatterplot3dContainer_' + this.__uniqueID);\n },\n\n getInitialDataParams: function() {\n return ({\n outputMode: SplunkVisualizationBase.ROW_MAJOR_OUTPUT_MODE,\n count: 50000\n });\n },\n\n formatData: function(data, config) {\n // Expects to have 4 columns corresponding to 4 fields:\n // (0) trace_name\n // (1) x_value\n // (2) y_value\n // (3) z_value\n // (4) (optional) marker_size\n\n var fields = data.fields;\n var rows = data.rows;\n var idxMarkerSize = -1;\n\n //This returns nothing if there is no data passed in\n if (rows.length < 1) {\n return;\n }\n\n // Extra customisation fields given\n if (fields.length > 4) {\n idxMarkerSize = 4;\n }\n\n //This checks if all data being passed in are numbers and displays an error if not.\n if (_.isNaN(data)) {\n throw new SplunkVisualizationBase.VisualizationError(\n 'This chart only supports numbers'\n );\n }\n\n var traces = rows.map(x => x[0])\n .filter(function(x, i, rows){\n return rows.indexOf(x) === i;\n });\n\n var tracesIds = Array.from({length: traces.length}, function(v, k){\n value = k+1;\n return value.toString();\n });\n\n var traceValues = [];\n var markerSizes = [];\n\n _.each(traces, function(groupid) {\n // get all objects with same groupid\n var arr = rows.filter(function(el){\n return el[0] === groupid;\n });\n // Collect all the x values\n traceValues.push(arr.map(x => x[1]));\n // Collect all the y values\n traceValues.push(arr.map(x => x[2]));\n // Collect all the z values\n traceValues.push(arr.map(x => x[3]));\n if (idxMarkerSize > 0) {\n // Collect all the marker sizes\n markerSizes.push(arr.map(x => x[idxMarkerSize]));\n }\n });\n\n // console.log(\"traceValues:\", traceValues);\n return {\n \"fields\": fields,\n \"content\": {\n \"ids\": tracesIds,\n \"labels\": traces,\n \"values\": traceValues,\n \"msizes\": markerSizes\n }\n }\n },\n\n updateView: function(data, config) {\n if (!data) {\n return;\n }\n // console.log(data);\n\n var dataset = data.content,\n tracesIds = dataset.ids, // e.g. [1,2,3,4,5]\n traces = dataset.labels,\n tracesValues = dataset.values,\n markersSizes = dataset.msizes;\n\n //get info from config\n var modeBar = SplunkVisualizationUtils.normalizeBoolean(\n this._getEscapedProperty('mbDisplay', config));\n var dispLegend = SplunkVisualizationUtils.normalizeBoolean(\n this._getEscapedProperty('showLegend', config));\n var xTickAngle = this._getEscapedProperty('xAngle', config) || 0;\n var yTickAngle = this._getEscapedProperty('yAngle', config) || 0;\n var zTickAngle = this._getEscapedProperty('zAngle', config) || 0;\n var xAxisLabel = this._getEscapedProperty('xAxisName', config) || \"x\";\n var yAxisLabel = this._getEscapedProperty('yAxisName', config) || \"y\";\n var zAxisLabel = this._getEscapedProperty('zAxisName', config) || \"z\";\n\n // Cleanup previous data\n Plotly.purge('scatterplot3dContainer_' + this.__uniqueID);\n $('#' + this.id).empty();\n\n // create a trace for every group of data\n let dataInput = tracesIds.map((v, i, a) => {\n return {\n x: tracesValues[i],\n y: tracesValues[i+1],\n z: tracesValues[i+2],\n type: 'scatter3d',\n mode: 'markers',\n name: traces[i],\n marker: {\n size: this._normalizeMarkerSize(markersSizes[i]),\n opacity: 0.8,\n }\n };\n });\n // console.log(dataInput);\n\n // this block sets the prerequisites to display the chart\n var layout = {\n showlegend: dispLegend,\n autosize: true,\n margin: {\n t: 50\n },\n // outside background\n paper_bgcolor: isDarkTheme ? \"transparent\" : \"#fff\",\n font: {\n color: isDarkTheme ? '#DCDCDC' : '#444',\n },\n legend: {\n bgcolor: isDarkTheme ? '#212527' : '#fff',\n // move legend above the chart\n orientation: \"h\",\n y: 1.1, // 1.0 is top of the plot\n x: 0.5, // 1.0 is fully right, 0.5 is center\n xanchor: \"center\", // anchor point relative to x\n yanchor: \"bottom\" // anchor point relative to y\n },\n scene: {\n bgcolor: isDarkTheme ? \"transparent\" : \"#fff\",\n xaxis: {\n autorange: true,\n tickangle: xTickAngle,\n title: {\n text: xAxisLabel\n },\n gridcolor: isDarkTheme ? \"#A6A6A6\" : \"#eee\"\n },\n yaxis: {\n autorange: true,\n tickangle: yTickAngle,\n gridcolor: isDarkTheme ? \"#A6A6A6\" : \"#eee\",\n title: {\n text: yAxisLabel\n }\n },\n zaxis: {\n autorange: true,\n tickangle: zTickAngle,\n gridcolor: isDarkTheme ? \"#A6A6A6\" : \"#eee\",\n title: {\n text: zAxisLabel\n }\n }\n }\n };\n\n // Plotting the chart\n // full options at: https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js\n Plotly.newPlot('scatterplot3dContainer_' + this.__uniqueID, dataInput, layout, {\n displayModeBar: modeBar,\n responsive: true,\n displaylogo: false\n });\n\n },\n\n // Normalize Marker Size. Supported range is 1-50 pixels.\n _normalizeMarkerSize: function (size) {\n if (size < 1) { return 1; }\n if (size > MAX_MARKER_SZ) { return MAX_MARKER_SZ; }\n return size;\n },\n\n _getEscapedProperty: function(name, config) {\n var propertyValue = config[this.getPropertyNamespaceInfo().propertyNamespace + name];\n if (propertyValue !== undefined ) propertyValue = propertyValue.replace(/\"/g, '');\n return SplunkVisualizationUtils.escapeHtml(propertyValue);\n }\n\n });\n}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),\n\t\t__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));\n\n\n//# sourceURL=webpack://scatterplot3d/./src/visualization_source.js?\n}");
0 commit comments