http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/advanced-transformation-util.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/advanced-transformation-util.js b/zeppelin-web/src/app/tabledata/advanced-transformation-util.js index 0bcefb6..0d1c2f6 100644 --- a/zeppelin-web/src/app/tabledata/advanced-transformation-util.js +++ b/zeppelin-web/src/app/tabledata/advanced-transformation-util.js @@ -13,7 +13,7 @@ */ export function getCurrentChart(config) { - return config.chart.current; + return config.chart.current } export function getCurrentChartTransform(config) { @@ -43,7 +43,7 @@ export function useSharedAxis(config, chart) { export function serializeSharedAxes(config) { const availableCharts = getAvailableChartNames(config.spec.charts) for (let i = 0; i < availableCharts.length; i++) { - const chartName = availableCharts[i]; + const chartName = availableCharts[i] if (useSharedAxis(config, chartName)) { /** use reference :) in case of sharedAxis */ config.axis[chartName] = config.sharedAxis @@ -59,19 +59,19 @@ export const Widget = { } export function isInputWidget(paramSpec) { - return (paramSpec && !paramSpec.widget) || (paramSpec && paramSpec.widget === Widget.INPUT); + return (paramSpec && !paramSpec.widget) || (paramSpec && paramSpec.widget === Widget.INPUT) } export function isOptionWidget(paramSpec) { - return paramSpec && paramSpec.widget === Widget.OPTION; + return paramSpec && paramSpec.widget === Widget.OPTION } export function isCheckboxWidget(paramSpec) { - return paramSpec && paramSpec.widget === Widget.CHECKBOX; + return paramSpec && paramSpec.widget === Widget.CHECKBOX } export function isTextareaWidget(paramSpec) { - return paramSpec && paramSpec.widget === Widget.TEXTAREA; + return paramSpec && paramSpec.widget === Widget.TEXTAREA } export const ParameterValueType = { @@ -86,37 +86,29 @@ export function parseParameter(paramSpecs, param) { /** copy original params */ const parsed = JSON.parse(JSON.stringify(param)) - for (let i = 0 ; i < paramSpecs.length; i++) { + for (let i = 0; i < paramSpecs.length; i++) { const paramSpec = paramSpecs[i] const name = paramSpec.name if (paramSpec.valueType === ParameterValueType.INT && typeof parsed[name] !== 'number') { - - try { parsed[name] = parseInt(parsed[name]); } - catch (error) { parsed[name] = paramSpec.defaultValue; } - } - else if (paramSpec.valueType === ParameterValueType.FLOAT && + try { parsed[name] = parseInt(parsed[name]) } catch (error) { parsed[name] = paramSpec.defaultValue } + } else if (paramSpec.valueType === ParameterValueType.FLOAT && typeof parsed[name] !== 'number') { - - try { parsed[name] = parseFloat(parsed[name]); } - catch (error) { parsed[name] = paramSpec.defaultValue; } - } - else if (paramSpec.valueType === ParameterValueType.BOOLEAN) { + try { parsed[name] = parseFloat(parsed[name]) } catch (error) { parsed[name] = paramSpec.defaultValue } + } else if (paramSpec.valueType === ParameterValueType.BOOLEAN) { if (parsed[name] === 'false') { - parsed[name] = false; + parsed[name] = false } else if (parsed[name] === 'true') { - parsed[name] = true; + parsed[name] = true } else if (typeof parsed[name] !== 'boolean') { - parsed[name] = paramSpec.defaultValue; + parsed[name] = paramSpec.defaultValue } - } - else if (paramSpec.valueType === ParameterValueType.JSON) { + } else if (paramSpec.valueType === ParameterValueType.JSON) { if (parsed[name] !== null && typeof parsed[name] !== 'object') { - try { parsed[name] = JSON.parse(parsed[name]); } - catch (error) { parsed[name] = paramSpec.defaultValue; } + try { parsed[name] = JSON.parse(parsed[name]) } catch (error) { parsed[name] = paramSpec.defaultValue } } else if (parsed[name] === null) { - parsed[name] = paramSpec.defaultValue; + parsed[name] = paramSpec.defaultValue } } } @@ -150,12 +142,12 @@ export function isSingleDimensionAxis(axisSpec) { * add the `name` field while converting to array to easily manipulate */ export function getSpecs(specObject) { - const specs = []; + const specs = [] for (let name in specObject) { - const singleSpec = specObject[name]; + const singleSpec = specObject[name] if (!singleSpec) { continue } - singleSpec.name = name; - specs.push(singleSpec); + singleSpec.name = name + specs.push(singleSpec) } return specs @@ -163,7 +155,7 @@ export function getSpecs(specObject) { export function getAvailableChartNames(charts) { const available = [] - for (var name in charts) { + for (let name in charts) { available.push(name) } @@ -172,11 +164,11 @@ export function getAvailableChartNames(charts) { export function applyMaxAxisCount(config, axisSpec) { if (isSingleDimensionAxis(axisSpec) || typeof axisSpec.maxAxisCount === 'undefined') { - return; + return } const columns = getCurrentChartAxis(config)[axisSpec.name] - if (columns.length <= axisSpec.maxAxisCount) { return; } + if (columns.length <= axisSpec.maxAxisCount) { return } const sliced = columns.slice(1) getCurrentChartAxis(config)[axisSpec.name] = sliced @@ -213,23 +205,23 @@ export function initAxisConfig(config) { const spec = config.spec const availableCharts = getAvailableChartNames(spec.charts) - if (!config.axisSpecs) { config.axisSpecs = {}; } + if (!config.axisSpecs) { config.axisSpecs = {} } for (let i = 0; i < availableCharts.length; i++) { - const chartName = availableCharts[i]; + const chartName = availableCharts[i] if (!config.axis[chartName]) { - config.axis[chartName] = {}; + config.axis[chartName] = {} } const axisSpecs = getSpecs(spec.charts[chartName].axis) if (!config.axisSpecs[chartName]) { - config.axisSpecs[chartName] = axisSpecs; + config.axisSpecs[chartName] = axisSpecs } /** initialize multi-dimension axes */ for (let i = 0; i < axisSpecs.length; i++) { const axisSpec = axisSpecs[i] if (isSingleDimensionAxis(axisSpec)) { - continue; + continue } /** intentionally nested if-stmt is used because order of conditions matter here */ @@ -268,18 +260,18 @@ export function initParameterConfig(config) { const spec = config.spec const availableCharts = getAvailableChartNames(spec.charts) - if (!config.paramSpecs) { config.paramSpecs = {}; } + if (!config.paramSpecs) { config.paramSpecs = {} } for (let i = 0; i < availableCharts.length; i++) { - const chartName = availableCharts[i]; + const chartName = availableCharts[i] - if (!config.parameter[chartName]) { config.parameter[chartName] = {}; } + if (!config.parameter[chartName]) { config.parameter[chartName] = {} } const paramSpecs = getSpecs(spec.charts[chartName].parameter) - if (!config.paramSpecs[chartName]) { config.paramSpecs[chartName] = paramSpecs; } + if (!config.paramSpecs[chartName]) { config.paramSpecs[chartName] = paramSpecs } for (let i = 0; i < paramSpecs.length; i++) { - const paramSpec = paramSpecs[i]; + const paramSpec = paramSpecs[i] if (!config.parameter[chartName][paramSpec.name]) { - config.parameter[chartName][paramSpec.name] = paramSpec.defaultValue; + config.parameter[chartName][paramSpec.name] = paramSpec.defaultValue } } } @@ -295,7 +287,7 @@ export function getSpecVersion(availableCharts, spec) { const paramHash = {} for (let i = 0; i < availableCharts.length; i++) { - const chartName = availableCharts[i]; + const chartName = availableCharts[i] const axisSpecs = getSpecs(spec.charts[chartName].axis) axisHash[chartName] = axisSpecs @@ -318,7 +310,6 @@ export function initializeConfig(config, spec) { if (!config.spec || !config.spec.version || !config.spec.version.axis || config.spec.version.axis !== axisVersion) { - spec.initialized = true updated = true @@ -332,7 +323,6 @@ export function initializeConfig(config, spec) { if (!config.spec || !config.spec.version || !config.spec.version.parameter || config.spec.version.parameter !== paramVersion) { - updated = true clearParameterConfig(config) @@ -343,12 +333,12 @@ export function initializeConfig(config, spec) { spec.version.axis = axisVersion spec.version.parameter = paramVersion - if (!config.spec || updated) { config.spec = spec; } + if (!config.spec || updated) { config.spec = spec } if (!config.chart) { - config.chart = {}; - config.chart.current = availableCharts[0]; - config.chart.available = availableCharts; + config.chart = {} + config.chart.current = availableCharts[0] + config.chart.available = availableCharts } /** initialize config.axis, config.axisSpecs for each chart */ @@ -363,8 +353,8 @@ export function getColumnsForMultipleAxes(axisType, axisSpecs, axis) { const axisNames = [] let column = {} - for(let i = 0; i < axisSpecs.length; i++) { - const axisSpec = axisSpecs[i]; + for (let i = 0; i < axisSpecs.length; i++) { + const axisSpec = axisSpecs[i] if (axisType === AxisType.KEY && isKeyAxis(axisSpec)) { axisNames.push(axisSpec.name) @@ -375,8 +365,8 @@ export function getColumnsForMultipleAxes(axisType, axisSpecs, axis) { } } - for(let axisName of axisNames) { - const columns = axis[axisName]; + for (let axisName of axisNames) { + const columns = axis[axisName] if (typeof axis[axisName] === 'undefined') { continue } if (!column[axisName]) { column[axisName] = [] } column[axisName] = column[axisName].concat(columns) @@ -386,35 +376,39 @@ export function getColumnsForMultipleAxes(axisType, axisSpecs, axis) { } export function getColumnsFromAxis(axisSpecs, axis) { - const keyAxisNames = []; - const groupAxisNames = []; - const aggrAxisNames = []; - - for(let i = 0; i < axisSpecs.length; i++) { - const axisSpec = axisSpecs[i]; - - if (isKeyAxis(axisSpec)) { keyAxisNames.push(axisSpec.name); } - else if (isGroupAxis(axisSpec)) { groupAxisNames.push(axisSpec.name); } - else if (isAggregatorAxis(axisSpec)) { aggrAxisNames.push(axisSpec.name); } + const keyAxisNames = [] + const groupAxisNames = [] + const aggrAxisNames = [] + + for (let i = 0; i < axisSpecs.length; i++) { + const axisSpec = axisSpecs[i] + + if (isKeyAxis(axisSpec)) { + keyAxisNames.push(axisSpec.name) + } else if (isGroupAxis(axisSpec)) { + groupAxisNames.push(axisSpec.name) + } else if (isAggregatorAxis(axisSpec)) { + aggrAxisNames.push(axisSpec.name) + } } - let keyColumns = []; - let groupColumns = []; - let aggregatorColumns = []; - let customColumn = {}; + let keyColumns = [] + let groupColumns = [] + let aggregatorColumns = [] + let customColumn = {} - for(let axisName in axis) { - const columns = axis[axisName]; + for (let axisName in axis) { + const columns = axis[axisName] if (keyAxisNames.includes(axisName)) { - keyColumns = keyColumns.concat(columns); + keyColumns = keyColumns.concat(columns) } else if (groupAxisNames.includes(axisName)) { - groupColumns = groupColumns.concat(columns); + groupColumns = groupColumns.concat(columns) } else if (aggrAxisNames.includes(axisName)) { - aggregatorColumns = aggregatorColumns.concat(columns); + aggregatorColumns = aggregatorColumns.concat(columns) } else { const axisType = axisSpecs.filter(s => s.name === axisName)[0].axisType - if (!customColumn[axisType]) { customColumn[axisType] = []; } - customColumn[axisType] = customColumn[axisType].concat(columns); + if (!customColumn[axisType]) { customColumn[axisType] = [] } + customColumn[axisType] = customColumn[axisType].concat(columns) } } @@ -466,10 +460,10 @@ export function getTransformer(conf, rows, axisSpecs, axis) { const method = transformSpec.method - const columns = getColumnsFromAxis(axisSpecs, axis); - const keyColumns = columns.key; - const groupColumns = columns.group; - const aggregatorColumns = columns.aggregator; + const columns = getColumnsFromAxis(axisSpecs, axis) + const keyColumns = columns.key + const groupColumns = columns.group + const aggregatorColumns = columns.aggregator const customColumns = columns.custom let column = { @@ -477,10 +471,10 @@ export function getTransformer(conf, rows, axisSpecs, axis) { } if (method === TransformMethod.RAW) { - transformer = () => { return rows; } + transformer = () => { return rows } } else if (method === TransformMethod.OBJECT) { transformer = () => { - const { cube, schema, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex, } = + const { cube, schema, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex, } = getKGACube(rows, keyColumns, groupColumns, aggregatorColumns) const { @@ -489,7 +483,8 @@ export function getTransformer(conf, rows, axisSpecs, axis) { keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) return { - rows: transformed, keyColumnName, + rows: transformed, + keyColumnName, keyNames, groupNames: groupNames, selectors: sortedSelectors, @@ -506,7 +501,8 @@ export function getTransformer(conf, rows, axisSpecs, axis) { keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) return { - rows: transformed, keyColumnName, + rows: transformed, + keyColumnName, keyNames, groupNames: groupNames, selectors: sortedSelectors, @@ -524,8 +520,7 @@ export function getTransformer(conf, rows, axisSpecs, axis) { for (let axisName in keyAxisColumn) { if (i === 2) { break } - if (i === 0) { key1Columns = keyAxisColumn[axisName] } - else if (i === 1) { key2Columns = keyAxisColumn[axisName] } + if (i === 0) { key1Columns = keyAxisColumn[axisName] } else if (i === 1) { key2Columns = keyAxisColumn[axisName] } i++ } @@ -553,8 +548,7 @@ export function getTransformer(conf, rows, axisSpecs, axis) { selectors: sortedSelectors, } } - } - else if (method === TransformMethod.DRILL_DOWN) { + } else if (method === TransformMethod.DRILL_DOWN) { transformer = () => { const { cube, schema, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex, } = getKAGCube(rows, keyColumns, groupColumns, aggregatorColumns) @@ -565,7 +559,9 @@ export function getTransformer(conf, rows, axisSpecs, axis) { keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) return { - rows: transformed, keyColumnName, keyNames, + rows: transformed, + keyColumnName, + keyNames, groupNames: groupNames, selectors: sortedSelectors, } @@ -577,31 +573,31 @@ export function getTransformer(conf, rows, axisSpecs, axis) { const AggregatorFunctions = { sum: function(a, b) { - const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return varA + varB; + const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return varA + varB }, count: function(a, b) { - const varA = (a !== undefined) ? parseInt(a) : 0; - const varB = (b !== undefined) ? 1 : 0; - return varA + varB; + const varA = (a !== undefined) ? parseInt(a) : 0 + const varB = (b !== undefined) ? 1 : 0 + return varA + varB }, min: function(a, b) { - const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return Math.min(varA,varB); + const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return Math.min(varA, varB) }, max: function(a, b) { - const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return Math.max(varA,varB); + const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return Math.max(varA, varB) }, avg: function(a, b, c) { - const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return varA + varB; + const varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + const varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return varA + varB } -}; +} const AggregatorFunctionDiv = { sum: false, @@ -609,7 +605,7 @@ const AggregatorFunctionDiv = { max: false, count: false, avg: true -}; +} /** nested cube `(key) -> (group) -> aggregator` */ export function getKGACube(rows, keyColumns, groupColumns, aggrColumns) { @@ -617,7 +613,7 @@ export function getKGACube(rows, keyColumns, groupColumns, aggrColumns) { key: keyColumns.length !== 0, group: groupColumns.length !== 0, aggregator: aggrColumns.length !== 0, - }; + } let cube = {} const entry = {} @@ -629,12 +625,12 @@ export function getKGACube(rows, keyColumns, groupColumns, aggrColumns) { let indexCounter = 0 for (let i = 0; i < rows.length; i++) { - const row = rows[i]; - let e = entry; - let c = cube; + const row = rows[i] + let e = entry + let c = cube // key: add to entry - let mergedKeyName = undefined + let mergedKeyName if (schema.key) { mergedKeyName = keyColumns.map(c => row[c.index]).join('.') if (!e[mergedKeyName]) { e[mergedKeyName] = { children: {}, } } @@ -646,7 +642,7 @@ export function getKGACube(rows, keyColumns, groupColumns, aggrColumns) { keyNameSet.add(mergedKeyName) } - let mergedGroupName = undefined + let mergedGroupName if (schema.group) { mergedGroupName = groupColumns.map(c => row[c.index]).join('.') @@ -690,13 +686,12 @@ export function getKGACube(rows, keyColumns, groupColumns, aggrColumns) { } else { const value = AggregatorFunctions[aggrColumn.aggr]( c[aggrName].value, row[aggrColumn.index], c[aggrName].count + 1) - const count = (AggregatorFunctionDiv[aggrColumn.aggr]) ? - c[aggrName].count + 1 : c[aggrName].count + const count = (AggregatorFunctionDiv[aggrColumn.aggr]) + ? c[aggrName].count + 1 : c[aggrName].count c[aggrName].value = value c[aggrName].count = count } - } /** end loop for aggrColumns */ } @@ -725,7 +720,7 @@ export function getKAGCube(rows, keyColumns, groupColumns, aggrColumns) { key: keyColumns.length !== 0, group: groupColumns.length !== 0, aggregator: aggrColumns.length !== 0, - }; + } let cube = {} @@ -736,11 +731,11 @@ export function getKAGCube(rows, keyColumns, groupColumns, aggrColumns) { let indexCounter = 0 for (let i = 0; i < rows.length; i++) { - const row = rows[i]; - let c = cube; + const row = rows[i] + let c = cube // key: add to entry - let mergedKeyName = undefined + let mergedKeyName if (schema.key) { mergedKeyName = keyColumns.map(c => row[c.index]).join('.') // key: add to row @@ -750,7 +745,7 @@ export function getKAGCube(rows, keyColumns, groupColumns, aggrColumns) { keyNameSet.add(mergedKeyName) } - let mergedGroupName = undefined + let mergedGroupName if (schema.group) { mergedGroupName = groupColumns.map(c => row[c.index]).join('.') groupNameSet.add(mergedGroupName) @@ -781,8 +776,8 @@ export function getKAGCube(rows, keyColumns, groupColumns, aggrColumns) { } else { const value = AggregatorFunctions[aggrColumn.aggr]( c[aggrName].value, row[aggrColumn.index], c[aggrName].count + 1) - const count = (AggregatorFunctionDiv[aggrColumn.aggr]) ? - c[aggrName].count + 1 : c[aggrName].count + const count = (AggregatorFunctionDiv[aggrColumn.aggr]) + ? c[aggrName].count + 1 : c[aggrName].count c[aggrName].value = value c[aggrName].count = count @@ -800,15 +795,13 @@ export function getKAGCube(rows, keyColumns, groupColumns, aggrColumns) { const drillDownedCount = c[aggrName].children[mergedGroupName].count const value = AggregatorFunctions[aggrColumn.aggr]( drillDownedValue, row[aggrColumn.index], drillDownedCount + 1) - const count = (AggregatorFunctionDiv[aggrColumn.aggr]) ? - drillDownedCount + 1 : drillDownedCount + const count = (AggregatorFunctionDiv[aggrColumn.aggr]) + ? drillDownedCount + 1 : drillDownedCount c[aggrName].children[mergedGroupName].value = value c[aggrName].children[mergedGroupName].count = count } - } - } /** end loop for aggrColumns */ } @@ -837,7 +830,7 @@ export function getKKGACube(rows, key1Columns, key2Columns, groupColumns, aggrCo key2: key2Columns.length !== 0, group: groupColumns.length !== 0, aggregator: aggrColumns.length !== 0, - }; + } let cube = {} const entry = {} @@ -851,12 +844,12 @@ export function getKKGACube(rows, key1Columns, key2Columns, groupColumns, aggrCo let indexCounter = 0 for (let i = 0; i < rows.length; i++) { - const row = rows[i]; - let e = entry; - let c = cube; + const row = rows[i] + let e = entry + let c = cube // key1: add to entry - let mergedKey1Name = undefined + let mergedKey1Name if (schema.key1) { mergedKey1Name = key1Columns.map(c => row[c.index]).join('.') if (!e[mergedKey1Name]) { e[mergedKey1Name] = { children: {}, } } @@ -869,7 +862,7 @@ export function getKKGACube(rows, key1Columns, key2Columns, groupColumns, aggrCo } // key2: add to entry - let mergedKey2Name = undefined + let mergedKey2Name if (schema.key2) { mergedKey2Name = key2Columns.map(c => row[c.index]).join('.') if (!e[mergedKey2Name]) { e[mergedKey2Name] = { children: {}, } } @@ -881,7 +874,7 @@ export function getKKGACube(rows, key1Columns, key2Columns, groupColumns, aggrCo if (!key2NameSet[mergedKey2Name]) { key2NameSet[mergedKey2Name] = true } } - let mergedGroupName = undefined + let mergedGroupName if (schema.group) { mergedGroupName = groupColumns.map(c => row[c.index]).join('.') @@ -925,13 +918,12 @@ export function getKKGACube(rows, key1Columns, key2Columns, groupColumns, aggrCo } else { const value = AggregatorFunctions[aggrColumn.aggr]( c[aggrName].value, row[aggrColumn.index], c[aggrName].count + 1) - const count = (AggregatorFunctionDiv[aggrColumn.aggr]) ? - c[aggrName].count + 1 : c[aggrName].count + const count = (AggregatorFunctionDiv[aggrColumn.aggr]) + ? c[aggrName].count + 1 : c[aggrName].count c[aggrName].value = value c[aggrName].count = count } - } /** end loop for aggrColumns */ } @@ -954,8 +946,8 @@ export function getSelectorName(mergedGroupName, aggrColumnLength, aggrColumnNam if (!mergedGroupName) { return aggrColumnName } else { - return (aggrColumnLength > 1) ? - `${mergedGroupName} / ${aggrColumnName}` : mergedGroupName + return (aggrColumnLength > 1) + ? `${mergedGroupName} / ${aggrColumnName}` : mergedGroupName } } @@ -990,7 +982,6 @@ export function getNameWithIndex(names) { export function getArrayRowsFromKKGACube(cube, schema, aggregatorColumns, key1Names, key2Names, groupNameSet, selectorNameWithIndex) { - const sortedSelectors = Object.keys(selectorNameWithIndex).sort() const sortedSelectorNameWithIndex = getNameWithIndex(sortedSelectors) @@ -1015,7 +1006,6 @@ export function getArrayRowsFromKKGACube(cube, schema, aggregatorColumns, export function fillSelectorRows(schema, cube, selectorRows, aggrColumns, selectorNameWithIndex, key1Names, key2Names) { - function fill(grouped, mergedGroupName, key1Name, key2Name) { // should iterate aggrColumns in the most nested loop to utilize memory locality for (let aggrColumn of aggrColumns) { @@ -1083,14 +1073,13 @@ export function fillSelectorRows(schema, cube, selectorRows, export function getArrayRowsFromKGACube(cube, schema, aggregatorColumns, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) { - const sortedSelectors = Object.keys(selectorNameWithIndex).sort() const sortedSelectorNameWithIndex = getNameWithIndex(sortedSelectors) const keyArrowRows = new Array(sortedSelectors.length) const keyNameWithIndex = getNameWithIndex(keyNames) - for(let i = 0; i < keyNames.length; i++) { + for (let i = 0; i < keyNames.length; i++) { const key = keyNames[i] const obj = cube[key] @@ -1110,7 +1099,6 @@ export function getArrayRowsFromKGACube(cube, schema, aggregatorColumns, export function fillArrayRow(schema, aggrColumns, obj, groupNameSet, selectorNameWithIndex, keyName, keyNames, keyArrayRows, keyNameWithIndex) { - function fill(target, mergedGroupName, aggr, aggrName) { const value = getCubeValue(target, aggr, aggrName) const selector = getSelectorName(mergedGroupName, aggrColumns.length, aggrName) @@ -1127,13 +1115,13 @@ export function fillArrayRow(schema, aggrColumns, obj, /** when group is empty */ if (!schema.group) { - for(let i = 0; i < aggrColumns.length; i++) { + for (let i = 0; i < aggrColumns.length; i++) { const aggrColumn = aggrColumns[i] const aggrName = `${aggrColumn.name}(${aggrColumn.aggr})` fill(obj, undefined, aggrColumn.aggr, aggrName) } } else { - for(let i = 0; i < aggrColumns.length; i++) { + for (let i = 0; i < aggrColumns.length; i++) { const aggrColumn = aggrColumns[i] const aggrName = `${aggrColumn.name}(${aggrColumn.aggr})` @@ -1148,7 +1136,6 @@ export function fillArrayRow(schema, aggrColumns, obj, export function getObjectRowsFromKGACube(cube, schema, aggregatorColumns, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) { - const rows = keyNames.reduce((acc, key) => { const obj = cube[key] const row = getObjectRow(schema, aggregatorColumns, obj, groupNameSet) @@ -1177,7 +1164,7 @@ export function getObjectRow(schema, aggrColumns, obj, groupNameSet) { /** when group is empty */ if (!schema.group) { - for(let i = 0; i < aggrColumns.length; i++) { + for (let i = 0; i < aggrColumns.length; i++) { const aggrColumn = aggrColumns[i] const aggrName = `${aggrColumn.name}(${aggrColumn.aggr})` @@ -1188,7 +1175,7 @@ export function getObjectRow(schema, aggrColumns, obj, groupNameSet) { } /** when group is specified */ - for(let i = 0; i < aggrColumns.length; i++) { + for (let i = 0; i < aggrColumns.length; i++) { const aggrColumn = aggrColumns[i] const aggrName = `${aggrColumn.name}(${aggrColumn.aggr})` @@ -1206,7 +1193,6 @@ export function getObjectRow(schema, aggrColumns, obj, groupNameSet) { export function getDrilldownRowsFromKAGCube(cube, schema, aggregatorColumns, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) { - const sortedSelectors = Object.keys(selectorNameWithIndex).sort() const sortedSelectorNameWithIndex = getNameWithIndex(sortedSelectors) @@ -1232,7 +1218,7 @@ export function getDrilldownRowsFromKAGCube(cube, schema, aggregatorColumns, export function fillDrillDownRow(schema, obj, rows, key, selectorNameWithIndex, aggrColumns, groupNames) { /** when group is empty */ - for(let i = 0; i < aggrColumns.length; i++) { + for (let i = 0; i < aggrColumns.length; i++) { const row = {} const aggrColumn = aggrColumns[i] const aggrName = `${aggrColumn.name}(${aggrColumn.aggr})` @@ -1248,7 +1234,7 @@ export function fillDrillDownRow(schema, obj, rows, key, if (schema.group) { row.drillDown = [] - for(let groupName of groupNames) { + for (let groupName of groupNames) { const value = getCubeValue(obj[aggrName].children, aggrColumn.aggr, groupName) row.drillDown.push({ group: groupName, value: value, }) }
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js b/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js index 6fde659..90f569f 100644 --- a/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js +++ b/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js @@ -50,7 +50,6 @@ const MockAxis4 = { 'groupAxis': { dimension: 'multiple', axisType: 'group', }, } - // test spec for axis, param, widget const MockSpec = { charts: { @@ -138,23 +137,23 @@ const MockSpec2 = { /* eslint-disable max-len */ const MockTableDataColumn = [ - {'name': 'age', 'index': 0, 'aggr': 'sum',}, - {'name': 'job', 'index': 1, 'aggr': 'sum',}, - {'name': 'marital', 'index': 2, 'aggr': 'sum',}, - {'name': 'education', 'index': 3, 'aggr': 'sum',}, - {'name': 'default', 'index': 4, 'aggr': 'sum',}, - {'name': 'balance', 'index': 5, 'aggr': 'sum',}, - {'name': 'housing', 'index': 6, 'aggr': 'sum',}, - {'name': 'loan', 'index': 7, 'aggr': 'sum',}, - {'name': 'contact', 'index': 8, 'aggr': 'sum',}, - {'name': 'day', 'index': 9, 'aggr': 'sum',}, - {'name': 'month', 'index': 10, 'aggr': 'sum',}, - {'name': 'duration', 'index': 11, 'aggr': 'sum',}, - {'name': 'campaign', 'index': 12, 'aggr': 'sum',}, - {'name': 'pdays', 'index': 13, 'aggr': 'sum',}, - {'name': 'previous', 'index': 14, 'aggr': 'sum',}, - {'name': 'poutcome', 'index': 15, 'aggr': 'sum',}, - {'name': 'y', 'index': 16, 'aggr': 'sum',} + {'name': 'age', 'index': 0, 'aggr': 'sum', }, + {'name': 'job', 'index': 1, 'aggr': 'sum', }, + {'name': 'marital', 'index': 2, 'aggr': 'sum', }, + {'name': 'education', 'index': 3, 'aggr': 'sum', }, + {'name': 'default', 'index': 4, 'aggr': 'sum', }, + {'name': 'balance', 'index': 5, 'aggr': 'sum', }, + {'name': 'housing', 'index': 6, 'aggr': 'sum', }, + {'name': 'loan', 'index': 7, 'aggr': 'sum', }, + {'name': 'contact', 'index': 8, 'aggr': 'sum', }, + {'name': 'day', 'index': 9, 'aggr': 'sum', }, + {'name': 'month', 'index': 10, 'aggr': 'sum', }, + {'name': 'duration', 'index': 11, 'aggr': 'sum', }, + {'name': 'campaign', 'index': 12, 'aggr': 'sum', }, + {'name': 'pdays', 'index': 13, 'aggr': 'sum', }, + {'name': 'previous', 'index': 14, 'aggr': 'sum', }, + {'name': 'poutcome', 'index': 15, 'aggr': 'sum', }, + {'name': 'y', 'index': 16, 'aggr': 'sum', } ] const MockTableDataRows1 = [ @@ -169,7 +168,7 @@ const MockTableDataRows1 = [ describe('advanced-transformation-util', () => { describe('getCurrent* funcs', () => { it('should set return proper value of the current chart', () => { - const config = {} + const config = {} const spec = JSON.parse(JSON.stringify(MockSpec)) Util.initializeConfig(config, spec) expect(Util.getCurrentChart(config)).toEqual('object-chart') @@ -183,7 +182,7 @@ describe('advanced-transformation-util', () => { describe('useSharedAxis', () => { it('should set chartChanged for initial drawing', () => { - const config = {} + const config = {} const spec = JSON.parse(JSON.stringify(MockSpec)) Util.initializeConfig(config, spec) expect(Util.useSharedAxis(config, 'object-chart')).toEqual(true) @@ -194,7 +193,7 @@ describe('advanced-transformation-util', () => { }) describe('initializeConfig', () => { - const config = {} + const config = {} const spec = JSON.parse(JSON.stringify(MockSpec)) Util.initializeConfig(config, spec) @@ -269,7 +268,6 @@ describe('advanced-transformation-util', () => { // it's ok not to set single dimension axis expect(config.axis['raw-chart']).toEqual({ customAxis2: [], }) }) - }) describe('axis', () => { @@ -354,7 +352,6 @@ describe('advanced-transformation-util', () => { expect(typeof parsed.stringParam).toBe('string') expect(parsed.stringParam).toBe('example') }) - }) describe('removeDuplicatedColumnsInMultiDimensionAxis', () => { @@ -472,7 +469,6 @@ describe('advanced-transformation-util', () => { // it's hard to test all methods for transformation. // so let's do behavioral (black-box) test instead of describe('getTransformer', () => { - describe('method: raw', () => { let config = {} const spec = JSON.parse(JSON.stringify(MockSpec2)) @@ -935,8 +931,8 @@ describe('advanced-transformation-util', () => { expect(groupNames).toEqual([ 'age(sum)', ]) expect(selectors).toEqual([ 'age(sum)', ]) expect(rows).toEqual([ - { 'age(sum)': 82, marital: 'married', }, - { 'age(sum)': 77, marital: 'single', }, + { 'age(sum)': 82, 'marital': 'married', }, + { 'age(sum)': 77, 'marital': 'single', }, ]) }) @@ -1021,7 +1017,7 @@ describe('advanced-transformation-util', () => { expect(groupNames).toEqual([ 'age(sum)', ]) expect(selectors).toEqual([ 'age(sum)', ]) expect(rows).toEqual([ - { selector: 'age(sum)', value: 44 + 43 + 39 + 33, drillDown: [ ], }, + { selector: 'age(sum)', value: 44 + 43 + 39 + 33, drillDown: [ ], }, ]) }) @@ -1035,7 +1031,7 @@ describe('advanced-transformation-util', () => { const { rows, } = transformer() expect(rows).toEqual([ - { selector: 'age(count)', value: 4, drillDown: [ ], }, + { selector: 'age(count)', value: 4, drillDown: [ ], }, ]) }) @@ -1049,7 +1045,7 @@ describe('advanced-transformation-util', () => { const { rows, } = transformer() expect(rows).toEqual([ - { selector: 'age(avg)', value: (44 + 43 + 39 + 33) / 4.0, drillDown: [ ], }, + { selector: 'age(avg)', value: (44 + 43 + 39 + 33) / 4.0, drillDown: [ ], }, ]) }) @@ -1063,7 +1059,7 @@ describe('advanced-transformation-util', () => { const { rows, } = transformer() expect(rows).toEqual([ - { selector: 'age(max)', value: 44, drillDown: [ ], }, + { selector: 'age(max)', value: 44, drillDown: [ ], }, ]) }) @@ -1077,7 +1073,7 @@ describe('advanced-transformation-util', () => { const { rows, } = transformer() expect(rows).toEqual([ - { selector: 'age(min)', value: 33, drillDown: [ ], }, + { selector: 'age(min)', value: 33, drillDown: [ ], }, ]) }) @@ -1098,8 +1094,8 @@ describe('advanced-transformation-util', () => { expect(groupNames).toEqual([ 'age(sum)', 'balance(sum)', ]) expect(selectors).toEqual([ 'age(sum)', 'balance(sum)', ]) expect(rows).toEqual([ - { selector: 'age(sum)', value: 159, drillDown: [ ], }, - { selector: 'balance(sum)', value: 14181, drillDown: [ ], }, + { selector: 'age(sum)', value: 159, drillDown: [ ], }, + { selector: 'balance(sum)', value: 14181, drillDown: [ ], }, ]) }) @@ -1212,8 +1208,8 @@ describe('advanced-transformation-util', () => { expect(groupNames).toEqual([ 'age(sum)', ]) expect(selectors).toEqual([ 'married', 'single', ]) expect(rows).toEqual([ - { selector: 'married', value: 82, drillDown: [ ], }, - { selector: 'single', value: 77, drillDown: [ ], }, + { selector: 'married', value: 82, drillDown: [ ], }, + { selector: 'single', value: 77, drillDown: [ ], }, ]) }) @@ -1234,9 +1230,9 @@ describe('advanced-transformation-util', () => { expect(groupNames).toEqual([ 'age(sum)', ]) expect(selectors).toEqual([ 'married.primary', 'married.secondary', 'single.tertiary', ]) expect(rows).toEqual([ - { selector: 'married.primary', value: '43', drillDown: [ ], }, - { selector: 'married.secondary', value: '39', drillDown: [ ], }, - { selector: 'single.tertiary', value: 77, drillDown: [ ], }, + { selector: 'married.primary', value: '43', drillDown: [ ], }, + { selector: 'married.secondary', value: '39', drillDown: [ ], }, + { selector: 'single.tertiary', value: 77, drillDown: [ ], }, ]) }) @@ -1738,9 +1734,6 @@ describe('advanced-transformation-util', () => { }, ]) }) - }) // end: describe('method: array:2-key') - }) // end: describe('getTransformer') }) - http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/advanced-transformation.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/advanced-transformation.js b/zeppelin-web/src/app/tabledata/advanced-transformation.js index d754f4d..051bb99 100644 --- a/zeppelin-web/src/app/tabledata/advanced-transformation.js +++ b/zeppelin-web/src/app/tabledata/advanced-transformation.js @@ -12,7 +12,7 @@ * limitations under the License. */ -import Transformation from './transformation'; +import Transformation from './transformation' import { getCurrentChart, getCurrentChartAxis, getCurrentChartParam, @@ -23,19 +23,19 @@ import { removeDuplicatedColumnsInMultiDimensionAxis, applyMaxAxisCount, isInputWidget, isOptionWidget, isCheckboxWidget, isTextareaWidget, parseParameter, getTransformer, -} from './advanced-transformation-util'; +} from './advanced-transformation-util' -const SETTING_TEMPLATE = 'app/tabledata/advanced-transformation-setting.html'; +const SETTING_TEMPLATE = 'app/tabledata/advanced-transformation-setting.html' export default class AdvancedTransformation extends Transformation { constructor(config, spec) { - super(config); + super(config) - this.columns = []; /** [{ name, index, comment }] */ - this.props = {}; + this.columns = [] /** [{ name, index, comment }] */ + this.props = {} this.spec = spec - initializeConfig(config, spec); + initializeConfig(config, spec) } emitConfigChange(conf) { @@ -57,8 +57,8 @@ export default class AdvancedTransformation extends Transformation { } getSetting() { - const self = this; /** for closure */ - const configInstance = self.config; /** for closure */ + const self = this /** for closure */ + const configInstance = self.config /** for closure */ if (self.spec.initialized) { self.spec.initialized = false @@ -111,7 +111,7 @@ export default class AdvancedTransformation extends Transformation { let comment = '' if (minAxisCount) { comment = `min: ${minAxisCount}` } - if (minAxisCount && maxAxisCount) { comment = `${comment}, `} + if (minAxisCount && maxAxisCount) { comment = `${comment}, ` } if (maxAxisCount) { comment = `${comment}max: ${maxAxisCount}` } if (comment !== '') { @@ -123,13 +123,13 @@ export default class AdvancedTransformation extends Transformation { getAxisTypeAnnotationColor: (axisSpec) => { if (isAggregatorAxis(axisSpec)) { - return { 'background-color': '#5782bd' }; + return { 'background-color': '#5782bd' } } else if (isGroupAxis(axisSpec)) { - return { 'background-color': '#cd5c5c' }; + return { 'background-color': '#cd5c5c' } } else if (isKeyAxis(axisSpec)) { - return { 'background-color': '#906ebd' }; + return { 'background-color': '#906ebd' } } else { - return { 'background-color': '#62bda9' }; + return { 'background-color': '#62bda9' } } }, @@ -179,14 +179,13 @@ export default class AdvancedTransformation extends Transformation { isTextareaWidget: function(paramSpec) { return isTextareaWidget(paramSpec) }, parameterChanged: (paramSpec) => { - configInstance.chartChanged = false configInstance.parameterChanged = true self.emitParameterChange(configInstance) }, parameterOnKeyDown: function(event, paramSpec) { - const code = event.keyCode || event.which; + const code = event.keyCode || event.which if (code === 13 && isInputWidget(paramSpec)) { self.emitParameterChange(configInstance) } else if (code === 13 && event.shiftKey && isTextareaWidget(paramSpec)) { @@ -201,7 +200,7 @@ export default class AdvancedTransformation extends Transformation { } transform(tableData) { - this.columns = tableData.columns; /** used in `getSetting` */ + this.columns = tableData.columns /** used in `getSetting` */ /** initialize in `transform` instead of `getSetting` because this method is called before */ serializeSharedAxes(this.config) @@ -213,7 +212,7 @@ export default class AdvancedTransformation extends Transformation { const paramSpecs = getCurrentChartParamSpecs(conf) const parsedParam = parseParameter(paramSpecs, param) - let { transformer, column, } = getTransformer(conf, tableData.rows, axisSpecs, axis) + let { transformer, column, } = getTransformer(conf, tableData.rows, axisSpecs, axis) return { chartChanged: conf.chartChanged, http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/columnselector.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/columnselector.js b/zeppelin-web/src/app/tabledata/columnselector.js index 4b9180a..9fcf2f1 100644 --- a/zeppelin-web/src/app/tabledata/columnselector.js +++ b/zeppelin-web/src/app/tabledata/columnselector.js @@ -12,7 +12,7 @@ * limitations under the License. */ -import Transformation from './transformation'; +import Transformation from './transformation' /** * select columns @@ -26,57 +26,57 @@ import Transformation from './transformation'; * ] */ export default class ColumnselectorTransformation extends Transformation { - constructor(config, columnSelectorProp) { - super(config); - this.props = columnSelectorProp; - }; + constructor (config, columnSelectorProp) { + super(config) + this.props = columnSelectorProp + } - getSetting() { - var self = this; - var configObj = self.config; + getSetting () { + let self = this + let configObj = self.config return { template: 'app/tabledata/columnselector_settings.html', scope: { config: self.config, props: self.props, tableDataColumns: self.tableDataColumns, - save: function() { - self.emitConfig(configObj); + save: function () { + self.emitConfig(configObj) }, - remove: function(selectorName) { - configObj[selectorName] = null; - self.emitConfig(configObj); + remove: function (selectorName) { + configObj[selectorName] = null + self.emitConfig(configObj) } } - }; - }; + } + } /** * Method will be invoked when tableData or config changes */ - transform(tableData) { - this.tableDataColumns = tableData.columns; - this.removeUnknown(); - return tableData; - }; + transform (tableData) { + this.tableDataColumns = tableData.columns + this.removeUnknown() + return tableData + } - removeUnknown() { - var fields = this.config; - for (var f in fields) { + removeUnknown () { + let fields = this.config + for (let f in fields) { if (fields[f]) { - var found = false; - for (var i = 0; i < this.tableDataColumns.length; i++) { - var a = fields[f]; - var b = this.tableDataColumns[i]; + let found = false + for (let i = 0; i < this.tableDataColumns.length; i++) { + let a = fields[f] + let b = this.tableDataColumns[i] if (a.index === b.index && a.name === b.name) { - found = true; - break; + found = true + break } } if (!found && (fields[f] instanceof Object) && !(fields[f] instanceof Array)) { - fields[f] = null; + fields[f] = null } } } - }; + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/passthrough.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/passthrough.js b/zeppelin-web/src/app/tabledata/passthrough.js index b2d6ec4..e376c43 100644 --- a/zeppelin-web/src/app/tabledata/passthrough.js +++ b/zeppelin-web/src/app/tabledata/passthrough.js @@ -12,20 +12,21 @@ * limitations under the License. */ -import Transformation from './transformation'; +import Transformation from './transformation' /** * passthough the data */ export default class PassthroughTransformation extends Transformation { - constructor(config) { - super(config); - }; + // eslint-disable-next-line no-useless-constructor + constructor (config) { + super(config) + } /** * Method will be invoked when tableData or config changes */ - transform(tableData) { - return tableData; - }; + transform (tableData) { + return tableData + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/pivot.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/pivot.js b/zeppelin-web/src/app/tabledata/pivot.js index 366efee..1c938ea 100644 --- a/zeppelin-web/src/app/tabledata/pivot.js +++ b/zeppelin-web/src/app/tabledata/pivot.js @@ -12,174 +12,175 @@ * limitations under the License. */ -import Transformation from './transformation'; +import Transformation from './transformation' /** * pivot table data and return d3 chart data */ export default class PivotTransformation extends Transformation { - constructor(config) { - super(config); - }; + // eslint-disable-next-line no-useless-constructor + constructor (config) { + super(config) + } - getSetting() { - var self = this; + getSetting () { + let self = this - var configObj = self.config; - console.log('getSetting', configObj); + let configObj = self.config + console.log('getSetting', configObj) return { template: 'app/tabledata/pivot_settings.html', scope: { config: configObj.common.pivot, tableDataColumns: self.tableDataColumns, - save: function() { - self.emitConfig(configObj); + save: function () { + self.emitConfig(configObj) }, - removeKey: function(idx) { - configObj.common.pivot.keys.splice(idx, 1); - self.emitConfig(configObj); + removeKey: function (idx) { + configObj.common.pivot.keys.splice(idx, 1) + self.emitConfig(configObj) }, - removeGroup: function(idx) { - configObj.common.pivot.groups.splice(idx, 1); - self.emitConfig(configObj); + removeGroup: function (idx) { + configObj.common.pivot.groups.splice(idx, 1) + self.emitConfig(configObj) }, - removeValue: function(idx) { - configObj.common.pivot.values.splice(idx, 1); - self.emitConfig(configObj); + removeValue: function (idx) { + configObj.common.pivot.values.splice(idx, 1) + self.emitConfig(configObj) }, - setValueAggr: function(idx, aggr) { - configObj.common.pivot.values[idx].aggr = aggr; - self.emitConfig(configObj); + setValueAggr: function (idx, aggr) { + configObj.common.pivot.values[idx].aggr = aggr + self.emitConfig(configObj) } } - }; - }; + } + } /** * Method will be invoked when tableData or config changes */ - transform(tableData) { - this.tableDataColumns = tableData.columns; - this.config.common = this.config.common || {}; - this.config.common.pivot = this.config.common.pivot || {}; - var config = this.config.common.pivot; - var firstTime = (!config.keys && !config.groups && !config.values); + transform (tableData) { + this.tableDataColumns = tableData.columns + this.config.common = this.config.common || {} + this.config.common.pivot = this.config.common.pivot || {} + let config = this.config.common.pivot + let firstTime = (!config.keys && !config.groups && !config.values) - config.keys = config.keys || []; - config.groups = config.groups || []; - config.values = config.values || []; + config.keys = config.keys || [] + config.groups = config.groups || [] + config.values = config.values || [] - this.removeUnknown(); + this.removeUnknown() if (firstTime) { - this.selectDefault(); + this.selectDefault() } return this.pivot( tableData, config.keys, config.groups, - config.values); - }; + config.values) + } - removeUnknown() { - var config = this.config.common.pivot; - var tableDataColumns = this.tableDataColumns; - var unique = function(list) { - for (var i = 0; i < list.length; i++) { - for (var j = i + 1; j < list.length; j++) { + removeUnknown () { + let config = this.config.common.pivot + let tableDataColumns = this.tableDataColumns + let unique = function (list) { + for (let i = 0; i < list.length; i++) { + for (let j = i + 1; j < list.length; j++) { if (angular.equals(list[i], list[j])) { - list.splice(j, 1); + list.splice(j, 1) } } } - }; + } - var removeUnknown = function(list) { - for (var i = 0; i < list.length; i++) { + let removeUnknown = function (list) { + for (let i = 0; i < list.length; i++) { // remove non existing column - var found = false; - for (var j = 0; j < tableDataColumns.length; j++) { - var a = list[i]; - var b = tableDataColumns[j]; + let found = false + for (let j = 0; j < tableDataColumns.length; j++) { + let a = list[i] + let b = tableDataColumns[j] if (a.index === b.index && a.name === b.name) { - found = true; - break; + found = true + break } } if (!found) { - list.splice(i, 1); + list.splice(i, 1) } } - }; + } - unique(config.keys); - removeUnknown(config.keys); - unique(config.groups); - removeUnknown(config.groups); - removeUnknown(config.values); - }; + unique(config.keys) + removeUnknown(config.keys) + unique(config.groups) + removeUnknown(config.groups) + removeUnknown(config.values) + } - selectDefault() { - var config = this.config.common.pivot; + selectDefault () { + let config = this.config.common.pivot if (config.keys.length === 0 && config.groups.length === 0 && config.values.length === 0) { if (config.keys.length === 0 && this.tableDataColumns.length > 0) { - config.keys.push(this.tableDataColumns[0]); + config.keys.push(this.tableDataColumns[0]) } if (config.values.length === 0 && this.tableDataColumns.length > 1) { - config.values.push(this.tableDataColumns[1]); + config.values.push(this.tableDataColumns[1]) } } - }; + } - pivot(data, keys, groups, values) { - var aggrFunc = { - sum: function(a, b) { - var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return varA + varB; + pivot (data, keys, groups, values) { + let aggrFunc = { + sum: function (a, b) { + let varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + let varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return varA + varB }, - count: function(a, b) { - var varA = (a !== undefined) ? parseInt(a) : 0; - var varB = (b !== undefined) ? 1 : 0; - return varA + varB; + count: function (a, b) { + let varA = (a !== undefined) ? parseInt(a) : 0 + let varB = (b !== undefined) ? 1 : 0 + return varA + varB }, - min: function(a, b) { - var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return Math.min(varA,varB); + min: function (a, b) { + let varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + let varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return Math.min(varA, varB) }, - max: function(a, b) { - var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return Math.max(varA,varB); + max: function (a, b) { + let varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + let varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return Math.max(varA, varB) }, - avg: function(a, b, c) { - var varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0; - var varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0; - return varA + varB; + avg: function (a, b, c) { + let varA = (a !== undefined) ? (isNaN(a) ? 1 : parseFloat(a)) : 0 + let varB = (b !== undefined) ? (isNaN(b) ? 1 : parseFloat(b)) : 0 + return varA + varB } - }; + } - var aggrFuncDiv = { + let aggrFuncDiv = { sum: false, count: false, min: false, max: false, avg: true - }; + } - var schema = {}; - var rows = {}; + let schema = {} + let rows = {} - for (var i = 0; i < data.rows.length; i++) { - var row = data.rows[i]; - var s = schema; - var p = rows; + for (let i = 0; i < data.rows.length; i++) { + let row = data.rows[i] + let s = schema + let p = rows - for (var k = 0; k < keys.length; k++) { - var key = keys[k]; + for (let k = 0; k < keys.length; k++) { + let key = keys[k] // add key to schema if (!s[key.name]) { @@ -188,21 +189,21 @@ export default class PivotTransformation extends Transformation { index: key.index, type: 'key', children: {} - }; + } } - s = s[key.name].children; + s = s[key.name].children // add key to row - var keyKey = row[key.index]; + let keyKey = row[key.index] if (!p[keyKey]) { - p[keyKey] = {}; + p[keyKey] = {} } - p = p[keyKey]; + p = p[keyKey] } - for (var g = 0; g < groups.length; g++) { - var group = groups[g]; - var groupKey = row[group.index]; + for (let g = 0; g < groups.length; g++) { + let group = groups[g] + let groupKey = row[group.index] // add group to schema if (!s[groupKey]) { @@ -211,20 +212,20 @@ export default class PivotTransformation extends Transformation { index: group.index, type: 'group', children: {} - }; + } } - s = s[groupKey].children; + s = s[groupKey].children // add key to row if (!p[groupKey]) { - p[groupKey] = {}; + p[groupKey] = {} } - p = p[groupKey]; + p = p[groupKey] } - for (var v = 0; v < values.length; v++) { - var value = values[v]; - var valueKey = value.name + '(' + value.aggr + ')'; + for (let v = 0; v < values.length; v++) { + let value = values[v] + let valueKey = value.name + '(' + value.aggr + ')' // add value to schema if (!s[valueKey]) { @@ -232,7 +233,7 @@ export default class PivotTransformation extends Transformation { type: 'value', order: v, index: value.index - }; + } } // add value to row @@ -240,23 +241,23 @@ export default class PivotTransformation extends Transformation { p[valueKey] = { value: (value.aggr !== 'count') ? row[value.index] : 1, count: 1 - }; + } } else { p[valueKey] = { value: aggrFunc[value.aggr](p[valueKey].value, row[value.index], p[valueKey].count + 1), - count: (aggrFuncDiv[value.aggr]) ? p[valueKey].count + 1 : p[valueKey].count - }; + count: (aggrFuncDiv[value.aggr]) ? p[valueKey].count + 1 : p[valueKey].count + } } } } - //console.log('schema=%o, rows=%o', schema, rows); + // console.log('schema=%o, rows=%o', schema, rows); return { keys: keys, groups: groups, values: values, schema: schema, rows: rows - }; - }; + } + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/tabledata.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/tabledata.js b/zeppelin-web/src/app/tabledata/tabledata.js index 950f456..8e4e6b6 100644 --- a/zeppelin-web/src/app/tabledata/tabledata.js +++ b/zeppelin-web/src/app/tabledata/tabledata.js @@ -16,58 +16,58 @@ * Create table data object from paragraph table type result */ export default class TableData { - constructor(columns, rows, comment) { - this.columns = columns || []; - this.rows = rows || []; - this.comment = comment || ''; - }; + constructor (columns, rows, comment) { + this.columns = columns || [] + this.rows = rows || [] + this.comment = comment || '' + } - loadParagraphResult(paragraphResult) { + loadParagraphResult (paragraphResult) { if (!paragraphResult || paragraphResult.type !== 'TABLE') { - console.log('Can not load paragraph result'); - return; + console.log('Can not load paragraph result') + return } - var columnNames = []; - var rows = []; - var array = []; - var textRows = paragraphResult.msg.split('\n'); - var comment = ''; - var commentRow = false; + let columnNames = [] + let rows = [] + let array = [] + let textRows = paragraphResult.msg.split('\n') + let comment = '' + let commentRow = false - for (var i = 0; i < textRows.length; i++) { - var textRow = textRows[i]; + for (let i = 0; i < textRows.length; i++) { + let textRow = textRows[i] if (commentRow) { - comment += textRow; - continue; + comment += textRow + continue } if (textRow === '' || textRow === '<!--TABLE_COMMENT-->') { if (rows.length > 0) { - commentRow = true; + commentRow = true } - continue; + continue } - var textCols = textRow.split('\t'); - var cols = []; - var cols2 = []; - for (var j = 0; j < textCols.length; j++) { - var col = textCols[j]; + let textCols = textRow.split('\t') + let cols = [] + let cols2 = [] + for (let j = 0; j < textCols.length; j++) { + let col = textCols[j] if (i === 0) { - columnNames.push({name: col, index: j, aggr: 'sum'}); + columnNames.push({name: col, index: j, aggr: 'sum'}) } else { - cols.push(col); - cols2.push({key: (columnNames[i]) ? columnNames[i].name : undefined, value: col}); + cols.push(col) + cols2.push({key: (columnNames[i]) ? columnNames[i].name : undefined, value: col}) } } if (i !== 0) { - rows.push(cols); - array.push(cols2); + rows.push(cols) + array.push(cols2) } } - this.comment = comment; - this.columns = columnNames; - this.rows = rows; - }; + this.comment = comment + this.columns = columnNames + this.rows = rows + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/tabledata.test.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/tabledata.test.js b/zeppelin-web/src/app/tabledata/tabledata.test.js index 64dd915..7e41de4 100644 --- a/zeppelin-web/src/app/tabledata/tabledata.test.js +++ b/zeppelin-web/src/app/tabledata/tabledata.test.js @@ -12,30 +12,30 @@ * limitations under the License. */ -import TableData from './tabledata.js'; +import TableData from './tabledata.js' -describe('TableData build', function() { - var td; +describe('TableData build', function () { + let td - beforeEach(function() { - console.log(TableData); - td = new TableData(); - }); + beforeEach(function () { + console.log(TableData) + td = new TableData() + }) - it('should initialize the default value', function() { - expect(td.columns.length).toBe(0); - expect(td.rows.length).toBe(0); - expect(td.comment).toBe(''); - }); + it('should initialize the default value', function () { + expect(td.columns.length).toBe(0) + expect(td.rows.length).toBe(0) + expect(td.comment).toBe('') + }) - it('should able to create Tabledata from paragraph result', function() { + it('should able to create Tabledata from paragraph result', function () { td.loadParagraphResult({ type: 'TABLE', msg: 'key\tvalue\na\t10\nb\t20\n\nhello' - }); + }) - expect(td.columns.length).toBe(2); - expect(td.rows.length).toBe(2); - expect(td.comment).toBe('hello'); - }); -}); + expect(td.columns.length).toBe(2) + expect(td.rows.length).toBe(2) + expect(td.comment).toBe('hello') + }) +}) http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/tabledata/transformation.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/transformation.js b/zeppelin-web/src/app/tabledata/transformation.js index bdd620b..f142618 100644 --- a/zeppelin-web/src/app/tabledata/transformation.js +++ b/zeppelin-web/src/app/tabledata/transformation.js @@ -16,10 +16,10 @@ * Base class for visualization */ export default class Transformation { - constructor(config) { - this.config = config; - this._emitter; - }; + constructor (config) { + this.config = config + this._emitter = () => {} + } /** * return { @@ -27,77 +27,77 @@ export default class Transformation { * scope : an object to bind to template scope * } */ - getSetting() { + getSetting () { // override this - }; + } /** * Method will be invoked when tableData or config changes */ - transform(tableData) { + transform (tableData) { // override this - }; + } /** * render setting */ - renderSetting(targetEl) { - var setting = this.getSetting(); + renderSetting (targetEl) { + let setting = this.getSetting() if (!setting) { - return; + return } // already readered if (this._scope) { - var self = this; - this._scope.$apply(function() { - for (var k in setting.scope) { - self._scope[k] = setting.scope[k]; + let self = this + this._scope.$apply(function () { + for (let k in setting.scope) { + self._scope[k] = setting.scope[k] } - for (var k in self._prevSettingScope) { + for (let k in self._prevSettingScope) { if (!setting.scope[k]) { - self._scope[k] = setting.scope[k]; + self._scope[k] = setting.scope[k] } } - }); - return; + }) + return } else { - this._prevSettingScope = setting.scope; + this._prevSettingScope = setting.scope } - var scope = this._createNewScope(); - for (var k in setting.scope) { - scope[k] = setting.scope[k]; + let scope = this._createNewScope() + for (let k in setting.scope) { + scope[k] = setting.scope[k] } - var template = setting.template; + let template = setting.template if (template.split('\n').length === 1 && template.endsWith('.html')) { // template is url - var self = this; - this._templateRequest(template).then(function(t) { - self._render(targetEl, t, scope); - }); + let self = this + this._templateRequest(template).then(function (t) { + self._render(targetEl, t, scope) + }) } else { - this._render(targetEl, template, scope); + this._render(targetEl, template, scope) } - }; + } - _render(targetEl, template, scope) { - this._targetEl = targetEl; - targetEl.html(template); - this._compile(targetEl.contents())(scope); - this._scope = scope; - }; + _render (targetEl, template, scope) { + this._targetEl = targetEl + targetEl.html(template) + this._compile(targetEl.contents())(scope) + this._scope = scope + } - setConfig(config) { - this.config = config; - }; + setConfig (config) { + this.config = config + } /** * Emit config. config will sent to server and saved. */ - emitConfig(config) { - this._emitter(config); - }; + emitConfig (config) { + this._emitter(config) + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/visualization/builtins/visualization-areachart.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/visualization/builtins/visualization-areachart.js b/zeppelin-web/src/app/visualization/builtins/visualization-areachart.js index 4e0d318..900f0f4 100644 --- a/zeppelin-web/src/app/visualization/builtins/visualization-areachart.js +++ b/zeppelin-web/src/app/visualization/builtins/visualization-areachart.js @@ -12,29 +12,29 @@ * limitations under the License. */ -import Nvd3ChartVisualization from './visualization-nvd3chart'; -import PivotTransformation from '../../tabledata/pivot'; +import Nvd3ChartVisualization from './visualization-nvd3chart' +import PivotTransformation from '../../tabledata/pivot' /** * Visualize data in area chart */ export default class AreachartVisualization extends Nvd3ChartVisualization { - constructor(targetEl, config) { - super(targetEl, config); + constructor (targetEl, config) { + super(targetEl, config) - this.pivot = new PivotTransformation(config); - }; + this.pivot = new PivotTransformation(config) + } - type() { - return 'stackedAreaChart'; - }; + type () { + return 'stackedAreaChart' + } - getTransformation() { - return this.pivot; - }; + getTransformation () { + return this.pivot + } - render(pivot) { - var d3Data = this.d3DataFromPivot( + render (pivot) { + let d3Data = this.d3DataFromPivot( pivot.schema, pivot.rows, pivot.keys, @@ -42,37 +42,36 @@ export default class AreachartVisualization extends Nvd3ChartVisualization { pivot.values, false, true, - false); + false) - this.xLabels = d3Data.xLabels; - super.render(d3Data); - }; + this.xLabels = d3Data.xLabels + super.render(d3Data) + } /** * Set new config */ - setConfig(config) { - super.setConfig(config); - this.pivot.setConfig(config); - }; + setConfig (config) { + super.setConfig(config) + this.pivot.setConfig(config) + } - configureChart(chart) { - var self = this; - chart.xAxis.tickFormat(function(d) {return self.xAxisTickFormat(d, self.xLabels);}); - chart.yAxis.tickFormat(function(d) {return self.yAxisTickFormat(d);}); - chart.yAxis.axisLabelDistance(50); - chart.useInteractiveGuideline(true); // for better UX and performance issue. (https://github.com/novus/nvd3/issues/691) + configureChart (chart) { + let self = this + chart.xAxis.tickFormat(function (d) { return self.xAxisTickFormat(d, self.xLabels) }) + chart.yAxis.tickFormat(function (d) { return self.yAxisTickFormat(d) }) + chart.yAxis.axisLabelDistance(50) + chart.useInteractiveGuideline(true) // for better UX and performance issue. (https://github.com/novus/nvd3/issues/691) - this.chart.style(this.config.style || 'stack'); + this.chart.style(this.config.style || 'stack') - var self = this; - this.chart.dispatch.on('stateChange', function(s) { - self.config.style = s.style; + this.chart.dispatch.on('stateChange', function (s) { + self.config.style = s.style // give some time to animation finish - setTimeout(function() { - self.emitConfig(self.config); - }, 500); - }); - }; + setTimeout(function () { + self.emitConfig(self.config) + }, 500) + }) + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/visualization/builtins/visualization-barchart.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/visualization/builtins/visualization-barchart.js b/zeppelin-web/src/app/visualization/builtins/visualization-barchart.js index 15f0337..258fcce 100644 --- a/zeppelin-web/src/app/visualization/builtins/visualization-barchart.js +++ b/zeppelin-web/src/app/visualization/builtins/visualization-barchart.js @@ -12,29 +12,29 @@ * limitations under the License. */ -import Nvd3ChartVisualization from './visualization-nvd3chart'; -import PivotTransformation from '../../tabledata/pivot'; +import Nvd3ChartVisualization from './visualization-nvd3chart' +import PivotTransformation from '../../tabledata/pivot' /** * Visualize data in bar char */ export default class BarchartVisualization extends Nvd3ChartVisualization { - constructor(targetEl, config) { - super(targetEl, config); + constructor (targetEl, config) { + super(targetEl, config) - this.pivot = new PivotTransformation(config); - }; + this.pivot = new PivotTransformation(config) + } - type() { - return 'multiBarChart'; - }; + type () { + return 'multiBarChart' + } - getTransformation() { - return this.pivot; - }; + getTransformation () { + return this.pivot + } - render(pivot) { - var d3Data = this.d3DataFromPivot( + render (pivot) { + let d3Data = this.d3DataFromPivot( pivot.schema, pivot.rows, pivot.keys, @@ -42,79 +42,77 @@ export default class BarchartVisualization extends Nvd3ChartVisualization { pivot.values, true, true, - true); + true) - super.render(d3Data); - this.config.changeXLabel(this.config.xLabelStatus); - }; + super.render(d3Data) + this.config.changeXLabel(this.config.xLabelStatus) + } /** * Set new config */ - setConfig(config) { - super.setConfig(config); - this.pivot.setConfig(config); - }; + setConfig (config) { + super.setConfig(config) + this.pivot.setConfig(config) + } - configureChart(chart) { - var self = this; - var configObj = self.config; + configureChart (chart) { + let self = this + let configObj = self.config - chart.yAxis.axisLabelDistance(50); - chart.yAxis.tickFormat(function(d) {return self.yAxisTickFormat(d);}); + chart.yAxis.axisLabelDistance(50) + chart.yAxis.tickFormat(function (d) { return self.yAxisTickFormat(d) }) - self.chart.stacked(this.config.stacked); + self.chart.stacked(this.config.stacked) self.config.changeXLabel = function(type) { switch (type) { case 'default': - self.chart._options['showXAxis'] = true; - self.chart._options['margin'] = {bottom: 50}; - self.chart.xAxis.rotateLabels(0); - configObj.xLabelStatus = 'default'; - break; + self.chart._options['showXAxis'] = true + self.chart._options['margin'] = {bottom: 50} + self.chart.xAxis.rotateLabels(0) + configObj.xLabelStatus = 'default' + break case 'rotate': - self.chart._options['showXAxis'] = true; - self.chart._options['margin'] = {bottom: 140}; - self.chart.xAxis.rotateLabels(-45); - configObj.xLabelStatus = 'rotate'; - break; + self.chart._options['showXAxis'] = true + self.chart._options['margin'] = {bottom: 140} + self.chart.xAxis.rotateLabels(-45) + configObj.xLabelStatus = 'rotate' + break case 'hide': - self.chart._options['showXAxis'] = false; - self.chart._options['margin'] = {bottom: 50}; - d3.select('#' + self.targetEl[0].id + '> svg').select('g.nv-axis.nv-x').selectAll('*').remove(); - configObj.xLabelStatus = 'hide'; - break; + self.chart._options['showXAxis'] = false + self.chart._options['margin'] = {bottom: 50} + d3.select('#' + self.targetEl[0].id + '> svg').select('g.nv-axis.nv-x').selectAll('*').remove() + configObj.xLabelStatus = 'hide' + break } - }; + } self.config.isXLabelStatus = function(type) { if (configObj.xLabelStatus === type) { - return true; + return true } else { - return false; + return false } - }; + } this.chart.dispatch.on('stateChange', function(s) { - configObj.stacked = s.stacked; + configObj.stacked = s.stacked // give some time to animation finish setTimeout(function() { - self.emitConfig(configObj); - }, 500); - }); - }; - - + self.emitConfig(configObj) + }, 500) + }) + } getSetting(chart) { - var self = this; - var configObj = self.config; + let self = this + let configObj = self.config // default to visualize xLabel - if (typeof(configObj.xLabelStatus) === 'undefined') { - configObj.changeXLabel('default'); + if (typeof (configObj.xLabelStatus) === 'undefined') { + configObj.changeXLabel('default') } return { @@ -147,10 +145,10 @@ export default class BarchartVisualization extends Nvd3ChartVisualization { scope: { config: configObj, save: function(type) { - configObj.changeXLabel(type); - self.emitConfig(configObj); + configObj.changeXLabel(type) + self.emitConfig(configObj) } } - }; - }; + } + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/19b0f30f/zeppelin-web/src/app/visualization/builtins/visualization-linechart.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/visualization/builtins/visualization-linechart.js b/zeppelin-web/src/app/visualization/builtins/visualization-linechart.js index 577001f..31da47b 100644 --- a/zeppelin-web/src/app/visualization/builtins/visualization-linechart.js +++ b/zeppelin-web/src/app/visualization/builtins/visualization-linechart.js @@ -12,33 +12,33 @@ * limitations under the License. */ -import Nvd3ChartVisualization from './visualization-nvd3chart'; -import PivotTransformation from '../../tabledata/pivot'; +import Nvd3ChartVisualization from './visualization-nvd3chart' +import PivotTransformation from '../../tabledata/pivot' /** * Visualize data in line chart */ export default class LinechartVisualization extends Nvd3ChartVisualization { - constructor(targetEl, config) { - super(targetEl, config); + constructor (targetEl, config) { + super(targetEl, config) - this.pivot = new PivotTransformation(config); - }; + this.pivot = new PivotTransformation(config) + } - type() { + type () { if (this.config.lineWithFocus) { - return 'lineWithFocusChart'; + return 'lineWithFocusChart' } else { - return 'lineChart'; + return 'lineChart' } - }; + } - getTransformation() { - return this.pivot; - }; + getTransformation () { + return this.pivot + } - render(pivot) { - var d3Data = this.d3DataFromPivot( + render (pivot) { + let d3Data = this.d3DataFromPivot( pivot.schema, pivot.rows, pivot.keys, @@ -46,49 +46,49 @@ export default class LinechartVisualization extends Nvd3ChartVisualization { pivot.values, false, true, - false); + false) - this.xLabels = d3Data.xLabels; - super.render(d3Data); - }; + this.xLabels = d3Data.xLabels + super.render(d3Data) + } /** * Set new config */ - setConfig(config) { - super.setConfig(config); - this.pivot.setConfig(config); + setConfig (config) { + super.setConfig(config) + this.pivot.setConfig(config) // change mode if (this.currentMode !== config.lineWithFocus) { - super.destroy(); - this.currentMode = config.lineWithFocus; + super.destroy() + this.currentMode = config.lineWithFocus } - }; + } - configureChart(chart) { - var self = this; - chart.xAxis.tickFormat(function(d) {return self.xAxisTickFormat(d, self.xLabels);}); - chart.yAxis.tickFormat(function(d) { + configureChart (chart) { + let self = this + chart.xAxis.tickFormat(function (d) { return self.xAxisTickFormat(d, self.xLabels) }) + chart.yAxis.tickFormat(function (d) { if (d === undefined) { - return 'N/A'; + return 'N/A' } - return self.yAxisTickFormat(d, self.xLabels); - }); - chart.yAxis.axisLabelDistance(50); + return self.yAxisTickFormat(d, self.xLabels) + }) + chart.yAxis.axisLabelDistance(50) if (chart.useInteractiveGuideline) { // lineWithFocusChart hasn't got useInteractiveGuideline - chart.useInteractiveGuideline(true); // for better UX and performance issue. (https://github.com/novus/nvd3/issues/691) + chart.useInteractiveGuideline(true) // for better UX and performance issue. (https://github.com/novus/nvd3/issues/691) } if (this.config.forceY) { - chart.forceY([0]); // force y-axis minimum to 0 for line chart. + chart.forceY([0]) // force y-axis minimum to 0 for line chart. } else { - chart.forceY([]); + chart.forceY([]) } - }; + } - getSetting(chart) { - var self = this; - var configObj = self.config; + getSetting (chart) { + let self = this + let configObj = self.config return { template: `<div> @@ -109,14 +109,14 @@ export default class LinechartVisualization extends Nvd3ChartVisualization { </div>`, scope: { config: configObj, - save: function() { - self.emitConfig(configObj); + save: function () { + self.emitConfig(configObj) } } - }; - }; + } + } - defaultY() { - return undefined; - }; + defaultY () { + return undefined + } }