Skip to content

Commit 3984bb7

Browse files
author
Mischa Spelt
committed
Add configuration class for chart.js Zoom plugin.
1 parent 3bbf5a9 commit 3984bb7

File tree

3 files changed

+309
-0
lines changed

3 files changed

+309
-0
lines changed

blazorbootstrap/Enums/DrawTime.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace BlazorBootstrap;
2+
3+
public enum DrawTime
4+
{
5+
/// <summary>
6+
/// Occurs before any drawing takes place
7+
/// </summary>
8+
BeforeDraw,
9+
10+
/// <summary>
11+
/// Occurs after drawing of axes, but before datasets
12+
/// </summary>
13+
BeforeDatasetsDraw,
14+
15+
/// <summary>
16+
/// Occurs after drawing of datasets but before items such as the tooltip
17+
/// </summary>
18+
AfterDatasetsDraw,
19+
20+
/// <summary>
21+
/// After other drawing is completed.
22+
/// </summary>
23+
AfterDraw
24+
}
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace BlazorBootstrap;
8+
9+
public enum ZoomMode
10+
{
11+
None,
12+
X,
13+
Y,
14+
XY
15+
}
16+
17+
public enum ModifierKey
18+
{
19+
None,
20+
Ctrl,
21+
Alt,
22+
Shift,
23+
Meta
24+
}
25+
26+
public class ZoomLimitAxisOptions
27+
{
28+
/// <summary>
29+
/// Minimum allowed value for scale.min
30+
/// </summary>
31+
[JsonIgnore]
32+
public double? Min { get; set; }
33+
34+
[JsonIgnore]
35+
public bool? MinimumIsOriginal { get; set; }
36+
37+
[JsonInclude]
38+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
39+
[JsonPropertyName( "min" )]
40+
private string? minText => MinimumIsOriginal.GetValueOrDefault() ? "original" : Min?.ToString();
41+
42+
/// <summary>
43+
/// Maximum allowed value for scale.max
44+
/// </summary>
45+
[JsonIgnore]
46+
public double? Max { get; set; }
47+
48+
[JsonIgnore]
49+
public bool? MaximumIsOriginal { get; set; }
50+
51+
[JsonInclude]
52+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
53+
[JsonPropertyName( "max" )]
54+
private string? maxText => MaximumIsOriginal.GetValueOrDefault() ? "original" : Max?.ToString();
55+
56+
/// <summary>
57+
/// Minimum allowed range (max - min). This defines the max zoom level.
58+
/// </summary>
59+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
60+
[JsonPropertyName( "minRange" )]
61+
public double? MinRange { get; set; }
62+
}
63+
64+
public class DragOptions
65+
{
66+
///<summary>
67+
/// Enable drag-to-zoom
68+
/// <summary>
69+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
70+
public bool? Enabled { get; set; }
71+
72+
///<summary>
73+
/// Fill color
74+
/// <summary>
75+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
76+
public string? BackgroundColor { get; set; }
77+
78+
///<summary>
79+
/// Stroke color
80+
/// <summary>
81+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
82+
public string? BorderColor { get; set; }
83+
84+
///<summary>
85+
/// Stroke width
86+
/// <summary>
87+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
88+
public double? BorderWidth { get; set; }
89+
90+
///<summary>
91+
/// When the dragging box is dran on the chart
92+
/// <summary>
93+
[JsonIgnore]
94+
public DrawTime? DrawTime { get; set; }
95+
96+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
97+
[JsonInclude]
98+
[JsonPropertyName( "drawTime" )]
99+
private string? DrawTimeText => DrawTime?.ToString().ToLower();
100+
101+
///<summary>
102+
/// Minimal zoom distance required before actually applying zoom
103+
/// <summary>
104+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
105+
public double? Threshold { get; set; }
106+
107+
///<summary>
108+
/// Modifier key required for drag-to-zoom
109+
/// <summary>
110+
[JsonIgnore]
111+
public ModifierKey? ModifierKey { get; set; }
112+
113+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
114+
[JsonInclude]
115+
[JsonPropertyName( "modifierKey" )]
116+
private string? ModifierKeyText => ( ModifierKey == BlazorBootstrap.ModifierKey.None ) ? string.Empty : ModifierKey?.ToString().ToLower();
117+
}
118+
119+
public class PinchOptions
120+
{
121+
///<summary>
122+
/// /// Enable zooming via pinch gesture
123+
/// /// <summary>
124+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
125+
public bool? Enabled { get; set; }
126+
}
127+
128+
public class PanOptions
129+
{///<summary>
130+
/// Enable panning
131+
/// <summary>
132+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
133+
public bool? Enabled { get; set; }
134+
135+
///<summary>
136+
/// Allowed panning directions
137+
/// <summary>
138+
[JsonIgnore]
139+
public ZoomMode? Mode { get; set; }
140+
141+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
142+
[JsonInclude]
143+
[JsonPropertyName( "mode" )]
144+
private string? ModeText => ( Mode == ZoomMode.None ) ? string.Empty : Mode?.ToString().ToLower();
145+
146+
///<summary>
147+
/// Modifier key required for panning with mouse
148+
/// <summary>
149+
[JsonIgnore]
150+
public ModifierKey? ModifierKey { get; set; }
151+
152+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
153+
[JsonInclude]
154+
[JsonPropertyName( "modifierKey" )]
155+
private string? ModifierKeyText => ( ModifierKey == BlazorBootstrap.ModifierKey.None ) ? string.Empty : ModifierKey?.ToString().ToLower();
156+
157+
///<summary>
158+
/// Enable panning over a scale for that axis (regardless of mode)
159+
/// <summary>
160+
[JsonIgnore]
161+
public ZoomMode? ScaleMode { get; set; }
162+
163+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
164+
[JsonInclude]
165+
[JsonPropertyName( "scaleMode" )]
166+
private string? ScaleModeText => ( ScaleMode == ZoomMode.None ) ? string.Empty : ScaleMode?.ToString().ToLower();
167+
168+
///<summary>
169+
/// Enable panning over a scale for that axis (but only if mode is also enabled), and disables panning along that axis otherwise. Deprecated.
170+
/// <summary>
171+
[JsonIgnore]
172+
public ZoomMode? OverScaleMode { get; set; }
173+
174+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
175+
[JsonInclude]
176+
[JsonPropertyName( "overScaleMode" )]
177+
private string? OverScaleModeText => ( OverScaleMode == ZoomMode.None ) ? string.Empty : OverScaleMode?.ToString().ToLower();
178+
179+
///<summary>
180+
/// Minimal pan distance required before actually applying pan
181+
/// <summary>
182+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
183+
public double? Threshold { get; set; }
184+
}
185+
186+
public class ZoomLimitOptions
187+
{
188+
public ZoomLimitAxisOptions X { get; set; } = new();
189+
public ZoomLimitAxisOptions Y { get; set; } = new();
190+
191+
}
192+
193+
public class ZoomOptions
194+
{
195+
///<summary>
196+
/// Options of the mouse wheel behavior
197+
/// <summary>
198+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
199+
public WheelOptions? Wheel { get; set; }
200+
201+
///<summary>
202+
/// Options of the drag-to-zoom behavior
203+
/// <summary>
204+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
205+
public DragOptions? Drag { get; set; }
206+
207+
///<summary>
208+
/// Options of the pinch behavior
209+
/// <summary>
210+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
211+
public PinchOptions? Pinch { get; set; }
212+
213+
///<summary>
214+
/// Allowed zoom directions
215+
/// <summary>
216+
[JsonIgnore]
217+
public ZoomMode? Mode { get; set; }
218+
219+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
220+
[JsonInclude]
221+
[JsonPropertyName( "mode" )]
222+
private string? ModeText => ( Mode == ZoomMode.None ) ? string.Empty : Mode?.ToString().ToLower();
223+
224+
///<summary>
225+
/// Which of the enabled zooming directions should only be available when the mouse cursor is over a scale for that axis
226+
/// <summary>
227+
[JsonIgnore]
228+
public ZoomMode? ScaleMode { get; set; }
229+
230+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
231+
[JsonInclude]
232+
[JsonPropertyName( "scaleMode" )]
233+
private string? ScaleModeText => ( ScaleMode == ZoomMode.None ) ? string.Empty : ScaleMode?.ToString().ToLower();
234+
235+
///<summary>
236+
/// Allowed zoom directions when the mouse cursor is over a scale for that axis (but only if mode is also enabled), and disables zooming along that axis otherwise. Deprecated; use scaleMode instead.
237+
/// <summary>
238+
[JsonIgnore]
239+
public ZoomMode? OverScaleMode { get; set; }
240+
241+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
242+
[JsonInclude]
243+
[JsonPropertyName( "overScaleMode" )]
244+
private string? OverScaleModeText => ( OverScaleMode == ZoomMode.None ) ? string.Empty : OverScaleMode?.ToString().ToLower();
245+
246+
}
247+
248+
public class WheelOptions
249+
{
250+
///<summary>
251+
/// Enable zooming via mouse wheel
252+
/// <summary>
253+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
254+
public bool? Enabled { get; set; }
255+
256+
///<summary>
257+
/// Factor of zoom speed via mouse wheel
258+
/// <summary>
259+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
260+
public double? Speed { get; set; }
261+
262+
///<summary>
263+
/// Modifier key required for zooming via mouse wheel
264+
/// <summary>
265+
[JsonIgnore]
266+
public ModifierKey? ModifierKey { get; set; }
267+
268+
[JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
269+
[JsonInclude]
270+
[JsonPropertyName( "modifierKey" )]
271+
private string? ModifierKeyText => ( ModifierKey == BlazorBootstrap.ModifierKey.None ) ? string.Empty : ModifierKey?.ToString().ToLower();
272+
}

blazorbootstrap/Models/Charts/ChartPlugins/ChartPlugins.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,16 @@ public class ChartPluginsTooltipFont : ChartPlugin
483483

484484
#endregion
485485
}
486+
487+
/// <summary>
488+
/// Configuration for the Zoom plugin, if enabled.
489+
/// See <see href="https://www.chartjs.org/chartjs-plugin-zoom/latest/guide/" />
490+
/// </summary>
491+
public class ChartPluginsZoom : ChartPlugin
492+
{
493+
public ZoomLimitOptions? Limits { get; set; }
494+
495+
public PanOptions? Pan { get; set; }
496+
497+
public ZoomOptions? Zoom { get; set; }
498+
}

0 commit comments

Comments
 (0)