Browse Source

Pull request #1772: CHART-13666 自动类型推荐匹配

Merge in DESIGN/design from ~BJORN/design:release/10.0 to release/10.0

* commit '55ce7416233fe7bc9f589306b30b37f9fe462eb2':
  CHART-13666 自动推荐类型
  CHART-13666 图表自动推荐
  CHART-13666 自动类型推荐匹配
feature/big-screen
Bjorn 4 years ago
parent
commit
d207646647
  1. 25
      designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfo.java
  2. 17
      designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java
  3. 15
      designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java
  4. 2
      designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java
  5. 122
      designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java
  6. 18
      designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java
  7. 143
      designer-chart/src/main/java/com/fr/design/chart/auto/AutoTypeCalculate.java

25
designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfo.java

@ -54,6 +54,8 @@ public class ChartInfo extends AbstractPointInfo {
private static final String ATTR_OVER_CHART_TYPE_COUNT = "overChartTypeCount"; private static final String ATTR_OVER_CHART_TYPE_COUNT = "overChartTypeCount";
private static final String ATTR_IS_NEW = "isNew"; private static final String ATTR_IS_NEW = "isNew";
private static final String ATTR_IS_REUSE = "isReuse"; private static final String ATTR_IS_REUSE = "isReuse";
private static final String ATTR_AUTO_CHART_CREATE_TIME = "autoChartCreateTime";
private static final String ATTR_AUTO_CHART_ENSURE_TIME = "autoChartEnsureTime";
private static final int COMPLETE_DAY_COUNT = 3; // 判断图表是否可以上传的天数 private static final int COMPLETE_DAY_COUNT = 3; // 判断图表是否可以上传的天数
@ -122,10 +124,10 @@ public class ChartInfo extends AbstractPointInfo {
} }
public static ChartInfo newInstance(ChartProvider chartProvider) { public static ChartInfo newInstance(ChartProvider chartProvider) {
return newInstance(chartProvider, null, false, false); return newInstance(chartProvider, null, false, false, false);
} }
public static ChartInfo newInstance(ChartProvider chartProvider, String createTime, boolean isNew, boolean isReuse) { public static ChartInfo newInstance(ChartProvider chartProvider, String createTime, boolean isNew, boolean isReuse, boolean isAutoChart) {
HashMap<String, String> chartConsumingMap = new HashMap<>(); HashMap<String, String> chartConsumingMap = new HashMap<>();
String username = MarketConfig.getInstance().getBbsUsername(); String username = MarketConfig.getInstance().getBbsUsername();
@ -163,6 +165,13 @@ public class ChartInfo extends AbstractPointInfo {
chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, "0"); chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, "0");
chartConsumingMap.put(ATTR_IS_NEW, String.valueOf(isNew)); chartConsumingMap.put(ATTR_IS_NEW, String.valueOf(isNew));
chartConsumingMap.put(ATTR_IS_REUSE, String.valueOf(isReuse)); chartConsumingMap.put(ATTR_IS_REUSE, String.valueOf(isReuse));
if (isAutoChart) {
chartConsumingMap.put(ATTR_AUTO_CHART_CREATE_TIME, createTime);
chartConsumingMap.put(ATTR_AUTO_CHART_ENSURE_TIME, typeTime);
} else {
chartConsumingMap.put(ATTR_AUTO_CHART_CREATE_TIME, StringUtils.EMPTY);
chartConsumingMap.put(ATTR_AUTO_CHART_ENSURE_TIME, StringUtils.EMPTY);
}
ChartInfo chartInfo = new ChartInfo(chartId, templateId, book); ChartInfo chartInfo = new ChartInfo(chartId, templateId, book);
chartInfo.chartConsumingMap = chartConsumingMap; chartInfo.chartConsumingMap = chartConsumingMap;
@ -202,6 +211,9 @@ public class ChartInfo extends AbstractPointInfo {
writer.attr(ATTR_OVER_CHART_TYPE_COUNT, chartConsumingMap.get(ATTR_OVER_CHART_TYPE_COUNT)); writer.attr(ATTR_OVER_CHART_TYPE_COUNT, chartConsumingMap.get(ATTR_OVER_CHART_TYPE_COUNT));
writer.attr(ATTR_IS_NEW, chartConsumingMap.get(ATTR_IS_NEW)); writer.attr(ATTR_IS_NEW, chartConsumingMap.get(ATTR_IS_NEW));
writer.attr(ATTR_IS_REUSE, chartConsumingMap.get(ATTR_IS_REUSE)); writer.attr(ATTR_IS_REUSE, chartConsumingMap.get(ATTR_IS_REUSE));
writer.attr(ATTR_AUTO_CHART_CREATE_TIME, chartConsumingMap.get(ATTR_AUTO_CHART_CREATE_TIME));
writer.attr(ATTR_AUTO_CHART_ENSURE_TIME, chartConsumingMap.get(ATTR_AUTO_CHART_ENSURE_TIME));
writer.end(); writer.end();
chartConfigInfo.writeXML(writer); chartConfigInfo.writeXML(writer);
@ -238,6 +250,8 @@ public class ChartInfo extends AbstractPointInfo {
chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, reader.getAttrAsString(ATTR_OVER_CHART_TYPE_COUNT, "0")); chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, reader.getAttrAsString(ATTR_OVER_CHART_TYPE_COUNT, "0"));
chartConsumingMap.put(ATTR_IS_NEW, reader.getAttrAsString(ATTR_IS_NEW, StringUtils.EMPTY)); chartConsumingMap.put(ATTR_IS_NEW, reader.getAttrAsString(ATTR_IS_NEW, StringUtils.EMPTY));
chartConsumingMap.put(ATTR_IS_REUSE, reader.getAttrAsString(ATTR_IS_REUSE, StringUtils.EMPTY)); chartConsumingMap.put(ATTR_IS_REUSE, reader.getAttrAsString(ATTR_IS_REUSE, StringUtils.EMPTY));
chartConsumingMap.put(ATTR_AUTO_CHART_CREATE_TIME, reader.getAttrAsString(ATTR_AUTO_CHART_CREATE_TIME, StringUtils.EMPTY));
chartConsumingMap.put(ATTR_AUTO_CHART_ENSURE_TIME, reader.getAttrAsString(ATTR_AUTO_CHART_ENSURE_TIME, StringUtils.EMPTY));
} }
if (ChartConfigInfo.XML_TAG.equals(name)) { if (ChartConfigInfo.XML_TAG.equals(name)) {
this.chartConfigInfo = (ChartConfigInfo) reader.readXMLObject(new ChartConfigInfo()); this.chartConfigInfo = (ChartConfigInfo) reader.readXMLObject(new ChartConfigInfo());
@ -276,6 +290,10 @@ public class ChartInfo extends AbstractPointInfo {
} }
public void updateChartType(ChartProvider chartProvider) { public void updateChartType(ChartProvider chartProvider) {
updateChartType(chartProvider, false);
}
public void updateChartType(ChartProvider chartProvider, boolean isAutoChart) {
String typeTime = DateTime.now().toString("yyyy-MM-dd HH:mm:ss"); String typeTime = DateTime.now().toString("yyyy-MM-dd HH:mm:ss");
chartConsumingMap.put(ATTR_CHART_TYPE_TIME, typeTime); chartConsumingMap.put(ATTR_CHART_TYPE_TIME, typeTime);
@ -285,6 +303,9 @@ public class ChartInfo extends AbstractPointInfo {
String count = chartConsumingMap.get(ATTR_OVER_CHART_TYPE_COUNT); String count = chartConsumingMap.get(ATTR_OVER_CHART_TYPE_COUNT);
count = StringUtils.isEmpty(count) ? "1" : String.valueOf(Integer.parseInt(count) + 1); count = StringUtils.isEmpty(count) ? "1" : String.valueOf(Integer.parseInt(count) + 1);
chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, count); chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, count);
if (isAutoChart) {
chartConsumingMap.put(ATTR_AUTO_CHART_ENSURE_TIME, typeTime);
}
resetChartConfigInfo(chartProvider); resetChartConfigInfo(chartProvider);
} }

17
designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java

@ -12,6 +12,7 @@ import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.third.joda.time.DateTime; import com.fr.third.joda.time.DateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -49,18 +50,22 @@ public class ChartInfoCollector extends AbstractPointCollector<ChartInfo> {
} }
public void collection(ChartProvider chartProvider, String createTime) { public void collection(ChartProvider chartProvider, String createTime) {
collection(chartProvider, createTime, false); collection(chartProvider, createTime, false, false);
}
public void collection(ChartProvider chartProvider, String createTime, boolean isReuse) {
collection(chartProvider, createTime, isReuse, false);
} }
/** /**
* 新建图表保存状态 * 新建图表保存状态
*/ */
public void collection(ChartProvider chartProvider, String createTime, boolean isReuse) { public void collection(ChartProvider chartProvider, String createTime, boolean isReuse, boolean isAutoChart) {
String chartId = chartProvider.getChartUuid(); String chartId = chartProvider.getChartUuid();
if (!shouldCollectInfo() || StringUtils.isEmpty(chartId)) { if (!shouldCollectInfo() || StringUtils.isEmpty(chartId)) {
return; return;
} }
ChartInfo chartInfo = ChartInfo.newInstance(chartProvider, createTime, true, isReuse); ChartInfo chartInfo = ChartInfo.newInstance(chartProvider, createTime, true, isReuse, isAutoChart);
chartInfoCacheMap.put(chartId, chartInfo); chartInfoCacheMap.put(chartId, chartInfo);
} }
@ -116,6 +121,10 @@ public class ChartInfoCollector extends AbstractPointCollector<ChartInfo> {
* 图表类型变化更新类型和类型确认时间 * 图表类型变化更新类型和类型确认时间
*/ */
public void updateChartTypeTime(ChartProvider chartProvider, String oldType) { public void updateChartTypeTime(ChartProvider chartProvider, String oldType) {
updateChartTypeTime(chartProvider, oldType, false);
}
public void updateChartTypeTime(ChartProvider chartProvider, String oldType, boolean isAutoChart) {
if (!shouldCollectInfo() || StringUtils.isEmpty(chartProvider.getChartUuid())) { if (!shouldCollectInfo() || StringUtils.isEmpty(chartProvider.getChartUuid())) {
return; return;
} }
@ -123,7 +132,7 @@ public class ChartInfoCollector extends AbstractPointCollector<ChartInfo> {
ChartInfo chartInfo = getOrCreateChartInfo(chartProvider, oldType); ChartInfo chartInfo = getOrCreateChartInfo(chartProvider, oldType);
//更新类型确认时间和类型 //更新类型确认时间和类型
chartInfo.updateChartType(chartProvider); chartInfo.updateChartType(chartProvider, isAutoChart);
//重置计数 //重置计数
chartInfo.resetIdleDayCount(); chartInfo.resetIdleDayCount();

15
designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java

@ -7,6 +7,9 @@ import com.fr.chartx.TwoTuple;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.plugin.chart.vanchart.VanChart; import com.fr.plugin.chart.vanchart.VanChart;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.Component; import java.awt.Component;
import java.awt.Dialog; import java.awt.Dialog;
import java.awt.Frame; import java.awt.Frame;
@ -33,14 +36,22 @@ public class AutoChartDialog extends ChartDialog {
protected Component initCenterPane() { protected Component initCenterPane() {
autoChartTypePane = new AutoChartTypePane(); autoChartTypePane = new AutoChartTypePane();
getOk().setEnabled(false);
autoChartTypePane.registsListAction(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
getOk().setEnabled(((JList) e.getSource()).getSelectedIndex() >= 0);
}
});
return autoChartTypePane; return autoChartTypePane;
} }
protected ActionListener getActionListener() { protected ActionListener getActionListener(final String createTime) {
return new ActionListener() { return new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ChartCollection chartCollection = (ChartCollection) getChartCollection(); ChartCollection chartCollection = (ChartCollection) getChartCollection();
autoChartTypePane.update(chartCollection); autoChartTypePane.update(chartCollection, createTime);
if (chartCollection.getChartCount() > 0) { if (chartCollection.getChartCount() > 0) {
doOK(); doOK();
} else { } else {

2
designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java

@ -66,7 +66,7 @@ public class AutoChartIcon implements Icon {
public void paintIcon(Component c, Graphics g, int x, int y) { public void paintIcon(Component c, Graphics g, int x, int y) {
BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(), BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(),
WebChartIDInfo.createEmptyDesignerInfo(), getIconWidth(), getIconHeight()); WebChartIDInfo.createAutoTypeInfo(), getIconWidth(), getIconHeight());
int resolution = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getJTemplateResolution(); int resolution = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getJTemplateResolution();

122
designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java

@ -2,28 +2,42 @@ package com.fr.design.chart;
import com.fr.base.chart.chartdata.CallbackEvent; import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.ChartCollection;
import com.fr.chartx.attr.ChartProvider; import com.fr.design.chart.auto.AutoTypeCalculate;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataComboBox; import com.fr.design.data.datapane.TableDataComboBox;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombocheckbox.UIComboCheckBox; import com.fr.design.gui.icombocheckbox.UIComboCheckBox;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.iprogressbar.AutoProgressBar;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.chart.info.ChartInfoCollector;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.GeneralUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.vanchart.VanChart;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JSplitPane; import javax.swing.JSplitPane;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.SplitPaneUI;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CancellationException;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
@ -46,6 +60,9 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
private TableDataComboBox tableNameComboBox; private TableDataComboBox tableNameComboBox;
private UIComboCheckBox dataFieldBox; private UIComboCheckBox dataFieldBox;
private AutoProgressBar connectionBar;
private SwingWorker worker;
public AutoChartTypePane() { public AutoChartTypePane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
initButtonGroup(); initButtonGroup();
@ -62,10 +79,15 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
chartViewList.setCellRenderer(iconCellRenderer); chartViewList.setCellRenderer(iconCellRenderer);
JScrollPane subListPane = new JScrollPane(chartViewList); JScrollPane subListPane = new JScrollPane(chartViewList);
subListPane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Chart_Recommended_Chart")));
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, contentPane, subListPane);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, contentPane, subListPane); SplitPaneUI ui = splitPane.getUI();
if (ui instanceof BasicSplitPaneUI) {
((BasicSplitPaneUI) ui).getDivider().setBorder(null);
}
splitPane.setDividerLocation(60); splitPane.setDividerLocation(60);
splitPane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Chart_M_Popup_Auto_Chart_Type")));
this.add(splitPane); this.add(splitPane);
} }
@ -94,7 +116,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
JPanel tableDataPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); JPanel tableDataPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
panel.add(tableDataPane); panel.add(tableDataPane);
tableDataPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Table_Data") + ":")); tableDataPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Table_Data") + ":"));
tableNameComboBox.setPreferredSize(new Dimension(96, 20)); tableNameComboBox.setPreferredSize(new Dimension(126, 20));
tableDataPane.add(tableNameComboBox); tableDataPane.add(tableNameComboBox);
JPanel areaNamePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); JPanel areaNamePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
@ -102,6 +124,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
areaNamePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Data_Field") + ":")); areaNamePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Data_Field") + ":"));
areaNamePane.add(dataFieldBox); areaNamePane.add(dataFieldBox);
panel.add(refreshButton); panel.add(refreshButton);
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
return panel; return panel;
} }
@ -136,6 +159,10 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
} }
} }
public void registsListAction(ListSelectionListener listSelectionListener) {
chartViewList.addListSelectionListener(listSelectionListener);
}
private void refreshBox() { private void refreshBox() {
TableDataWrapper dataWrap = tableNameComboBox.getSelectedItem(); TableDataWrapper dataWrap = tableNameComboBox.getSelectedItem();
@ -154,6 +181,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
refreshButton.addActionListener(new ActionListener() { refreshButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
refreshButton.setEnabled(false);
calculateAutoChart(); calculateAutoChart();
} }
}); });
@ -161,7 +189,56 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
} }
private void calculateAutoChart() { private void calculateAutoChart() {
chartResultModel.clear(); connectionBar = new AutoProgressBar(this, Toolkit.i18nText("Fine-Design_Chart_Generate_Recommended_Chart"), "", 0, 100) {
public void doMonitorCanceled() {
refreshButton.setEnabled(true);
worker.cancel(true);
}
};
setWorker();
worker.execute();
}
private void setWorker() {
worker = new SwingWorker<List<VanChart>, Void>() {
protected List<VanChart> doInBackground() {
connectionBar.start();
chartResultModel.clear();
List<String> columnList = new ArrayList<>();
Object[] selectedValues = dataFieldBox.getSelectedValues();
for (Object value : selectedValues) {
columnList.add(GeneralUtils.objectToString(value));
}
List<VanChart> vanChartList = AutoTypeCalculate.calculateType(tableNameComboBox.getSelectedItem().getTableDataName(), columnList);
connectionBar.close();
return vanChartList;
}
public void done() {
try {
List<VanChart> vanChartList = get();
if (vanChartList != null && !vanChartList.isEmpty()) {
for (VanChart vanChart : vanChartList) {
ChartCollection chartCollection = new ChartCollection(vanChart);
AutoChartIcon autoChartIcon = new AutoChartIcon(chartCollection);
autoChartIcon.registerCallBackEvent(AutoChartTypePane.this);
chartResultModel.addElement(autoChartIcon);
}
chartViewList.setSelectedIndex(0);
}
} catch (Exception e) {
if (!(e instanceof CancellationException)) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
FineJOptionPane.showMessageDialog(AutoChartTypePane.this, e.getMessage(),
Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"));
}
} finally {
connectionBar.close();
refreshButton.setEnabled(true);
}
}
};
} }
@Override @Override
@ -171,16 +248,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
@Override @Override
public void update(ChartCollection cc) { public void update(ChartCollection cc) {
if (chartViewList.getSelectedIndex() < 0) { update(cc, null);
return;
}
AutoChartIcon chartIcon = (AutoChartIcon) chartViewList.getSelectedValue();
ChartProvider chartProvider = chartIcon.getChartCollection().getSelectedChartProvider(ChartProvider.class);
if (cc.getChartCount() > 0) {
cc.setSelectChart(chartProvider);
} else {
cc.addChart(chartProvider);
}
} }
public void populate(String tableName, String[] dataFields) { public void populate(String tableName, String[] dataFields) {
@ -190,6 +258,30 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent
map.put(dataField, true); map.put(dataField, true);
} }
dataFieldBox.setSelectedValues(map); dataFieldBox.setSelectedValues(map);
if (refreshButton.isEnabled()) {
refreshButton.setEnabled(false);
calculateAutoChart();
}
}
public void update(ChartCollection cc, String createTime) {
if (chartViewList.getSelectedIndex() < 0) {
return;
}
AutoChartIcon chartIcon = (AutoChartIcon) chartViewList.getSelectedValue();
VanChart vanChart = chartIcon.getChartCollection().getSelectedChartProvider(VanChart.class);
if (cc.getChartCount() > 0) {
VanChart selectedChartProvider = cc.getSelectedChartProvider(VanChart.class);
if (selectedChartProvider.getChartUuid() != null) {
vanChart.setUuid(selectedChartProvider.getChartUuid());
}
cc.setSelectChart(vanChart);
ChartInfoCollector.getInstance().updateChartTypeTime(vanChart, null, true);
} else {
cc.addChart(vanChart);
//记录埋点
ChartInfoCollector.getInstance().collection(vanChart, createTime, false, true);
}
} }
@Override @Override

18
designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java

@ -31,7 +31,6 @@ public class ChartDialog extends MiddleChartDialog {
private UIButton ok; private UIButton ok;
private UIButton cancel; private UIButton cancel;
private ChartTypePane chartTypePane; private ChartTypePane chartTypePane;
private String createTime;
public ChartDialog(Frame owner) { public ChartDialog(Frame owner) {
super(owner); super(owner);
@ -44,11 +43,14 @@ public class ChartDialog extends MiddleChartDialog {
} }
private void initComponent() { private void initComponent() {
createTime = DateTime.now().toString("yyyy-MM-dd HH:mm:ss"); String createTime = DateTime.now().toString("yyyy-MM-dd HH:mm:ss");
this.setModal(true); this.setModal(true);
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
setTitle(getDialogTitle()); setTitle(getDialogTitle());
ok = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_OK"));
cancel = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
this.applyClosingAction(); this.applyClosingAction();
this.applyEscapeAction(); this.applyEscapeAction();
this.setBasicDialogSize(BasicDialog.DEFAULT); this.setBasicDialogSize(BasicDialog.DEFAULT);
@ -58,10 +60,7 @@ public class ChartDialog extends MiddleChartDialog {
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
this.add(buttonPane, BorderLayout.SOUTH); this.add(buttonPane, BorderLayout.SOUTH);
ok = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_OK")); ok.addActionListener(getActionListener(createTime));
cancel = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
ok.addActionListener(getActionListener());
cancel.addActionListener(new ActionListener() { cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
doCancel(); doCancel();
@ -83,7 +82,7 @@ public class ChartDialog extends MiddleChartDialog {
return chartTypePane; return chartTypePane;
} }
protected ActionListener getActionListener() { protected ActionListener getActionListener(final String createTime) {
return new ActionListener() { return new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
chartTypePane.update((ChartCollection) cc, createTime); chartTypePane.update((ChartCollection) cc, createTime);
@ -92,6 +91,11 @@ public class ChartDialog extends MiddleChartDialog {
}; };
} }
public UIButton getOk() {
return ok;
}
/** /**
* 不处理 * 不处理
*/ */

143
designer-chart/src/main/java/com/fr/design/chart/auto/AutoTypeCalculate.java

@ -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;
}
}
Loading…
Cancel
Save