Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Session Breaks #514

Open
jinusean opened this issue Dec 7, 2023 · 4 comments
Open

[Feature] Session Breaks #514

jinusean opened this issue Dec 7, 2023 · 4 comments

Comments

@jinusean
Copy link

jinusean commented Dec 7, 2023

Feature Description

Draw a formatted line in between sessions, e.g. A line at start of a new day

To Do

An options in the styles

@liihuu
Copy link
Member

liihuu commented Dec 9, 2023

Custom indicator can do it.

@char101
Copy link

char101 commented Dec 11, 2023

Custom indicator can draw the lines but the xaxis labels will not be aligned. This is something that I have implemented before by changing the optimalTicks in xAxis.

diff --git a/src/component/XAxis.ts b/src/component/XAxis.ts
index d6f63c77..bac760ae 100644
--- a/src/component/XAxis.ts
+++ b/src/component/XAxis.ts
@@ -33,7 +33,48 @@ export default class XAxisImp extends AxisImp {
     }
   }
 
-  protected optimalTicks (ticks: AxisTick[]): AxisTick[] {
+  protected optimalTicks (_ticks: AxisTick[]): AxisTick[] {
+    const data = this.getParent().getChart().getDataList()
+    const { realMin, realMax } = this.getExtremum()
+    const ticks: AxisTick[] = []
+    const interval = (window as any).interval || '1d' // <--- need to read the interval value from somewhere
+    let prevPeriod = -1
+    for (let i = realMin; i <= realMax; ++i) {
+      const row = data[i]
+      const dt = new Date(row.timestamp)
+      switch (interval) {
+        case '1d':
+          const month = dt.getMonth()
+          if (month !== prevPeriod) {
+            ticks.push({text: `${dt.getFullYear().toString().substr(-2)}/${month + 1}`, coord: this.convertToPixel(i), value: i})
+          }
+          prevPeriod = month
+          break
+        case '1w':
+        case '1mo':
+          const year = dt.getFullYear()
+          if (year !== prevPeriod) {
+            ticks.push({text: `${year}`, coord: this.convertToPixel(i), value: i})
+            prevPeriod = year
+          }
+          break
+        case '5m':
+        case '10m':
+        case '15m':
+        case '30m':
+        case '1h':
+          const day = dt.getDate()
+          if (day !== prevPeriod) {
+            ticks.push({text: `${dt.getMonth() + 1}/${day}`, coord: this.convertToPixel(i), value: i})
+            prevPeriod = day
+          }
+          break
+      }
+    }
+    return ticks
+  }
+
+  protected xoptimalTicks (ticks: AxisTick[]): AxisTick[] {
     const chart = this.getParent().getChart()
     const chartStore = chart.getChartStore()
     const formatDate = chartStore.getCustomApi().formatDate

@liihuu
Copy link
Member

liihuu commented Dec 13, 2023

I don't quite understand

@jinusean
Copy link
Author

@liihuu
image

There's a line that appears at the start of day.
Would like an option to enable a line drawn at start of day, start of month, or a custom interval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants