Skip to content

Commit

Permalink
Merge pull request LLWenke#39 from LLWenke/wk-dev
Browse files Browse the repository at this point in the history
1.K线module高度计算,边框计算,和布局算法优化 2.修复了缩放闪动的问题
  • Loading branch information
WENKE authored Aug 12, 2022
2 parents 2ff2662 + 226e0b6 commit 2d7f9d6
Show file tree
Hide file tree
Showing 56 changed files with 1,371 additions and 1,490 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions WKChart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
compileSdkVersion 32
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
Expand All @@ -17,14 +17,14 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt-2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9-native-mt-2'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.7'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.20"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.jetbrains:annotations:15.0'
}
50 changes: 25 additions & 25 deletions WKChart/src/main/java/com/wk/chart/ChartLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import com.wk.chart.drawing.CursorDrawing;
import com.wk.chart.drawing.ExtremumLabelDrawing;
import com.wk.chart.drawing.ExtremumTagDrawing;
import com.wk.chart.drawing.GridDrawing;
import com.wk.chart.drawing.GridLabelDrawing;
import com.wk.chart.drawing.GridLineDrawing;
import com.wk.chart.drawing.HighlightDrawing;
import com.wk.chart.drawing.IndexLabelDrawing;
import com.wk.chart.drawing.IndexLineDrawing;
Expand All @@ -28,6 +29,8 @@
import com.wk.chart.drawing.WaterMarkingDrawing;
import com.wk.chart.drawing.candle.CandleDrawing;
import com.wk.chart.drawing.candle.CandleSelectorDrawing;
import com.wk.chart.drawing.child.AxisTextMarker;
import com.wk.chart.drawing.child.GridTextMarker;
import com.wk.chart.drawing.depth.DepthDrawing;
import com.wk.chart.drawing.depth.DepthGridDrawing;
import com.wk.chart.drawing.depth.DepthHighlightDrawing;
Expand All @@ -45,8 +48,6 @@
import com.wk.chart.enumeration.PositionType;
import com.wk.chart.enumeration.RenderModel;
import com.wk.chart.interfaces.ICacheLoadListener;
import com.wk.chart.marker.AxisTextMarker;
import com.wk.chart.marker.GridTextMarker;
import com.wk.chart.module.CandleIndexModule;
import com.wk.chart.module.CandleModule;
import com.wk.chart.module.DepthModule;
Expand Down Expand Up @@ -96,7 +97,8 @@ protected void initCandleChartModules(AbsRender<?, ?> render) {
render.resetChartModules();
CandleModule candleModule = new CandleModule();
candleModule.addDrawing(new WaterMarkingDrawing());//水印组件
candleModule.addDrawing(new AxisDrawing(5, false));//x轴组件
candleModule.addDrawing(new AxisDrawing(5, false));//axis轴组件
candleModule.addDrawing(new GridLineDrawing());//grid轴组件
candleModule.addDrawing(new CandleDrawing());//蜡烛图组件
candleModule.addDrawing(new IndexLineDrawing(IndexType.CANDLE_MA));//MA组件
candleModule.addDrawing(new IndexLabelDrawing(IndexType.CANDLE_MA));//MA指标文字标签组件
Expand All @@ -111,14 +113,16 @@ protected void initCandleChartModules(AbsRender<?, ?> render) {

TimeLineModule timeLineModule = new TimeLineModule();
timeLineModule.addDrawing(new WaterMarkingDrawing());//水印组件
timeLineModule.addDrawing(new AxisDrawing(5, false));//x轴组件
timeLineModule.addDrawing(new AxisDrawing(5, false));//axis轴组件
timeLineModule.addDrawing(new GridLineDrawing());//grid轴组件
timeLineModule.addDrawing(new TimeLineDrawing());//分时图组件
timeLineModule.addDrawing(new BreathingLampDrawing());//呼吸灯组件
timeLineModule.addDrawing(new MarkerPointDrawing());//标记点绘制组件
timeLineModule.addDrawing(new BorderDrawing(PositionType.BOTTOM));//边框组件
render.addModule(timeLineModule);

VolumeModule volumeModule = new VolumeModule();
volumeModule.addDrawing(new GridLineDrawing());//grid轴组件
volumeModule.addDrawing(new VolumeDrawing());//交易量组件
volumeModule.addDrawing(new IndexLineDrawing(IndexType.VOLUME_MA));//MA组件
volumeModule.addDrawing(new IndexLabelDrawing(IndexType.VOLUME_MA));//MA指标文字标签组件
Expand All @@ -129,6 +133,7 @@ protected void initCandleChartModules(AbsRender<?, ?> render) {
render.addModule(volumeModule);

CandleIndexModule indexModule = new CandleIndexModule();
indexModule.addDrawing(new GridLineDrawing());//grid轴组件
indexModule.addDrawing(new MACDDrawing());//MACD 指标组件
indexModule.addDrawing(new IndexLabelDrawing(IndexType.MACD));//MACD 指标文字标签组件
indexModule.addDrawing(new IndexLineDrawing(IndexType.KDJ));//KDJ 指标线组件
Expand All @@ -142,13 +147,9 @@ protected void initCandleChartModules(AbsRender<?, ?> render) {
render.addModule(indexModule);

FloatModule floatModule = new FloatModule();
HighlightDrawing candleHighlight = new HighlightDrawing();
candleHighlight.addMarkerView(new AxisTextMarker());
candleHighlight.addMarkerView(new GridTextMarker());
floatModule.addDrawing(new GridDrawing());//Y轴组件
floatModule.addDrawing(candleHighlight);
floatModule.addDrawing(new GridLabelDrawing());
floatModule.addDrawing(new HighlightDrawing(new AxisTextMarker(), new GridTextMarker()));
floatModule.addDrawing(new CandleSelectorDrawing());
// floatModule.addDrawing(new BorderDrawing(BorderStyle.TOP));//边框组件
render.addModule(floatModule);
}

Expand All @@ -157,20 +158,17 @@ protected void initCandleChartModules(AbsRender<?, ?> render) {
*/
protected void initDepthChartModules(AbsRender<?, ?> render) {
DepthModule depthModule = new DepthModule();
depthModule.addDrawing(new AxisDrawing(5, true));//x轴组件
depthModule.addDrawing(new AxisDrawing(5, true));//axis轴组件
depthModule.addDrawing(new DepthGridDrawing());//grid轴组件
depthModule.addDrawing(new DepthDrawing());//深度图组件
depthModule.addDrawing(new BorderDrawing(PositionType.BOTTOM));
depthModule.addDrawing(new DepthHighlightDrawing(new AxisTextMarker(), new GridTextMarker()));//高亮组件
depthModule.addDrawing(new DepthSelectorDrawing());//选择器组件
depthModule.addDrawing(new BorderDrawing(PositionType.BOTTOM));//边框组件
depthModule.setEnable(true);
render.addModule(depthModule);

FloatModule floatModule = new FloatModule();
DepthHighlightDrawing depthHighlight = new DepthHighlightDrawing();
depthHighlight.addMarkerView(new AxisTextMarker());
depthHighlight.addMarkerView(new GridTextMarker());
floatModule.addDrawing(depthHighlight);
floatModule.addDrawing(new DepthGridDrawing());//Y轴组件
floatModule.addDrawing(new DepthSelectorDrawing());
floatModule.addDrawing(new BorderDrawing(PositionType.START | PositionType.END | PositionType.BOTTOM));
floatModule.addDrawing(new BorderDrawing(PositionType.START | PositionType.BOTTOM | PositionType.END));//边框组件
render.addModule(floatModule);
}

Expand Down Expand Up @@ -203,8 +201,8 @@ private void initChart() {
/**
* 切换图表组件
*
* @param moduleType 模型类型
* @param moduleGroupType 模型分组
* @param moduleType 模块类型
* @param moduleGroupType 模块分组
*/
public boolean switchModuleType(@ModuleType int moduleType, @ModuleGroupType int moduleGroupType) {
if (null == candleRender) {
Expand Down Expand Up @@ -234,7 +232,7 @@ public boolean switchModuleType(@ModuleType int moduleType, @ModuleGroupType int
* 切换图表指标
*
* @param indexType 指标类型
* @param moduleGroupType 模型分组
* @param moduleGroupType 模块分组
*/
public boolean switchIndexType(@IndexType int indexType, @ModuleGroupType int moduleGroupType) {
if (null == candleRender) {
Expand Down Expand Up @@ -282,7 +280,8 @@ ChartCache chartCache() {
}
ChartCache chartCache = new ChartCache();
chartCache.scale = candleRender.getAttribute().currentScale;
chartCache.beginPosition = candleRender.getBegin();
chartCache.cacheMaxScrollOffset = candleRender.getMaxScrollOffset();
chartCache.cacheCurrentTransX = candleRender.getCurrentTransX();
AbsAdapter<?, ?> adapter = candleRender.getAdapter();
if (adapter instanceof CandleAdapter) {
chartCache.timeType = ((CandleAdapter) adapter).getTimeType();
Expand All @@ -308,7 +307,8 @@ public void loadChartCache(@NotNull final ChartCache chartCache) {
}
boolean isNeedLoadData = false;
candleRender.getAttribute().currentScale = chartCache.scale;
candleRender.setFirstLoadPosition(chartCache.beginPosition);
candleRender.setCacheMaxScrollOffset(chartCache.cacheMaxScrollOffset);
candleRender.setCacheCurrentTransX(chartCache.cacheCurrentTransX);
AbsAdapter<?, ?> adapter = candleRender.getAdapter();
if (adapter instanceof CandleAdapter) {
CandleAdapter candleAdapter = (CandleAdapter) adapter;
Expand Down
Loading

0 comments on commit 2d7f9d6

Please sign in to comment.