You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
266 lines
10 KiB
266 lines
10 KiB
package com.fr.van.chart.config; |
|
|
|
import com.fr.base.ChartColorMatching; |
|
import com.fr.base.ChartPreStyleConfig; |
|
import com.fr.chart.base.AttrBorder; |
|
import com.fr.chart.base.AttrFillStyle; |
|
import com.fr.chart.base.ChartConstants; |
|
import com.fr.chart.base.ChartThemeStyleProvider; |
|
import com.fr.chart.chartattr.Plot; |
|
import com.fr.chart.chartglyph.ConditionAttr; |
|
import com.fr.chart.chartglyph.DataSheet; |
|
import com.fr.chartx.attr.ChartProvider; |
|
import com.fr.config.predefined.ColorFillStyle; |
|
import com.fr.design.fun.DefaultValueAdjustProvider; |
|
import com.fr.design.mainframe.chart.mode.ChartEditContext; |
|
import com.fr.design.utils.DesignUtils; |
|
import com.fr.plugin.chart.PiePlot4VanChart; |
|
import com.fr.plugin.chart.attr.axis.VanChartAlertValue; |
|
import com.fr.plugin.chart.attr.axis.VanChartAxis; |
|
import com.fr.plugin.chart.attr.axis.VanChartAxisLabelStyle; |
|
import com.fr.plugin.chart.attr.plot.VanChartPlot; |
|
import com.fr.plugin.chart.attr.plot.VanChartRectanglePlot; |
|
import com.fr.plugin.chart.base.AttrLabel; |
|
import com.fr.plugin.chart.base.AttrLabelDetail; |
|
import com.fr.plugin.chart.custom.type.CustomPlotType; |
|
import com.fr.plugin.chart.gauge.VanChartGaugePlot; |
|
import com.fr.plugin.chart.map.VanChartMapPlot; |
|
import com.fr.plugin.chart.type.GaugeStyle; |
|
import com.fr.plugin.chart.vanchart.VanChart; |
|
|
|
import java.util.ArrayList; |
|
import java.util.Arrays; |
|
import java.util.List; |
|
|
|
/** |
|
* @author shine |
|
* @version 10.0 |
|
* Created by shine on 2021/10/22 |
|
* vanchart的抽出来,因为主体代码 新增y轴 组合图新增图表都要用 |
|
*/ |
|
public class DefaultStyleHelper4Van { |
|
|
|
private static boolean duchampMode() { |
|
try { |
|
return ChartEditContext.duchampMode(); |
|
} catch (Throwable e) { |
|
//tomcat预览 默认数据的图表 |
|
return true; |
|
} |
|
} |
|
|
|
public static void checkChartDefaultStyle4Duchamp(ChartProvider chartProvider) { |
|
if (!ChartEditContext.supportTheme() && chartProvider instanceof VanChart) { |
|
//主题中有的属性 界面上屏蔽不跟随主题 属性全部设置成自定义 |
|
((VanChart) chartProvider).setThemeCustom(); |
|
dealChartColor((VanChart) chartProvider); |
|
// //主题中没有的 根据主题深浅色自动 的属性 默认自动 |
|
// ((VanChart) chart4Update).setAutoThemeCustom(); |
|
DefaultValueAdjustProvider adjustProvider = DesignUtils.getValueAdjust(); |
|
if (adjustProvider != null) { |
|
adjustProvider.adjustChart(chartProvider); |
|
} |
|
} |
|
|
|
} |
|
|
|
public static void dealVanPlot4Custom(VanChartPlot plot, CustomPlotType customPlotType) { |
|
if (!duchampMode()) { |
|
return; |
|
} |
|
dealVanPlotCommonAttr(plot); |
|
switch (customPlotType) { |
|
case PIE: |
|
case DIFFERENT_PIE: |
|
case SAME_PIE: |
|
dealPie(plot); |
|
break; |
|
case SLOT: |
|
case POINTER_360: |
|
case POINTER_180: |
|
case CUVETTE: |
|
case RING: |
|
dealGauge(plot); |
|
break; |
|
case COLUMN: |
|
case LINE: |
|
case AREA: |
|
case BUBBLE: |
|
case RADAR: |
|
case STACK_RADAR: |
|
case SCATTER: |
|
default: |
|
break; |
|
} |
|
|
|
} |
|
|
|
private static void dealAxisCheckTheme(VanChartAxis axis) { |
|
if (!ChartEditContext.supportTheme()) { |
|
List<ChartThemeStyleProvider> chartThemeStyleProviders = new ArrayList<>(); |
|
VanChartRectanglePlot.getAxisChartPreStyleProvider(axis, chartThemeStyleProviders); |
|
for (ChartThemeStyleProvider themeStyleProvider : chartThemeStyleProviders) { |
|
themeStyleProvider.setThemeCustom(); |
|
} |
|
} |
|
} |
|
|
|
public static VanChartAxisLabelStyle dealAxisCheckTheme(VanChartAxisLabelStyle labelStyle) { |
|
if (!ChartEditContext.supportTheme()) { |
|
labelStyle.getTextAttr().setThemeCustom(); |
|
} |
|
return labelStyle; |
|
} |
|
|
|
|
|
public static VanChartAxis dealAxisDefault(VanChartAxis axis) { |
|
|
|
dealAxisCheckTheme(axis); |
|
|
|
if (!duchampMode()) { |
|
return axis; |
|
} |
|
axis.getTitle().getTextAttr().setFRFont(DefaultStyleConstants.AXIS_TITLE); |
|
axis.getTextAttr().setFRFont(DefaultStyleConstants.AXIS_LABEL); |
|
axis.setAxisColor(DefaultStyleConstants.AXIS_LINE); |
|
axis.setMainGridColor(DefaultStyleConstants.GRID_LINE); |
|
return axis; |
|
} |
|
|
|
public static void dealAxisAlert(VanChartAlertValue vanChartAlertValue) { |
|
if (!duchampMode()) { |
|
return; |
|
} |
|
vanChartAlertValue.setAlertFont(DefaultStyleConstants.ALERT_FONT); |
|
} |
|
|
|
static void dealVanPlotCommonAttr(Plot plot) { |
|
if (!duchampMode()) { |
|
return; |
|
} |
|
if (plot instanceof VanChartPlot) { |
|
VanChartPlot vanChartPlot = (VanChartPlot) plot; |
|
|
|
dealChartColor(vanChartPlot); |
|
|
|
if (vanChartPlot.getLegend() != null) { |
|
vanChartPlot.getLegend().setFRFont(DefaultStyleConstants.LEGEND); |
|
} |
|
|
|
if (vanChartPlot instanceof VanChartRectanglePlot) { |
|
VanChartRectanglePlot vanChartRectanglePlot = (VanChartRectanglePlot) vanChartPlot; |
|
|
|
for (VanChartAxis axis : vanChartRectanglePlot.getXAxisList()) { |
|
dealAxisDefault(axis); |
|
} |
|
for (VanChartAxis axis : vanChartRectanglePlot.getYAxisList()) { |
|
dealAxisDefault(axis); |
|
} |
|
} |
|
|
|
dealBorder(vanChartPlot); |
|
|
|
DataSheet dataSheet = vanChartPlot.getDataSheet(); |
|
dataSheet.getTextAttr().setFRFont(DefaultStyleConstants.DATA_SHEET); |
|
dataSheet.setBorderColor(DefaultStyleConstants.DATA_SHEET_BORDER); |
|
} |
|
|
|
} |
|
|
|
private static void dealChartColor(VanChart vanChart) { |
|
dealChartColor(vanChart.getPlot()); |
|
} |
|
|
|
private static void dealChartColor(VanChartPlot vanChartPlot) { |
|
ChartPreStyleConfig manager = ChartPreStyleConfig.getInstance(); |
|
Object preStyle = manager.getPreStyle(DefaultStyleConstants.COLORS); |
|
ColorFillStyle colorFillStyle = new ColorFillStyle(); |
|
if (preStyle instanceof ChartColorMatching) { |
|
//default是默认的意思,为服务器默认配色方案 |
|
//acc为多个颜色组合 |
|
//gradient为渐变颜色 |
|
colorFillStyle.setColorStyle(ChartConstants.COLOR_ACC); |
|
colorFillStyle.setFillStyleName(DefaultStyleConstants.COLORS); |
|
colorFillStyle.setColorList(((ChartColorMatching) preStyle).getColorList()); |
|
} else { |
|
//服务器上没有图表配色 |
|
//需要指定配色属性为自定义组合色,否则会被兼容成跟随主题 |
|
// com.fr.plugin.chart.attr.plot.VanChartPlot.compatibleFillStyle |
|
colorFillStyle.setColorStyle(ChartConstants.COLOR_ACC); |
|
colorFillStyle.setColorList(Arrays.asList(ChartConstants.NEW_FEATURES)); |
|
} |
|
|
|
AttrFillStyle plotFillStyle = vanChartPlot.getPlotFillStyle(); |
|
if (plotFillStyle == null) { |
|
plotFillStyle = new AttrFillStyle(); |
|
vanChartPlot.setPlotFillStyle(plotFillStyle); |
|
} |
|
plotFillStyle.setColorFillStyle(colorFillStyle); |
|
} |
|
|
|
private static void dealBorder(VanChartPlot vanChartPlot) { |
|
ConditionAttr defaultAttr = vanChartPlot.getConditionCollection().getDefaultAttr(); |
|
AttrBorder attrBorder = defaultAttr.getExisted(AttrBorder.class); |
|
if (attrBorder != null) { |
|
attrBorder.setBorderColor(DefaultStyleConstants.BORDER); |
|
attrBorder.setBorderStyle(defaultBorderWidth(vanChartPlot)); |
|
} |
|
} |
|
|
|
private static int defaultBorderWidth(VanChartPlot vanChartPlot) { |
|
//pie multipie treemap map drillmap heatmap |
|
if (vanChartPlot instanceof PiePlot4VanChart |
|
|| vanChartPlot instanceof VanChartMapPlot) { |
|
return DefaultStyleConstants.SPECIAL_BORDER_WIDTH; |
|
} |
|
return DefaultStyleConstants.BORDER_WIDTH; |
|
} |
|
|
|
static void dealPie(Plot plot) { |
|
if (plot instanceof PiePlot4VanChart) { |
|
ConditionAttr defaultAttr = plot.getConditionCollection().getDefaultAttr(); |
|
AttrLabel attrLabel = defaultAttr.getExisted(AttrLabel.class); |
|
if (attrLabel == null) { |
|
attrLabel = ((PiePlot4VanChart) plot).getDefaultAttrLabel(); |
|
defaultAttr.addDataSeriesCondition(attrLabel); |
|
} |
|
attrLabel.getSecondLabelDetail().getTextAttr().setFRFont(DefaultStyleConstants.PIE_CATEGORY_LABEL); |
|
} |
|
} |
|
|
|
static void dealGauge(Plot param) { |
|
if (!(param instanceof VanChartGaugePlot)) { |
|
return; |
|
} |
|
VanChartGaugePlot plot = (VanChartGaugePlot) param; |
|
plot.getGaugeDetailStyle().setPaneBackgroundColor(plot.getGaugeStyle() == GaugeStyle.RING ? DefaultStyleConstants.GAUGE_PANE_BACK_COLOR_4_RING : DefaultStyleConstants.GAUGE_PANE_BACK_COLOR); |
|
plot.getGaugeDetailStyle().setSlotBackgroundColor(DefaultStyleConstants.GAUGE_SLOT_BACKGROUND_COLOR); |
|
plot.getGaugeDetailStyle().setHingeColor(DefaultStyleConstants.GAUGE_HINGE); |
|
|
|
ConditionAttr defaultAttr = plot.getConditionCollection().getDefaultAttr(); |
|
AttrLabel attrLabel = defaultAttr.getExisted(AttrLabel.class); |
|
if (attrLabel != null) { |
|
AttrLabelDetail detail = attrLabel.getAttrLabelDetail(); |
|
AttrLabelDetail valueDetail = attrLabel.getGaugeValueLabelDetail(); |
|
|
|
switch (plot.getGaugeStyle()) { |
|
case POINTER: |
|
case POINTER_SEMI: |
|
detail.getContent().getCategoryFormat().setEnable(false); |
|
detail.getTextAttr().setFRFont(DefaultStyleConstants.POINTER_CATE_LABEL_FONT); |
|
valueDetail.getTextAttr().setFRFont(DefaultStyleConstants.POINTER_VALUE_LABEL_FONT); |
|
break; |
|
case RING: |
|
case SLOT: |
|
valueDetail.getTextAttr().setFRFont(DefaultStyleConstants.RING_VALUE_LABEL_FONT); |
|
break; |
|
case THERMOMETER: |
|
detail.getTextAttr().setFRFont(DefaultStyleConstants.THERMOMETER_LABEL_FONT); |
|
valueDetail.getTextAttr().setFRFont(DefaultStyleConstants.THERMOMETER_LABEL_FONT); |
|
plot.getGaugeAxis().getTextAttr().setFRFont(DefaultStyleConstants.THERMOMETER_AXIS_LABEL); |
|
break; |
|
} |
|
|
|
} |
|
} |
|
}
|
|
|