Skip to content

Commit beb2f62

Browse files
committed
Added fibonacci tool
improved tools toolbox and tooltips Multiple tweaks
1 parent 68ab1e5 commit beb2f62

File tree

16 files changed

+1653
-130
lines changed

16 files changed

+1653
-130
lines changed

demo/qfchart-demo.html

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ <h1>QFChart Library Demo</h1>
122122
const chartContainer = document.getElementById("main-chart");
123123
const chart = new QFChart.QFChart(chartContainer, {
124124
title: "BTC/USDT", // Custom title
125-
height: "600px",
126-
tooltip: {
125+
height: "740px",
126+
databox: {
127127
position: "right",
128128
},
129129
dataZoom: {
@@ -135,25 +135,35 @@ <h1>QFChart Library Demo</h1>
135135
mainPaneHeight: "60%",
136136
gap: 5,
137137
},
138+
controls: {
139+
collapse: true,
140+
maximize: true,
141+
fullscreen: true,
142+
},
138143
});
139144

140145
// Set Market Data
141146
chart.setMarketData(ohlcvData);
142147

143148
chart.addIndicator("Institutional Bias", institBiasPlots, {
144149
isOverlay: true,
145-
height: 10,
150+
height: 14,
146151
titleColor: "#2962FF",
147152
});
148153

149154
// Set Indicators
150155
// Group plots into one indicator
151-
chart.addIndicator("SQZMOM", plots, { isOverlay: false, height: 10 });
156+
chart.addIndicator("SQZMOM", plots, {
157+
isOverlay: false,
158+
height: 14,
159+
controls: { collapse: true, maximize: true },
160+
});
152161

153162
chart.addIndicator("MACD", macdPlots, {
154163
isOverlay: false,
155164
height: 10,
156165
titleColor: "#ff9900",
166+
controls: { collapse: true, maximize: true },
157167
});
158168

159169
// Register Measure Tool Plugin
@@ -163,6 +173,36 @@ <h1>QFChart Library Demo</h1>
163173
// Register Line Tool Plugin
164174
const lineTool = new QFChart.LineTool();
165175
chart.registerPlugin(lineTool);
176+
177+
// Register Fibonacci Tool Plugin
178+
const fibTool = new QFChart.FibonacciTool();
179+
chart.registerPlugin(fibTool);
180+
181+
// Logging Event Listeners for Drawing Tools
182+
chart.events.on("drawing:hover", (payload) =>
183+
console.log("Event: drawing:hover", payload)
184+
);
185+
chart.events.on("drawing:mouseout", (payload) =>
186+
console.log("Event: drawing:mouseout", payload)
187+
);
188+
chart.events.on("drawing:mousedown", (payload) =>
189+
console.log("Event: drawing:mousedown", payload)
190+
);
191+
chart.events.on("drawing:click", (payload) =>
192+
console.log("Event: drawing:click", payload)
193+
);
194+
chart.events.on("drawing:point:hover", (payload) =>
195+
console.log("Event: drawing:point:hover", payload)
196+
);
197+
chart.events.on("drawing:point:mouseout", (payload) =>
198+
console.log("Event: drawing:point:mouseout", payload)
199+
);
200+
chart.events.on("drawing:point:mousedown", (payload) =>
201+
console.log("Event: drawing:point:mousedown", payload)
202+
);
203+
chart.events.on("drawing:point:click", (payload) =>
204+
console.log("Event: drawing:point:click", payload)
205+
);
166206
});
167207
</script>
168208
</body>

docs/api.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Adds an indicator to the chart.
3737
- **options**:
3838
- `isOverlay`: (boolean) If `true`, renders on the main chart. If `false`, creates a new pane below.
3939
- `height`: (number) Height percentage for the new pane (e.g., `15` for 15%).
40+
- `controls`: (object) Control buttons configuration.
41+
- `collapse`: (boolean) Show collapse/expand button.
42+
- `maximize`: (boolean) Show maximize/restore pane button.
4043

4144
#### `removeIndicator(id: string)`
4245

@@ -56,8 +59,9 @@ Adds a persistent drawing (like a line or shape) to the chart. These drawings mo
5659
```typescript
5760
interface DrawingElement {
5861
id: string;
59-
type: "line";
62+
type: "line" | "fibonacci";
6063
points: DataCoordinate[]; // [{ timeIndex, value }, ...]
64+
paneIndex?: number;
6165
style?: { color?: string; lineWidth?: number };
6266
}
6367
```
@@ -82,16 +86,17 @@ Cleans up event listeners and disposes of the ECharts instance.
8286

8387
Configuration object passed to the constructor.
8488

85-
| Property | Type | Default | Description |
86-
| ----------------- | -------------------- | -------------------------- | ---------------------------------------- |
87-
| `title` | `string` | `"Market"` | Main chart title displayed in tooltip. |
88-
| `height` | `string` \| `number` | - | Explicit height for the container. |
89-
| `padding` | `number` | `0.2` | Vertical padding for auto-scaling (0-1). |
90-
| `upColor` | `string` | `"#00da3c"` | Color for bullish candles. |
91-
| `downColor` | `string` | `"#ec0000"` | Color for bearish candles. |
92-
| `backgroundColor` | `string` | `"#1e293b"` | Chart background color. |
93-
| `tooltip` | `object` | `{ position: 'floating' }` | Tooltip configuration (see Layouts). |
94-
| `dataZoom` | `object` | - | Configuration for the zoom slider. |
89+
| Property | Type | Default | Description |
90+
| ----------------- | -------------------- | -------------------------- | -------------------------------------------------------------- |
91+
| `title` | `string` | `"Market"` | Main chart title displayed in databox. |
92+
| `height` | `string` \| `number` | - | Explicit height for the container. |
93+
| `padding` | `number` | `0.2` | Vertical padding for auto-scaling (0-1). |
94+
| `upColor` | `string` | `"#00da3c"` | Color for bullish candles. |
95+
| `downColor` | `string` | `"#ec0000"` | Color for bearish candles. |
96+
| `backgroundColor` | `string` | `"#1e293b"` | Chart background color. |
97+
| `databox` | `object` | `{ position: 'floating' }` | Databox configuration (see Layouts). |
98+
| `dataZoom` | `object` | - | Configuration for the zoom slider. |
99+
| `controls` | `object` | `{}` | Enable control buttons (`collapse`, `maximize`, `fullscreen`). |
95100

96101
### `OHLCV`
97102

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permalink: /
1414
- **Candlestick Charts**: High-performance rendering of OHLCV data.
1515
- **Multi-Pane Indicators**: Support for stacking indicators in separate panes (e.g., RSI, MACD) with customizable heights.
1616
- **Overlay Indicators**: Add indicators directly on top of the main chart (e.g., SMA, Bollinger Bands).
17-
- **Flexible Layouts**: Configurable sidebars for tooltips (Left/Right/Floating) to avoid obstructing the chart.
17+
- **Flexible Layouts**: Configurable sidebars for data display (Left/Right/Floating) to avoid obstructing the chart.
1818
- **Dynamic Resizing**: Automatically handles window resizing and layout adjustments.
1919
- **Plugin System**: Extensible architecture for adding interactive tools (e.g., Measure Tool).
2020
- **TypeScript Support**: Written in TypeScript with full type definitions.

docs/layout-and-customization.md

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,34 @@ permalink: /layout
99

1010
QFChart offers flexible layout options to adapt to different screen sizes and user preferences.
1111

12-
## Tooltip Positioning
12+
## Databox Positioning
1313

14-
The tooltip is the primary way to view precise values. You can configure its behavior using `options.tooltip.position`.
14+
The databox is the primary way to view precise values. You can configure its behavior using `options.databox.position`.
1515

1616
### Modes
1717

1818
1. **Floating (Default)**
19+
1920
- Follows the mouse cursor.
2021
- Automatically switches sides to avoid going off-screen.
2122
- Best for maximizing chart space.
2223

2324
```javascript
24-
tooltip: {
25-
position: 'floating'
25+
databox: {
26+
position: "floating";
2627
}
2728
```
2829

2930
2. **Sidebar (Left/Right)**
31+
3032
- Dedicates a fixed sidebar (250px) for data display.
3133
- Chart automatically resizes to fill remaining width.
32-
- Prevents the tooltip from obscuring the chart data.
34+
- Prevents the databox from obscuring the chart data.
3335
- Ideal for desktop views with detailed indicators.
3436

3537
```javascript
36-
tooltip: {
37-
position: 'left' // or 'right'
38+
databox: {
39+
position: "left"; // or 'right'
3840
}
3941
```
4042

@@ -48,24 +50,59 @@ You can specify the height of each indicator pane as a percentage of the total c
4850

4951
```javascript
5052
// Add RSI with 15% height
51-
chart.addIndicator("RSI", rsiPlots, {
52-
isOverlay: false,
53-
height: 15
53+
chart.addIndicator("RSI", rsiPlots, {
54+
isOverlay: false,
55+
height: 15,
5456
});
5557

5658
// Add MACD with 20% height
57-
chart.addIndicator("MACD", macdPlots, {
58-
isOverlay: false,
59-
height: 20
59+
chart.addIndicator("MACD", macdPlots, {
60+
isOverlay: false,
61+
height: 20,
6062
});
6163
```
6264

6365
**Layout Algorithm:**
66+
6467
1. Sums up all explicit indicator heights.
6568
2. Calculates gaps (default 20px dynamic equivalent).
6669
3. Allocates remaining space to the Main Chart (Candlesticks).
6770
4. If remaining space is too small (<20%), it clamps the main chart height.
6871

72+
## Pane Controls
73+
74+
You can enable interactive controls for each pane (Main Chart and Indicators) to allow users to customize their view at runtime.
75+
76+
### Available Controls
77+
78+
- **Collapse (`+` / ``)**: Minimizes the pane to a small strip, giving more space to other panes.
79+
- **Maximize (`` / ``)**: Expands the pane to fill the entire chart container (viewport), hiding other panes.
80+
- **Fullscreen (``)**: Expands the chart container to fill the entire monitor screen (Browser Fullscreen). _Only available for Main Chart._
81+
82+
### Configuration
83+
84+
Controls are configured via the `controls` object in `QFChartOptions` (for the main chart) or the options object in `addIndicator`.
85+
86+
```javascript
87+
// Main Chart Configuration
88+
const chart = new QFChart(container, {
89+
controls: {
90+
collapse: true, // Enable collapse button
91+
maximize: true, // Enable maximize pane button
92+
fullscreen: true, // Enable browser fullscreen button
93+
},
94+
});
95+
96+
// Indicator Configuration
97+
chart.addIndicator("MACD", plots, {
98+
isOverlay: false,
99+
controls: {
100+
collapse: true,
101+
maximize: true,
102+
},
103+
});
104+
```
105+
69106
## DataZoom Control
70107

71108
The zoom slider allows users to navigate history.
@@ -81,4 +118,3 @@ dataZoom: {
81118
- **Top**: Places slider at the very top. Chart starts below.
82119
- **Bottom**: Places slider at the bottom.
83120
- **Hidden**: Set `visible: false` to control zoom only via mouse wheel/drag.
84-

docs/plugins.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ The `MeasureTool` is a built-in plugin that allows users to measure price and ti
3939
3. **Click** again to finish and freeze the measurement.
4040
4. **Click** anywhere else or drag the chart to clear the measurement.
4141

42+
### Fibonacci Tool
43+
44+
The `FibonacciTool` allows users to draw Fibonacci retracement levels on the chart.
45+
46+
- **Usage**: Click the Fibonacci icon in the toolbar.
47+
- **Interaction**:
48+
1. **Click** to set the start point (e.g., swing high).
49+
2. **Move** mouse to set the end point (e.g., swing low).
50+
3. **Click** to finish drawing.
51+
- **Levels**: 0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.
52+
4253
## Creating Custom Plugins
4354

4455
You can create your own plugins by extending the `AbstractPlugin` class or implementing the `Plugin` interface directly. We recommend extending `AbstractPlugin` as it provides useful helpers and automatic event cleanup.
@@ -112,8 +123,9 @@ export interface ChartContext {
112123

113124
export interface DrawingElement {
114125
id: string;
115-
type: "line";
126+
type: "line" | "fibonacci";
116127
points: DataCoordinate[];
128+
paneIndex?: number;
117129
style?: {
118130
color?: string;
119131
lineWidth?: number;
@@ -129,6 +141,31 @@ The chart exposes an Event Bus via `context.events` for communication between pl
129141
- `chart:resize`, `chart:dataZoom`, `chart:updated`
130142
- `plugin:activated`, `plugin:deactivated`
131143

144+
#### Drawing Events
145+
146+
When using the native drawing system (via `addDrawing`), the chart emits granular events for interactions with drawing elements:
147+
148+
- **Shape Events**:
149+
- `drawing:hover`: Mouse over a drawing shape (e.g., line).
150+
- `drawing:mouseout`: Mouse out of a drawing shape.
151+
- `drawing:mousedown`: Mouse down on a drawing shape.
152+
- `drawing:click`: Click on a drawing shape.
153+
- **Control Point Events**:
154+
- `drawing:point:hover`: Mouse over a control point (start/end).
155+
- `drawing:point:mouseout`: Mouse out of a control point.
156+
- `drawing:point:mousedown`: Mouse down on a control point.
157+
- `drawing:point:click`: Click on a control point.
158+
159+
All drawing events carry a payload identifying the drawing:
160+
161+
```typescript
162+
{
163+
id: string, // The ID of the drawing
164+
type?: string, // The type of drawing (e.g., "line")
165+
pointIndex?: number // For point events: 0 (start), 1 (end), etc.
166+
}
167+
```
168+
132169
### Coordinate Conversion & Native Drawings
133170

134171
For persistent drawings (lines, shapes that stick to the chart), you should use the `addDrawing` API instead of manual ZRender management.

0 commit comments

Comments
 (0)