forked from eclipse-birt/birt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support new aggregation function "Range" in model, data engine, chart
engine and extension. New function will also appear in UI aggregation function drop down list automatically.
- Loading branch information
Yulin Wang
committed
Jul 11, 2016
1 parent
7b71f1b
commit 078d643
Showing
12 changed files
with
335 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...pse.birt.chart.engine.extension/src/org/eclipse/birt/chart/extension/aggregate/Range.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2004, 2016 Actuate Corporation. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Actuate Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.birt.chart.extension.aggregate; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.eclipse.birt.chart.aggregate.AggregateFunctionAdapter; | ||
import org.eclipse.birt.core.data.DataType; | ||
|
||
/** | ||
* | ||
*/ | ||
|
||
public class Range extends AggregateFunctionAdapter | ||
{ | ||
|
||
private Object max; | ||
private Object min; | ||
|
||
@SuppressWarnings({ | ||
"unchecked", "rawtypes" | ||
}) | ||
public void accumulate( Object oValue ) throws IllegalArgumentException | ||
{ | ||
if ( max == null ) | ||
{ | ||
max = oValue; | ||
min = oValue; | ||
} | ||
else if ( oValue instanceof Comparable ) | ||
{ | ||
max = ( (Comparable) oValue ).compareTo( max ) >= 0 ? oValue : max; | ||
min = ( (Comparable) oValue ).compareTo( min ) <= 0 ? oValue : min; | ||
} | ||
|
||
} | ||
|
||
public Object getAggregatedValue( ) | ||
{ | ||
switch ( getDataType( ) ) | ||
{ | ||
case NUMBER : | ||
return new Double( ( (double) max ) - (double) min ); | ||
|
||
case BIGDECIMAL : | ||
return ( (BigDecimal) max ).subtract( (BigDecimal) min ); | ||
|
||
default : | ||
return null; // THIS CONDITION SHOULD NEVER ARISE | ||
} | ||
} | ||
|
||
public void initialize( ) | ||
{ | ||
max = null; | ||
min = null; | ||
} | ||
|
||
@Override | ||
public int getBIRTDataType( ) | ||
{ | ||
return DataType.DOUBLE_TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
....eclipse.birt.data.aggregation/src/org/eclipse/birt/data/aggregation/impl/TotalRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/** | ||
************************************************************************* | ||
* Copyright (c) 2004, 2016 Actuate Corporation. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Actuate Corporation - initial API and implementation | ||
* | ||
************************************************************************* | ||
*/ | ||
|
||
package org.eclipse.birt.data.aggregation.impl; | ||
|
||
import org.eclipse.birt.core.data.DataType; | ||
import org.eclipse.birt.data.aggregation.api.IBuildInAggregation; | ||
import org.eclipse.birt.data.aggregation.calculator.CalculatorFactory; | ||
import org.eclipse.birt.data.aggregation.calculator.ICalculator; | ||
import org.eclipse.birt.data.aggregation.i18n.Messages; | ||
import org.eclipse.birt.data.engine.api.aggregation.Accumulator; | ||
import org.eclipse.birt.data.engine.api.aggregation.IParameterDefn; | ||
import org.eclipse.birt.data.engine.core.DataException; | ||
|
||
/** | ||
* | ||
* Implements the built-in Total.Range aggregation | ||
*/ | ||
public class TotalRange extends AggrFunction | ||
{ | ||
|
||
public String getName( ) | ||
{ | ||
return IBuildInAggregation.TOTAL_RANGE_FUNC; | ||
} | ||
|
||
public int getType( ) | ||
{ | ||
return SUMMARY_AGGR; | ||
} | ||
|
||
public int getDataType( ) | ||
{ | ||
return DataType.DOUBLE_TYPE; | ||
} | ||
|
||
public IParameterDefn[] getParameterDefn( ) | ||
{ | ||
return new IParameterDefn[]{ | ||
new ParameterDefn( Constants.EXPRESSION_NAME, | ||
Constants.EXPRESSION_DISPLAY_NAME, | ||
false, | ||
true, | ||
SupportedDataTypes.CALCULATABLE, | ||
"" )//$NON-NLS-1$ | ||
}; | ||
} | ||
|
||
public Accumulator newAccumulator( ) | ||
{ | ||
return new MyAccumulator( | ||
CalculatorFactory.getCalculator( getDataType( ) ) ); | ||
} | ||
|
||
private static class MyAccumulator extends SummaryAccumulator | ||
{ | ||
|
||
private Object max = null; | ||
private Object min = null; | ||
|
||
private boolean isRowAvailable = false; | ||
|
||
MyAccumulator( ICalculator calc ) | ||
{ | ||
super( calc ); | ||
} | ||
|
||
public void start( ) | ||
{ | ||
super.start( ); | ||
max = null; | ||
min = null; | ||
isRowAvailable = false; | ||
} | ||
|
||
public void onRow( Object[] args ) | ||
{ | ||
assert ( args.length > 0 ); | ||
if ( args[0] != null ) | ||
{ | ||
if ( !isRowAvailable ) | ||
{ | ||
isRowAvailable = true; | ||
max = args[0]; | ||
min = max; | ||
return; | ||
} | ||
if ( isGreaterThan( args[0], max ) ) | ||
{ | ||
max = args[0]; | ||
} | ||
else if ( isLessThan( args[0], min ) ) | ||
{ | ||
min = args[0]; | ||
} | ||
} | ||
} | ||
|
||
public Object getSummaryValue( ) throws DataException | ||
{ | ||
return calculator.subtract( calculator.getTypedObject( max ), | ||
calculator.getTypedObject( min ) ); | ||
} | ||
|
||
@SuppressWarnings({ | ||
"unchecked", "rawtypes" | ||
}) | ||
private boolean isGreaterThan( Object origin, Object target ) | ||
{ | ||
if ( ( origin instanceof Comparable ) | ||
&& ( target instanceof Comparable ) ) | ||
{ | ||
return ( (Comparable) origin ).compareTo( target ) > 0; | ||
} | ||
else | ||
{ | ||
throw new RuntimeException( Messages.getString( | ||
"TotalMax.exception.cannot_get_max_value" ) ); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
@SuppressWarnings({ | ||
"unchecked", "rawtypes" | ||
}) | ||
private boolean isLessThan( Object origin, Object target ) | ||
{ | ||
if ( ( origin instanceof Comparable ) | ||
&& ( target instanceof Comparable ) ) | ||
{ | ||
return ( (Comparable) origin ).compareTo( target ) < 0; | ||
} | ||
else | ||
{ | ||
throw new RuntimeException( Messages.getString( | ||
"TotalMin.exception.cannot_get_min_value" ) ); //$NON-NLS-1$ | ||
} | ||
} | ||
} | ||
|
||
public String getDescription( ) | ||
{ | ||
return Messages.getString( "TotalRange.description" ); //$NON-NLS-1$ | ||
} | ||
|
||
public String getDisplayName( ) | ||
{ | ||
return Messages.getString( "TotalRange.displayName" ); //$NON-NLS-1$ | ||
} | ||
} |
Oops, something went wrong.