diff --git a/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfo.java b/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfo.java index 4c546c4cd..9025b9806 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfo.java +++ b/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_IS_NEW = "isNew"; 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; // 判断图表是否可以上传的天数 @@ -122,10 +124,10 @@ public class ChartInfo extends AbstractPointInfo { } 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 chartConsumingMap = new HashMap<>(); 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_IS_NEW, String.valueOf(isNew)); 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.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_IS_NEW, chartConsumingMap.get(ATTR_IS_NEW)); 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(); 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_IS_NEW, reader.getAttrAsString(ATTR_IS_NEW, 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)) { this.chartConfigInfo = (ChartConfigInfo) reader.readXMLObject(new ChartConfigInfo()); @@ -276,6 +290,10 @@ public class ChartInfo extends AbstractPointInfo { } 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"); 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); count = StringUtils.isEmpty(count) ? "1" : String.valueOf(Integer.parseInt(count) + 1); chartConsumingMap.put(ATTR_OVER_CHART_TYPE_COUNT, count); + if (isAutoChart) { + chartConsumingMap.put(ATTR_AUTO_CHART_ENSURE_TIME, typeTime); + } resetChartConfigInfo(chartProvider); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java b/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java index 87dc8ca40..cd651fc6b 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/chart/info/ChartInfoCollector.java +++ b/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.XMLableReader; import com.fr.third.joda.time.DateTime; + import java.util.HashMap; import java.util.Map; @@ -49,18 +50,22 @@ public class ChartInfoCollector extends AbstractPointCollector { } 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(); if (!shouldCollectInfo() || StringUtils.isEmpty(chartId)) { return; } - ChartInfo chartInfo = ChartInfo.newInstance(chartProvider, createTime, true, isReuse); + ChartInfo chartInfo = ChartInfo.newInstance(chartProvider, createTime, true, isReuse, isAutoChart); chartInfoCacheMap.put(chartId, chartInfo); } @@ -116,6 +121,10 @@ public class ChartInfoCollector extends AbstractPointCollector { * 图表类型变化,更新类型和类型确认时间 */ 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())) { return; } @@ -123,7 +132,7 @@ public class ChartInfoCollector extends AbstractPointCollector { ChartInfo chartInfo = getOrCreateChartInfo(chartProvider, oldType); //更新类型确认时间和类型 - chartInfo.updateChartType(chartProvider); + chartInfo.updateChartType(chartProvider, isAutoChart); //重置计数 chartInfo.resetIdleDayCount(); diff --git a/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java b/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java index ddf4a0b40..34dacfa90 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java +++ b/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.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.Dialog; import java.awt.Frame; @@ -33,14 +36,22 @@ public class AutoChartDialog extends ChartDialog { protected Component initCenterPane() { 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; } - protected ActionListener getActionListener() { + protected ActionListener getActionListener(final String createTime) { return new ActionListener() { public void actionPerformed(ActionEvent e) { ChartCollection chartCollection = (ChartCollection) getChartCollection(); - autoChartTypePane.update(chartCollection); + autoChartTypePane.update(chartCollection, createTime); if (chartCollection.getChartCount() > 0) { doOK(); } else { diff --git a/designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java b/designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java index b85e2194c..6e347d34b 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java +++ b/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) { BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(), - WebChartIDInfo.createEmptyDesignerInfo(), getIconWidth(), getIconHeight()); + WebChartIDInfo.createAutoTypeInfo(), getIconWidth(), getIconHeight()); int resolution = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getJTemplateResolution(); diff --git a/designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java b/designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java index b546a330b..b7974fb6e 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java +++ b/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.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.datapane.TableDataComboBox; 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.icombocheckbox.UIComboCheckBox; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.iprogressbar.AutoProgressBar; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.chart.info.ChartInfoCollector; 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.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JList; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; 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.List; import java.util.Map; +import java.util.concurrent.CancellationException; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -46,6 +60,9 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent private TableDataComboBox tableNameComboBox; private UIComboCheckBox dataFieldBox; + private AutoProgressBar connectionBar; + private SwingWorker worker; + public AutoChartTypePane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); initButtonGroup(); @@ -62,10 +79,15 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent chartViewList.setCellRenderer(iconCellRenderer); 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.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Chart_M_Popup_Auto_Chart_Type"))); this.add(splitPane); } @@ -94,7 +116,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent JPanel tableDataPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); panel.add(tableDataPane); 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); 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(dataFieldBox); panel.add(refreshButton); + panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); return panel; } @@ -136,6 +159,10 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent } } + public void registsListAction(ListSelectionListener listSelectionListener) { + chartViewList.addListSelectionListener(listSelectionListener); + } + private void refreshBox() { TableDataWrapper dataWrap = tableNameComboBox.getSelectedItem(); @@ -154,6 +181,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + refreshButton.setEnabled(false); calculateAutoChart(); } }); @@ -161,7 +189,56 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent } 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, Void>() { + protected List doInBackground() { + connectionBar.start(); + chartResultModel.clear(); + List columnList = new ArrayList<>(); + Object[] selectedValues = dataFieldBox.getSelectedValues(); + for (Object value : selectedValues) { + columnList.add(GeneralUtils.objectToString(value)); + } + List vanChartList = AutoTypeCalculate.calculateType(tableNameComboBox.getSelectedItem().getTableDataName(), columnList); + connectionBar.close(); + return vanChartList; + } + + public void done() { + try { + List 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 @@ -171,16 +248,7 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent @Override public void update(ChartCollection cc) { - if (chartViewList.getSelectedIndex() < 0) { - return; - } - AutoChartIcon chartIcon = (AutoChartIcon) chartViewList.getSelectedValue(); - ChartProvider chartProvider = chartIcon.getChartCollection().getSelectedChartProvider(ChartProvider.class); - if (cc.getChartCount() > 0) { - cc.setSelectChart(chartProvider); - } else { - cc.addChart(chartProvider); - } + update(cc, null); } public void populate(String tableName, String[] dataFields) { @@ -190,6 +258,30 @@ public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent map.put(dataField, true); } 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 diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java b/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java index 9251bdbc8..4cd00e577 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java +++ b/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 cancel; private ChartTypePane chartTypePane; - private String createTime; public ChartDialog(Frame owner) { super(owner); @@ -44,11 +43,14 @@ public class ChartDialog extends MiddleChartDialog { } 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.setLayout(new BorderLayout()); 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.applyEscapeAction(); this.setBasicDialogSize(BasicDialog.DEFAULT); @@ -58,10 +60,7 @@ public class ChartDialog extends MiddleChartDialog { buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); this.add(buttonPane, BorderLayout.SOUTH); - 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")); - - ok.addActionListener(getActionListener()); + ok.addActionListener(getActionListener(createTime)); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doCancel(); @@ -83,7 +82,7 @@ public class ChartDialog extends MiddleChartDialog { return chartTypePane; } - protected ActionListener getActionListener() { + protected ActionListener getActionListener(final String createTime) { return new ActionListener() { public void actionPerformed(ActionEvent e) { chartTypePane.update((ChartCollection) cc, createTime); @@ -92,6 +91,11 @@ public class ChartDialog extends MiddleChartDialog { }; } + + public UIButton getOk() { + return ok; + } + /** * 不处理 */ diff --git a/designer-chart/src/main/java/com/fr/design/chart/auto/AutoTypeCalculate.java b/designer-chart/src/main/java/com/fr/design/chart/auto/AutoTypeCalculate.java new file mode 100644 index 000000000..db20af8cf --- /dev/null +++ b/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 calculateType(String tableName, List columns) { + List columnValue = calculateField(tableName, columns); + if (columnValue.isEmpty()) { + return new ArrayList<>(); + } + + List dimensions = new ArrayList<>(); + List 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 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 calculateField(String tableName, List 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 originalData = new ArrayList<>(); + for (String column : columns) { + List columnData = getColumnData(tableData, column); + if (columnData != null && !columnData.isEmpty()) { + originalData.add(new ColumnInfo(column, columnData)); + } + } + return originalData; + } + + private static List getColumnData(EmbeddedTableData tableData, String columnName) { + List 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; + } +} diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java index b363dc5f6..1fa61298a 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java @@ -111,12 +111,15 @@ public class ChartTypePane extends AbstractChartAttrPane { autoButtonListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + final String lastId = editingCollection.getSelectedChartProvider(ChartProvider.class).getID(); final MiddleChartDialog autoChartDialog = DesignModuleFactory.getAutoChartDialog(DesignerContext.getDesignerFrame()); autoChartDialog.populate(editingCollection); autoChartDialog.addDialogActionListener(new DialogActionAdapter() { @Override public void doOk() { populate(editingCollection); + ChartProvider chart = editingCollection.getSelectedChartProvider(ChartProvider.class); + reLayoutEditPane(chart, lastId); } }); autoChartDialog.setVisible(true); @@ -124,6 +127,17 @@ public class ChartTypePane extends AbstractChartAttrPane { }; } + private void reLayoutEditPane(ChartProvider chart, String lastChartId) { + String chartId = chart.getID(); + //chartID改变的话图表类型就算改变了 + if (StringUtils.isNotEmpty(chartId)) { + boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(chartId); + if (editPane.isDefaultPane() != isUseDefault || (!isUseDefault && !ComparatorUtils.equals(lastChartId, chartId))) { + editPane.reLayout(chart); + } + } + } + class ComboBoxPane extends UIComboBoxPane { private Map>> allChartTypePane; @@ -167,17 +181,7 @@ public class ChartTypePane extends AbstractChartAttrPane { //这一步会替换plot ((AbstractChartTypePane) getSelectedPane()).updateBean(chart); - String chartID = chart.getID(); - - //chartID改变的话图表类型就算改变了 - if (StringUtils.isNotEmpty(chartID)) { - - boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(chartID); - - if (editPane.isDefaultPane() != isUseDefault || (!isUseDefault && !ComparatorUtils.equals(lastPlotID, chartID))) { - editPane.reLayout(chart); - } - } + reLayoutEditPane(chart,lastPlotID); } protected UIComboBox createComboBox() { diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/axis/VanChartAxisScrollPaneWithTypeSelect.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/axis/VanChartAxisScrollPaneWithTypeSelect.java index 830bebf64..ef042e0f2 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/axis/VanChartAxisScrollPaneWithTypeSelect.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/axis/VanChartAxisScrollPaneWithTypeSelect.java @@ -102,21 +102,21 @@ public class VanChartAxisScrollPaneWithTypeSelect extends AbstractVanChartScroll if(ComparatorUtils.equals(axis.getAxisType(), AxisType.AXIS_CATEGORY)){ textAxisPane.updateBean(axis); } else { - axis = new VanChartAxis(axis.getAxisName(), axis.getPosition(), axis.getGridLineType()); + axis = new VanChartAxis(axis.getAxisName(), axis.getPosition(), axis.getGridLineType(), axis.getMainGridColor()); textAxisPane.updateBean(axis); } } else if(ComparatorUtils.equals(index, AxisType.AXIS_TIME.ordinal())){ if(ComparatorUtils.equals(axis.getAxisType(), AxisType.AXIS_TIME)){ timeAxisPane.updateBean(axis); } else { - axis = new VanChartTimeAxis(axis.getAxisName(), axis.getPosition(), axis.getGridLineType()); + axis = new VanChartTimeAxis(axis.getAxisName(), axis.getPosition(), axis.getGridLineType(), axis.getMainGridColor()); timeAxisPane.updateBean(axis); } } else if(ComparatorUtils.equals(index, AxisType.AXIS_VALUE.ordinal())){ if(ComparatorUtils.equals(axis.getAxisType(), AxisType.AXIS_VALUE)){ valueAxisPane.updateBean(axis); } else { - axis = new VanChartValueAxis(axis.getAxisName(), axis.getPosition(), axis.getGridLineType()); + axis = new VanChartValueAxis(axis.getAxisName(), axis.getPosition(), axis.getGridLineType(), axis.getMainGridColor()); valueAxisPane.updateBean(axis); } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index 9f5f36f66..1209310f6 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -262,7 +262,7 @@ public class SelectionModel { Rectangle rec = selection.getSelctionBounds(); FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); } else if (isExtraContainer(container)) { - provider.paste2Container(selection); + provider.paste2Container(clipboard); } } diff --git a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java index ff8a74e57..3abd0f3aa 100644 --- a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java +++ b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java @@ -9,7 +9,6 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; @@ -20,6 +19,7 @@ import com.fr.grid.selection.CellSelection; import com.fr.quickeditor.CellQuickEditor; import com.fr.report.ReportHelper; import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; import com.fr.stable.ColumnRow; import com.fr.stable.StringUtils; @@ -56,6 +56,9 @@ public class CellFormulaQuickEditor extends CellQuickEditor { //默认值 private static final String DEFAULT_FORMULA = "="; + //正在编辑的单元格 + private TemplateCellElement editingCellElement; + private DocumentListener documentListener = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -102,19 +105,27 @@ public class CellFormulaQuickEditor extends CellQuickEditor { formulaButton.setPreferredSize(new Dimension(20, formulaTextField.getPreferredSize().height)); formulaButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { - String text = formulaTextField.getText(); final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula(); - formulaPane.populate(BaseFormula.createFormulaBuilder().build(text)); + CellSelection cellSelection = (CellSelection) tc.getSelection(); + editingCellElement = tc.getEditingElementCase().getTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); + Object object = editingCellElement.getValue(); + if (object instanceof BaseFormula) { + formulaPane.populate((BaseFormula) object); + } else { + String text = formulaTextField.getText(); + formulaPane.populate(BaseFormula.createFormulaBuilder().build(text)); + } formulaPane.showLargeWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { @Override public void doOk() { BaseFormula fm = formulaPane.update(); if (fm.getContent().length() <= 1) { + fm.setContent(DEFAULT_FORMULA); formulaTextField.setText(DEFAULT_FORMULA); } else { formulaTextField.setText(fm.getContent()); } - + editingCellElement.setValue(fm); } }).setVisible(true); }