mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
refactor: Refine axis, param spec
This commit is contained in:
parent
d89e223768
commit
49985c6905
3 changed files with 64 additions and 57 deletions
|
|
@ -95,12 +95,12 @@ limitations under the License.
|
|||
<span ng-if="isGroupAxis(axisSpec)"
|
||||
class="label label-default"
|
||||
style="background-color: #cd5c5c; font-weight: 300; font-size: 13px; margin-left: 3px;">
|
||||
group by
|
||||
group
|
||||
</span>
|
||||
<span ng-if="isGroupBaseAxis(axisSpec)"
|
||||
<span ng-if="isKeyAxis(axisSpec)"
|
||||
class="label label-default"
|
||||
style="background-color: #906ebd; font-weight: 300; font-size: 13px; margin-left: 3px;">
|
||||
group base
|
||||
key
|
||||
</span>
|
||||
|
||||
<!-- axis box: in case of single dimension -->
|
||||
|
|
@ -235,7 +235,7 @@ limitations under the License.
|
|||
|
||||
<tr data-ng-repeat="paramSpec in config.paramSpecs[config.chart.current]">
|
||||
<td style="font-weight: 400; vertical-align: middle;">{{paramSpec.name}}</td>
|
||||
<td style="font-weight: 400; vertical-align: middle;">{{paramSpec.type}}</td>
|
||||
<td style="font-weight: 400; vertical-align: middle;">{{paramSpec.valueType}}</td>
|
||||
<td style="font-weight: 400; vertical-align: middle;">{{paramSpec.description}}</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
|
|
|
|||
|
|
@ -26,10 +26,18 @@ export const Aggregator = {
|
|||
MAX: 'max',
|
||||
}
|
||||
|
||||
export function isAggregator(axisSpec) { return axisSpec.aggregator; }
|
||||
export function isGroup(axisSpec) { return axisSpec.group; }
|
||||
export function isGroupBase(axisSpec) { return axisSpec.groupBase; }
|
||||
export function isSingleDimension(axisSpec) { return axisSpec.dimension === 'single'; }
|
||||
export function isAggregator(axisSpec) {
|
||||
return axisSpec && axisSpec.axisType === 'aggregator';
|
||||
}
|
||||
export function isGroup(axisSpec) {
|
||||
return axisSpec && axisSpec.axisType === 'group';
|
||||
}
|
||||
export function isKey(axisSpec) {
|
||||
return axisSpec && axisSpec.axisType === 'key';
|
||||
}
|
||||
export function isSingleDimension(axisSpec) {
|
||||
return axisSpec && axisSpec.dimension === 'single';
|
||||
}
|
||||
|
||||
/**
|
||||
* before: { name: { ... } }
|
||||
|
|
@ -150,29 +158,29 @@ export function initializeConfig(config, spec) {
|
|||
}
|
||||
|
||||
|
||||
export function getGroupAndAggrColumns(axisSpecs, axisConfig) {
|
||||
export function getColumnsFromAxis(axisSpecs, axisConfig) {
|
||||
const groupAxisNames = [];
|
||||
const groupBaseAxisNames = [];
|
||||
const keyAxisNames = [];
|
||||
const aggrAxisNames = [];
|
||||
|
||||
for(let i = 0; i < axisSpecs.length; i++) {
|
||||
const axisSpec = axisSpecs[i];
|
||||
|
||||
// do not allow duplication and beware of if-else stmt order
|
||||
if (isGroupBase(axisSpec)) { groupBaseAxisNames.push(axisSpec.name); }
|
||||
if (isKey(axisSpec)) { keyAxisNames.push(axisSpec.name); }
|
||||
else if (isGroup(axisSpec)) { groupAxisNames.push(axisSpec.name); }
|
||||
else if (isAggregator(axisSpec)) { aggrAxisNames.push(axisSpec.name); }
|
||||
}
|
||||
|
||||
let groupBaseColumns = []; /** `groupBase` */
|
||||
let keyColumns = []; /** `groupBase` */
|
||||
let groupColumns = []; /** `group` */
|
||||
let aggregatorColumns = []; /** `aggregator` */
|
||||
let otherColumns = []; /** specified, but not group and aggregator */
|
||||
|
||||
for(let colName in axisConfig) {
|
||||
const columns = axisConfig[colName];
|
||||
if (groupBaseAxisNames.includes(colName)) {
|
||||
groupBaseColumns = groupBaseColumns.concat(columns);
|
||||
if (keyAxisNames.includes(colName)) {
|
||||
keyColumns = keyColumns.concat(columns);
|
||||
} else if (groupAxisNames.includes(colName)) {
|
||||
groupColumns = groupColumns.concat(columns);
|
||||
} else if (aggrAxisNames.includes(colName)) {
|
||||
|
|
@ -183,26 +191,14 @@ export function getGroupAndAggrColumns(axisSpecs, axisConfig) {
|
|||
}
|
||||
|
||||
return {
|
||||
groupBase: groupBaseColumns,
|
||||
key: keyColumns,
|
||||
group: groupColumns,
|
||||
aggregator: aggregatorColumns,
|
||||
others: otherColumns,
|
||||
}
|
||||
}
|
||||
|
||||
export function getConfiguredColumnIndices(allColumns, configuredColumns) {
|
||||
|
||||
const configuredColumnNames = configuredColumns.map(c => c.name);
|
||||
|
||||
const configuredColumnIndices = allColumns.reduce((acc, c) => {
|
||||
if (configuredColumnNames.includes(c.name)) { return acc.concat(c.index) }
|
||||
else { return acc }
|
||||
}, []);
|
||||
|
||||
return configuredColumnIndices;
|
||||
}
|
||||
|
||||
export function groupAndAggregateRows(rows, groupBaseColumns, groupColumns, aggregatorColumns) {
|
||||
export function groupAndAggregateRows(rows, keyColumns, groupColumns, aggregatorColumns) {
|
||||
const groupColumnIndices = groupColumns.map(c => c.index);
|
||||
|
||||
const converted = lo.chain(rows)
|
||||
|
|
|
|||
|
|
@ -15,13 +15,16 @@
|
|||
import Transformation from './transformation';
|
||||
|
||||
import {
|
||||
isAggregator, isGroup, isGroupBase, isSingleDimension,
|
||||
isAggregator, isGroup, isKey, isSingleDimension,
|
||||
clearConfig, initializeConfig, removeDuplicatedColumnsInMultiDimensionAxis,
|
||||
// groupAndAggregateRows, getGroupAndAggrColumns,
|
||||
groupAndAggregateRows, getColumnsFromAxis,
|
||||
} from './advanced-transformation-util';
|
||||
|
||||
import {
|
||||
getCurrentChart,
|
||||
getCurrentChartAxis,
|
||||
getCurrentChartAxisSpecs,
|
||||
getCurrentChartParam,
|
||||
} from './advanced-transformation-api'
|
||||
|
||||
const SETTING_TEMPLATE = 'app/tabledata/advanced-transformation-setting.html';
|
||||
|
|
@ -48,7 +51,7 @@ class AdvancedTransformation extends Transformation {
|
|||
columns: self.columns,
|
||||
|
||||
getAxisAnnotation: (axisSpec) => {
|
||||
return `${axisSpec.name} (${axisSpec.type})`
|
||||
return `${axisSpec.name} (${axisSpec.valueType})`
|
||||
},
|
||||
|
||||
getSingleDimensionAxis: (axisSpec) => {
|
||||
|
|
@ -72,7 +75,7 @@ class AdvancedTransformation extends Transformation {
|
|||
},
|
||||
|
||||
isGroupAxis: (axisSpec) => { return isGroup(axisSpec) },
|
||||
isGroupBaseAxis: (axisSpec) => { return isGroupBase(axisSpec) },
|
||||
isKeyAxis: (axisSpec) => { return isKey(axisSpec) },
|
||||
isAggregatorAxis: (axisSpec) => { return isAggregator(axisSpec) },
|
||||
isSingleDimensionAxis: (axisSpec) => { return isSingleDimension(axisSpec) },
|
||||
|
||||
|
|
@ -114,31 +117,39 @@ class AdvancedTransformation extends Transformation {
|
|||
transform(tableData) {
|
||||
this.columns = tableData.columns; /** used in `getSetting` */
|
||||
|
||||
return tableData
|
||||
// const axisSpecs = this.axisSpecs; /** specs */
|
||||
// const axisConfig = this.config.axis; /** configured columns */
|
||||
//
|
||||
// const columns = getGroupAndAggrColumns(axisSpecs, axisConfig);
|
||||
// const groupBaseColumns = columns.groupBase;
|
||||
// const groupColumns = columns.group;
|
||||
// const aggregatorColumns = columns.aggregator;
|
||||
// const otherColumns = columns.others;
|
||||
//
|
||||
// const grouped = groupAndAggregateRows(tableData.rows, groupBaseColumns, groupColumns, aggregatorColumns)
|
||||
//
|
||||
// return {
|
||||
// row: {
|
||||
// all: tableData.rows,
|
||||
// grouped: grouped, /** [ { group<String>, rows<Array>, aggregatedValues<Object> } ] */
|
||||
// },
|
||||
// column: {
|
||||
// all: tableData.columns,
|
||||
// groupBase: groupBaseColumns,
|
||||
// group: groupColumns,
|
||||
// aggregator: aggregatorColumns,
|
||||
// others: otherColumns,
|
||||
// }
|
||||
// }
|
||||
const conf = this.config
|
||||
const chart = getCurrentChart(conf)
|
||||
const axis = getCurrentChartAxis(conf)
|
||||
const param = getCurrentChartParam(conf)
|
||||
const axisSpecs = getCurrentChartAxisSpecs(conf)
|
||||
|
||||
const columns = getColumnsFromAxis(axisSpecs, axis);
|
||||
const keyColumns = columns.key;
|
||||
const groupColumns = columns.group;
|
||||
const aggregatorColumns = columns.aggregator;
|
||||
const otherColumns = columns.others;
|
||||
|
||||
const grouped = groupAndAggregateRows(tableData.rows, keyColumns, groupColumns, aggregatorColumns)
|
||||
|
||||
return {
|
||||
chart: chart,
|
||||
axis: axis,
|
||||
parameter: param,
|
||||
|
||||
row: {
|
||||
all: tableData.rows,
|
||||
},
|
||||
|
||||
column: {
|
||||
all: tableData.columns,
|
||||
key: keyColumns,
|
||||
group: groupColumns,
|
||||
aggregator: aggregatorColumns,
|
||||
others: otherColumns,
|
||||
},
|
||||
|
||||
cube: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue