feat: advanced-transformation-api

This commit is contained in:
1ambda 2017-03-13 21:15:38 +09:00
parent 75569cea6e
commit d89e223768
3 changed files with 51 additions and 10 deletions

View file

@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export function getCurrentChart(config) {
return config.chart.current;
}
export function getCurrentChartAxis(config) {
return config.axis[getCurrentChart(config)]
}
export function getCurrentChartParam(config) {
return config.parameter[getCurrentChart(config)]
}
export function getCurrentChartAxisSpecs(config) {
return config.axisSpecs[getCurrentChart(config)]
}
export function getCurrentChartParamSpecs(config) {
return config.paramSpecs[getCurrentChart(config)]
}

View file

@ -14,6 +14,10 @@
const lo = _; /** provided by bower */
import {
getCurrentChartAxis,
} from './advanced-transformation-api'
export const Aggregator = {
SUM: 'sum',
COUNT: 'count',
@ -56,7 +60,7 @@ export function getAvailableChartNames(charts) {
export function removeDuplicatedColumnsInMultiDimensionAxis(config, axisSpec) {
if (isSingleDimension(axisSpec)) { return config; }
const columns = config.axis[config.chart.current][axisSpec.name]
const columns = getCurrentChartAxis(config)[axisSpec.name]
const uniqObject = columns.reduce((acc, col) => {
if (!acc[col.name]) { acc[col.name] = col; }
return acc
@ -68,7 +72,7 @@ export function removeDuplicatedColumnsInMultiDimensionAxis(config, axisSpec) {
filtered.push(col)
}
config.axis[config.chart.current][axisSpec.name] = filtered
getCurrentChartAxis(config)[axisSpec.name] = filtered
return config
}
@ -84,9 +88,9 @@ export function clearConfig(config) {
}
export function initializeConfig(config, spec) {
// if (!config.spec || config.spec.version !== spec.version) {
// clearConfig(config)
// }
if (!config.spec || config.spec.version !== spec.version) {
clearConfig(config)
}
const availableCharts = getAvailableChartNames(spec.charts);

View file

@ -20,6 +20,10 @@ import {
// groupAndAggregateRows, getGroupAndAggrColumns,
} from './advanced-transformation-util';
import {
getCurrentChartAxis,
} from './advanced-transformation-api'
const SETTING_TEMPLATE = 'app/tabledata/advanced-transformation-setting.html';
class AdvancedTransformation extends Transformation {
@ -48,7 +52,7 @@ class AdvancedTransformation extends Transformation {
},
getSingleDimensionAxis: (axisSpec) => {
return configInstance.axis[configInstance.chart.current][axisSpec.name]
return getCurrentChartAxis(configInstance)[axisSpec.name]
},
toggleColumnPanel: () => {
@ -88,18 +92,18 @@ class AdvancedTransformation extends Transformation {
aggregatorChanged: (colIndex, axisSpec, aggregator) => {
if (isSingleDimension(axisSpec)) {
configInstance.axis[configInstance.chart.current][axisSpec.name].aggr = aggregator
getCurrentChartAxis(configInstance)[axisSpec.name].aggr = aggregator
} else {
configInstance.axis[configInstance.chart.current][axisSpec.name][colIndex].aggr = aggregator
getCurrentChartAxis(configInstance)[axisSpec.name][colIndex].aggr = aggregator
}
self.emitConfig(configInstance)
},
removeFromAxis: function(colIndex, axisSpec) {
if (isSingleDimension(axisSpec)) {
configInstance.axis[configInstance.chart.current][axisSpec.name] = null
getCurrentChartAxis(configInstance)[axisSpec.name] = null
} else {
configInstance.axis[configInstance.chart.current][axisSpec.name].splice(colIndex, 1)
getCurrentChartAxis(configInstance)[axisSpec.name].splice(colIndex, 1)
}
self.emitConfig(configInstance)
}