forked from fanruan/design
Browse Source
* commit 'fabd06ef62dcc5311bf4b62975dbd9762d0d340c': (73 commits) REPORT-34780 && CHART-14441 CHART-14624 调整面积图系列面板不透明的enable属性的check REPORT-35381 && REPORT-35379 CHART-14541 轴标题增加缩进 REPORT-34020 【国际化】非简中设计器-界面右侧面板选择超链接或悬浮元素后下拉框溢出 CHART-14120 英文设计器地图数据面板截断 REPORT-33236 REPORT-31546 公式面板的说明切换偶尔会失效 REPORT-34351 ""改为StringUtils.EMPTY REPORT-33500 日志面板清除日志后同时清除设计器右上角日志提示信息 REPORT-35016【组件生成】目前生成的组件,从组件库拖入模板中会变大 [场景] 从组件库拖入时,不会保持原有的大小。 [解决方案] 将原来的大小,在创建时一并初始化 CHART-14346 CHART-14346 悬浮窗图表组合图不允许选择单元格数据源 REPORT-34954 富文本上标下标不应该可以同时设置 REPORT-34954 富文本上标下标可以同时设置 CHART-14180 优化代码 CHART-14346 && CHART-14180 悬浮图表配置组合图不能选择单元格数据源 && 轴标题隐藏优化 REPORT-34385 修改联网搜索的enable条件 REPORT-34351 修正FineJOptionPane组件showInputDialog()方法点击弹出框的取消键后的行为;在组件重命名后将与自己的原来的名字进行对比的情况去除 REPORT-34385 enabled4Locale与isSearchOnLine条件合并 ...feature/big-screen
Qinghui.Liu
5 years ago
40 changed files with 1192 additions and 668 deletions
@ -0,0 +1,143 @@
|
||||
package com.fr.design.chart.auto; |
||||
|
||||
import com.fr.chart.auto.ColumnInfo; |
||||
import com.fr.chart.auto.strategy.AutoTypeStrategy; |
||||
import com.fr.chart.auto.strategy.imp.AvaStrategy; |
||||
import com.fr.chart.auto.strategy.imp.BubbleChartStrategy; |
||||
import com.fr.chart.auto.strategy.imp.SingleDimensionStrategy; |
||||
import com.fr.chart.auto.strategy.imp.SingleTargetStrategy; |
||||
import com.fr.data.TableDataSource; |
||||
import com.fr.data.TableDataSourceTailor; |
||||
import com.fr.data.impl.EmbeddedTableData; |
||||
import com.fr.data.impl.NameTableData; |
||||
import com.fr.design.data.DesignTableDataManager; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.chart.vanchart.VanChart; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2020-05-08 |
||||
*/ |
||||
public class AutoTypeCalculate { |
||||
|
||||
public static List<VanChart> calculateType(String tableName, List<String> columns) { |
||||
List<ColumnInfo> columnValue = calculateField(tableName, columns); |
||||
if (columnValue.isEmpty()) { |
||||
return new ArrayList<>(); |
||||
} |
||||
|
||||
List<ColumnInfo> dimensions = new ArrayList<>(); |
||||
List<ColumnInfo> targets = new ArrayList<>(); |
||||
for (ColumnInfo field : columnValue) { |
||||
if (isTarget(field.getValues())) { |
||||
targets.add(field); |
||||
} else { |
||||
dimensions.add(field); |
||||
} |
||||
} |
||||
AutoTypeStrategy autoTypeStrategy = chooseStrategy(dimensions.size(), targets.size()); |
||||
return autoTypeStrategy.rankChart(tableName, dimensions, targets); |
||||
} |
||||
|
||||
private static AutoTypeStrategy chooseStrategy(int dimensionSize, int targetSize) { |
||||
if (dimensionSize == 0) { |
||||
//没有维度,并且只有一个指标,使用单指标匹配逻辑,大于1个指标,使用气泡图(散点图)匹配逻辑
|
||||
if (targetSize == 1) { |
||||
return new SingleTargetStrategy(); |
||||
} else { |
||||
return new BubbleChartStrategy(); |
||||
} |
||||
} else if (dimensionSize == 1) { |
||||
//1个维度,并且没有指标,使用单维度匹配,2~3个指标,使用气泡图(散点图)匹配逻辑,其余使用ava匹配
|
||||
if (targetSize == 0) { |
||||
return new SingleDimensionStrategy(); |
||||
} else if (targetSize == 2 || targetSize == 3) { |
||||
return new BubbleChartStrategy(); |
||||
} else { |
||||
return new AvaStrategy(); |
||||
} |
||||
} else { |
||||
//大与1个维度,并且没有指标,使用单维度匹配(循环),否则使用ava匹配
|
||||
if (targetSize == 0) { |
||||
return new SingleDimensionStrategy(); |
||||
} else { |
||||
return new AvaStrategy(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static boolean isTarget(List<String> values) { |
||||
for (String value : values) { |
||||
if (StringUtils.isEmpty(value)) { |
||||
continue; |
||||
} |
||||
Number number = GeneralUtils.string2Number(value); |
||||
if (number == null) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
private static List<ColumnInfo> calculateField(String tableName, List<String> columns) { |
||||
NameTableData nameTableData = new NameTableData(tableName); |
||||
TableDataSource dataSource = TableDataSourceTailor.extractTableData(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget()); |
||||
Calculator calculator = Calculator.createCalculator(); |
||||
calculator.setAttribute(TableDataSource.KEY, dataSource); |
||||
nameTableData.createTableData(calculator); |
||||
|
||||
EmbeddedTableData tableData; |
||||
try { |
||||
tableData = DesignTableDataManager.previewTableDataNeedInputParameters(dataSource, nameTableData, Integer.MAX_VALUE, false); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
return new ArrayList<>(); |
||||
} |
||||
|
||||
List<ColumnInfo> originalData = new ArrayList<>(); |
||||
for (String column : columns) { |
||||
List<String> columnData = getColumnData(tableData, column); |
||||
if (columnData != null && !columnData.isEmpty()) { |
||||
originalData.add(new ColumnInfo(column, columnData)); |
||||
} |
||||
} |
||||
return originalData; |
||||
} |
||||
|
||||
private static List<String> getColumnData(EmbeddedTableData tableData, String columnName) { |
||||
List<String> columnData = new ArrayList<>(); |
||||
|
||||
int colIndex = getColIndex(tableData, columnName); |
||||
if (colIndex == DataModel.COLUMN_NAME_NOT_FOUND) { |
||||
return columnData; |
||||
} |
||||
|
||||
int size = tableData.getRowCount(); |
||||
for (int i = 0; i < size; i++) { |
||||
Object valueAt = tableData.getValueAt(i, colIndex); |
||||
columnData.add(GeneralUtils.objectToString(valueAt)); |
||||
} |
||||
return columnData; |
||||
} |
||||
|
||||
private static int getColIndex(EmbeddedTableData tableData, String columnName) { |
||||
int colIndex = 0; |
||||
|
||||
for (int count = tableData.getColumnCount(); colIndex < count; ++colIndex) { |
||||
if (ComparatorUtils.tableDataColumnNameEquals(tableData.getColumnName(colIndex), columnName)) { |
||||
return colIndex; |
||||
} |
||||
} |
||||
return DataModel.COLUMN_NAME_NOT_FOUND; |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.chart.chartattr.ChartCollection; |
||||
import com.fr.design.designer.creator.XCreator; |
||||
import com.fr.form.share.SharableWidgetProvider; |
||||
import com.fr.form.ui.ChartEditor; |
||||
import com.fr.general.ImageWithSuffix; |
||||
import com.fr.invoke.Reflect; |
||||
import org.easymock.EasyMock; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore; |
||||
import org.powermock.modules.junit4.PowerMockRunner; |
||||
|
||||
@RunWith(PowerMockRunner.class) |
||||
@PowerMockIgnore({"com.fr.jvm.assist.*", "javax.swing.*"}) |
||||
public class ShareWidgetButtonTest { |
||||
|
||||
@Test |
||||
public void testCreateXCreator() throws Exception { |
||||
|
||||
SharableWidgetProvider provider = EasyMock.mock(SharableWidgetProvider.class); |
||||
EasyMock.expect(provider.getWidth()).andReturn(300).anyTimes(); |
||||
EasyMock.expect(provider.getHeight()).andReturn(400).anyTimes(); |
||||
EasyMock.expect(provider.getName()).andReturn("test-drag").anyTimes(); |
||||
EasyMock.expect(provider.getCover()).andReturn(new ImageWithSuffix("utf-8")).anyTimes(); |
||||
EasyMock.replay(provider); |
||||
|
||||
ShareWidgetButton.ShareWidgetUI ui = new ShareWidgetButton.ShareWidgetUI(); |
||||
|
||||
ChartEditor editor = new ChartEditor(); |
||||
Reflect.on(editor).set("chartCollection", new ChartCollection()); |
||||
XCreator xCreator = ui.createXCreator(editor, "333", provider); |
||||
Assert.assertEquals(300, xCreator.getWidth()); |
||||
Assert.assertEquals(400, xCreator.getHeight()); |
||||
} |
||||
} |
Loading…
Reference in new issue