(function() { var callWithJQuery; callWithJQuery = function(pivotModule) { if (typeof exports === "object" && typeof module === "object") { return pivotModule(require("jquery"), require("plotly.js")); } else if (typeof define === "function" && define.amd) { return define(["jquery", "plotly.js"], pivotModule); } else { return pivotModule(jQuery, Plotly); } }; callWithJQuery(function($, Plotly) { var makePlotlyChart, makePlotlyScatterChart; makePlotlyChart = function(traceOptions, layoutOptions, transpose) { if (traceOptions == null) { traceOptions = {}; } if (layoutOptions == null) { layoutOptions = {}; } if (transpose == null) { transpose = false; } return function(pivotData, opts) { var colKeys, columns, d, data, datumKeys, defaults, fullAggName, groupByTitle, hAxisTitle, i, layout, result, rowKeys, rows, titleText, traceKeys; defaults = { localeStrings: { vs: "vs", by: "by" }, plotly: {}, plotlyConfig: {} }; opts = $.extend(true, {}, defaults, opts); rowKeys = pivotData.getRowKeys(); colKeys = pivotData.getColKeys(); traceKeys = transpose ? colKeys : rowKeys; if (traceKeys.length === 0) { traceKeys.push([]); } datumKeys = transpose ? rowKeys : colKeys; if (datumKeys.length === 0) { datumKeys.push([]); } fullAggName = pivotData.aggregatorName; if (pivotData.valAttrs.length) { fullAggName += "(" + (pivotData.valAttrs.join(", ")) + ")"; } data = traceKeys.map(function(traceKey) { var datumKey, j, labels, len, trace, val, values; values = []; labels = []; for (j = 0, len = datumKeys.length; j < len; j++) { datumKey = datumKeys[j]; val = parseFloat(pivotData.getAggregator(transpose ? datumKey : traceKey, transpose ? traceKey : datumKey).value()); values.push(isFinite(val) ? val : null); labels.push(datumKey.join('-') || ' '); } trace = { name: traceKey.join('-') || fullAggName }; if (traceOptions.type === "pie") { trace.values = values; trace.labels = labels.length > 1 ? labels : [fullAggName]; } else { trace.x = transpose ? values : labels; trace.y = transpose ? labels : values; } return $.extend(trace, traceOptions); }); if (transpose) { hAxisTitle = pivotData.rowAttrs.join("-"); groupByTitle = pivotData.colAttrs.join("-"); } else { hAxisTitle = pivotData.colAttrs.join("-"); groupByTitle = pivotData.rowAttrs.join("-"); } titleText = fullAggName; if (hAxisTitle !== "") { titleText += " " + opts.localeStrings.vs + " " + hAxisTitle; } if (groupByTitle !== "") { titleText += " " + opts.localeStrings.by + " " + groupByTitle; } layout = { title: titleText, hovermode: 'closest', width: window.innerWidth / 1.4, height: window.innerHeight / 1.4 - 50 }; if (traceOptions.type === 'pie') { columns = Math.ceil(Math.sqrt(data.length)); rows = Math.ceil(data.length / columns); layout.grid = { columns: columns, rows: rows }; for (i in data) { d = data[i]; d.domain = { row: Math.floor(i / columns), column: i - columns * Math.floor(i / columns) }; if (data.length > 1) { d.title = d.name; } } if (data[0].labels.length === 1) { layout.showlegend = false; } } else { layout.xaxis = { title: transpose ? fullAggName : null, automargin: true }; layout.yaxis = { title: transpose ? null : fullAggName, automargin: true }; } result = $("