@reside-ic/skadi-chart 1.1.5-alpha → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -123,11 +123,15 @@ new Chart()
123
123
 
124
124
  ## Base chart class
125
125
 
126
- All charts start with the `Chart` class that takes in `ChartOptions` (e.g. `animationDuration`
127
- in ms or `logScale`, see [here](./src/Chart.ts) for source code):
126
+ All charts start with the `Chart` class that takes in `ChartOptions`, e.g. `animationDuration`
127
+ in ms, `logScale`, or tick configuration options. See [here](./src/Chart.ts) for source code.
128
+
129
+ Examples:
128
130
 
129
131
  ```ts
130
- const chart = new Chart({ animationDuration: 500 });
132
+ const chart = new Chart()
133
+ const chartWithLongerAnimation = new Chart({ animationDuration: 500 });
134
+ const chartWithFewXAxisTicks = new Chart({ tickConfig: { numerical: { x: { size: 1 } } } });
131
135
  ```
132
136
 
133
137
  ## Layers
@@ -196,11 +200,12 @@ Each layer itself defines how it zooms so this will let the user zoom on your gr
196
200
  * `addTooltips` adds a [TooltipLayer](./src/layers/TooltipsLayer.ts) which adds tooltips
197
201
  to the chart. For traces and points this means the tooltip will appear pointing to the
198
202
  closest point in the graph to the cursor (once it is within a threshold). You must provide
199
- a callback returning HTML to render the tooltip. You may optionally specify an axis; if you do,
200
- then the 'closest point' will be determined by the distance from the cursor on that axis.
203
+ a callback returning HTML to render the tooltip. You may optionally configure the radius (px)
204
+ within which a point triggers the tooltip to be displayed. You may also optionally specify an axis;
205
+ if you do, then the 'closest point' will be determined by the distance from the cursor on that axis.
201
206
  For example, you may want to show the tooltip for the nearest x value regardless of y distance.
202
207
  ```ts
203
- chart.addTooltips(tooltipHtmlCallback, "x");
208
+ chart.addTooltips(tooltipHtmlCallback, 25, "x");
204
209
  ```
205
210
  * `makeResponsive` is not really a layer but will make your graph responsive (redraw on change
206
211
  to container bounds and changes to window size).
@@ -39,10 +39,14 @@ declare module "types" {
39
39
  main: d3.ScaleBand<string>;
40
40
  bands: Record<string, ScaleNumeric>;
41
41
  };
42
- export type TickConfig = {
43
- count: number;
42
+ export type TickConfig<Domain> = {
43
+ padding?: number;
44
+ size?: number;
45
+ formatter?: (domainValue: Domain, index: number) => string;
46
+ } & (Domain extends number ? {
47
+ count?: number;
44
48
  specifier?: string;
45
- };
49
+ } : {});
46
50
  export type LayerArgs = {
47
51
  id: string;
48
52
  getHtmlId: (layer: LayerType) => string;
@@ -50,7 +54,10 @@ declare module "types" {
50
54
  clipPathBounds: Bounds;
51
55
  globals: {
52
56
  animationDuration: number;
53
- tickConfig: XY<TickConfig>;
57
+ tickConfig: {
58
+ numerical: XY<TickConfig<number>>;
59
+ categorical: XY<TickConfig<string>>;
60
+ };
54
61
  };
55
62
  scaleConfig: {
56
63
  numericalScales: XY<ScaleNumeric>;
@@ -211,10 +218,11 @@ declare module "layers/TooltipsLayer" {
211
218
  export type TooltipHtmlCallback<Metadata> = (pointWithMetadata: PointWithMetadata<Metadata>) => string;
212
219
  export class TooltipsLayer<Metadata> extends OptionalLayer {
213
220
  tooltipHtmlCallback: TooltipHtmlCallback<Metadata>;
221
+ radiusPx: number;
214
222
  distanceAxis?: AxisType;
215
223
  type: LayerType;
216
224
  tooltipRadiusSq: number;
217
- constructor(tooltipHtmlCallback: TooltipHtmlCallback<Metadata>, distanceAxis?: AxisType);
225
+ constructor(tooltipHtmlCallback: TooltipHtmlCallback<Metadata>, radiusPx?: number, distanceAxis?: AxisType);
218
226
  private getDistanceSq;
219
227
  private getDistanceSqSC;
220
228
  private convertSCPointToCC;
@@ -263,7 +271,7 @@ declare module "Chart" {
263
271
  import { TracesOptions } from "layers/TracesLayer";
264
272
  import { ZoomOptions } from "layers/ZoomLayer";
265
273
  import { TooltipHtmlCallback } from "layers/TooltipsLayer";
266
- import { AllOptionalLayers, Bounds, Lines, PartialScales, Scales, ScatterPoints, XY, XYLabel, ClipPathBounds } from "types";
274
+ import { AllOptionalLayers, Bounds, LayerArgs, Lines, PartialScales, Scales, ScatterPoints, XY, XYLabel, ClipPathBounds, TickConfig } from "types";
267
275
  import { LifecycleHooks, OptionalLayer } from "layers/Layer";
268
276
  export type ChartOptions = {
269
277
  logScale: XY<boolean>;
@@ -271,6 +279,10 @@ declare module "Chart" {
271
279
  type PartialChartOptions = {
272
280
  logScale?: Partial<XY<boolean>>;
273
281
  animationDuration?: number;
282
+ tickConfig?: {
283
+ numerical?: Partial<XY<Partial<TickConfig<number>>>>;
284
+ categorical?: Partial<XY<Partial<TickConfig<string>>>>;
285
+ };
274
286
  };
275
287
  type CategoricalScales = Partial<XY<string[]>>;
276
288
  export class Chart<Metadata = any> {
@@ -279,15 +291,7 @@ declare module "Chart" {
279
291
  isResponsive: boolean;
280
292
  globals: {
281
293
  animationDuration: number;
282
- tickConfig: {
283
- x: {
284
- count: number;
285
- };
286
- y: {
287
- count: number;
288
- specifier: string;
289
- };
290
- };
294
+ tickConfig: LayerArgs["globals"]["tickConfig"];
291
295
  };
292
296
  defaultMargin: {
293
297
  top: number;
@@ -306,7 +310,7 @@ declare module "Chart" {
306
310
  addTraces: (lines: Lines<Metadata>, options?: Partial<TracesOptions>) => this;
307
311
  addArea: () => this;
308
312
  addZoom: (options?: ZoomOptions) => this;
309
- addTooltips: (tooltipHtmlCallback: TooltipHtmlCallback<Metadata>, distanceAxis?: "x" | "y") => this;
313
+ addTooltips: (tooltipHtmlCallback: TooltipHtmlCallback<Metadata>, radiusPx?: number, distanceAxis?: "x" | "y") => this;
310
314
  private filterScatterPointsForLogAxis;
311
315
  private filterScatterPoints;
312
316
  addScatterPoints: (points: ScatterPoints<Metadata>) => this;