@reside-ic/skadi-chart 1.1.4 → 1.1.5
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 +20 -9
- package/dist/skadi-chart.d.ts +12 -9
- package/dist/skadi-chart.js +1497 -1471
- package/dist/skadi-chart.umd.cjs +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ class CustomLayer extends OptionalLayer {
|
|
|
98
98
|
const svg = layerArgs.coreLayers[LayerType.Svg];
|
|
99
99
|
const { getHtmlId } = layerArgs;
|
|
100
100
|
svg.append("svg:circle")
|
|
101
|
-
.attr("id",
|
|
101
|
+
.attr("id", `${getHtmlId(this.type)}-circle`)
|
|
102
102
|
.attr("cx", "50%")
|
|
103
103
|
.attr("cy", "50%")
|
|
104
104
|
.attr("r", "5%")
|
|
@@ -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
|
|
127
|
-
in ms
|
|
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(
|
|
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
|
|
@@ -157,9 +161,13 @@ overview of the methods [Chart](./src/Chart.ts) class provides for adding layers
|
|
|
157
161
|
|
|
158
162
|
* `addAxes` adds an [AxesLayer](./src/layers/AxesLayer.ts). This will draw axes with tick
|
|
159
163
|
marks. The axes can be autoscaled based on your data or you can provide a fixed scale in
|
|
160
|
-
the `appendTo` function below.
|
|
164
|
+
the `appendTo` function below. Both the arguments are optional. Note that the values passed in
|
|
165
|
+
the `labelPositions` argument are proportions: for example, `{ x: 0.5 }` would mean to position
|
|
166
|
+
the axis label halfway (50%) between the bottom edge of the graph and the bottom edge of the svg.
|
|
161
167
|
```ts
|
|
162
|
-
|
|
168
|
+
labels = { x: "Time" }
|
|
169
|
+
labelPositions = { x: 0.5 }
|
|
170
|
+
chart.addAxes(labels, labelPositions);
|
|
163
171
|
```
|
|
164
172
|
* `addTraces` adds a [TracesLayer](./src/layers/TracesLayer.ts). This will add traces to
|
|
165
173
|
the graph. This data will also be used for autoscaling the axes if you haven't provided a
|
|
@@ -192,9 +200,12 @@ Each layer itself defines how it zooms so this will let the user zoom on your gr
|
|
|
192
200
|
* `addTooltips` adds a [TooltipLayer](./src/layers/TooltipsLayer.ts) which adds tooltips
|
|
193
201
|
to the chart. For traces and points this means the tooltip will appear pointing to the
|
|
194
202
|
closest point in the graph to the cursor (once it is within a threshold). You must provide
|
|
195
|
-
a callback returning HTML to render the tooltip.
|
|
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.
|
|
206
|
+
For example, you may want to show the tooltip for the nearest x value regardless of y distance.
|
|
196
207
|
```ts
|
|
197
|
-
chart.addTooltips(tooltipHtmlCallback);
|
|
208
|
+
chart.addTooltips(tooltipHtmlCallback, 25, "x");
|
|
198
209
|
```
|
|
199
210
|
* `makeResponsive` is not really a layer but will make your graph responsive (redraw on change
|
|
200
211
|
to container bounds and changes to window size).
|
|
@@ -230,7 +241,7 @@ class CustomLayer extends OptionalLayer {
|
|
|
230
241
|
const svg = layerArgs.coreLayers[LayerType.Svg];
|
|
231
242
|
const { getHtmlId } = layerArgs;
|
|
232
243
|
svg.append("svg:circle")
|
|
233
|
-
.attr("id",
|
|
244
|
+
.attr("id", `${getHtmlId(this.type)}-circle`)
|
|
234
245
|
.attr("cx", "50%")
|
|
235
246
|
.attr("cy", "50%")
|
|
236
247
|
.attr("r", "5%")
|
package/dist/skadi-chart.d.ts
CHANGED
|
@@ -132,11 +132,12 @@ declare module "layers/Layer" {
|
|
|
132
132
|
}
|
|
133
133
|
declare module "layers/AxesLayer" {
|
|
134
134
|
import { LayerType, OptionalLayer } from "layers/Layer";
|
|
135
|
-
import { LayerArgs, XYLabel } from "types";
|
|
135
|
+
import { LayerArgs, XY, XYLabel } from "types";
|
|
136
136
|
export class AxesLayer extends OptionalLayer {
|
|
137
137
|
labels: XYLabel;
|
|
138
|
+
labelPositions: XY<number>;
|
|
138
139
|
type: LayerType;
|
|
139
|
-
constructor(labels: XYLabel);
|
|
140
|
+
constructor(labels: XYLabel, labelPositions: XY<number>);
|
|
140
141
|
private drawAxis;
|
|
141
142
|
draw: (layerArgs: LayerArgs) => void;
|
|
142
143
|
private drawCategoricalAxis;
|
|
@@ -146,11 +147,12 @@ declare module "layers/AxesLayer" {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
declare module "helpers" {
|
|
149
|
-
import { LayerArgs, ScaleNumeric, XY, Point, Scales } from "types";
|
|
150
|
+
import { LayerArgs, ScaleNumeric, XY, Point, Scales, AxisType } from "types";
|
|
150
151
|
export const customLineGen: (lineSC: Point[], layerArgs: LayerArgs) => string[];
|
|
151
152
|
export const numScales: (bands: Partial<XY<string>> | undefined, layerArgs: LayerArgs) => XY<ScaleNumeric>;
|
|
152
153
|
export const getXYMinMax: (points: Point[]) => Scales;
|
|
153
154
|
export const getSvgRectPath: (xStart: number, xEnd: number, yStart: number, yEnd: number) => string;
|
|
155
|
+
export const mapScales: <T>(layerArgs: LayerArgs, callback: (scale: ScaleNumeric, axis: AxisType) => T) => [Record<string, T>, Record<string, Record<string, T>>];
|
|
154
156
|
}
|
|
155
157
|
declare module "layers/TracesLayer" {
|
|
156
158
|
import { LayerArgs, Lines, Point, ZoomExtents } from "types";
|
|
@@ -205,13 +207,14 @@ declare module "layers/ScatterLayer" {
|
|
|
205
207
|
}
|
|
206
208
|
declare module "layers/TooltipsLayer" {
|
|
207
209
|
import { LayerType, OptionalLayer } from "layers/Layer";
|
|
208
|
-
import { LayerArgs, PointWithMetadata } from "types";
|
|
210
|
+
import { AxisType, LayerArgs, PointWithMetadata } from "types";
|
|
209
211
|
export type TooltipHtmlCallback<Metadata> = (pointWithMetadata: PointWithMetadata<Metadata>) => string;
|
|
210
212
|
export class TooltipsLayer<Metadata> extends OptionalLayer {
|
|
211
213
|
tooltipHtmlCallback: TooltipHtmlCallback<Metadata>;
|
|
214
|
+
distanceAxis?: AxisType;
|
|
212
215
|
type: LayerType;
|
|
213
216
|
tooltipRadiusSq: number;
|
|
214
|
-
constructor(tooltipHtmlCallback: TooltipHtmlCallback<Metadata
|
|
217
|
+
constructor(tooltipHtmlCallback: TooltipHtmlCallback<Metadata>, distanceAxis?: AxisType);
|
|
215
218
|
private getDistanceSq;
|
|
216
219
|
private getDistanceSqSC;
|
|
217
220
|
private convertSCPointToCC;
|
|
@@ -260,7 +263,7 @@ declare module "Chart" {
|
|
|
260
263
|
import { TracesOptions } from "layers/TracesLayer";
|
|
261
264
|
import { ZoomOptions } from "layers/ZoomLayer";
|
|
262
265
|
import { TooltipHtmlCallback } from "layers/TooltipsLayer";
|
|
263
|
-
import { AllOptionalLayers, Lines, PartialScales, Scales, ScatterPoints, XY, XYLabel, ClipPathBounds } from "types";
|
|
266
|
+
import { AllOptionalLayers, Bounds, Lines, PartialScales, Scales, ScatterPoints, XY, XYLabel, ClipPathBounds } from "types";
|
|
264
267
|
import { LifecycleHooks, OptionalLayer } from "layers/Layer";
|
|
265
268
|
export type ChartOptions = {
|
|
266
269
|
logScale: XY<boolean>;
|
|
@@ -296,14 +299,14 @@ declare module "Chart" {
|
|
|
296
299
|
options: ChartOptions;
|
|
297
300
|
autoscaledMaxExtents: Scales;
|
|
298
301
|
constructor(options?: PartialChartOptions);
|
|
299
|
-
addAxes: (labels?: XYLabel) => this;
|
|
302
|
+
addAxes: (labels?: XYLabel, labelPositions?: Partial<XY<number>>) => this;
|
|
300
303
|
addGridLines: (directions?: Partial<XY<boolean>>) => this;
|
|
301
304
|
private filterLinesForLogAxis;
|
|
302
305
|
private filterLines;
|
|
303
306
|
addTraces: (lines: Lines<Metadata>, options?: Partial<TracesOptions>) => this;
|
|
304
307
|
addArea: () => this;
|
|
305
308
|
addZoom: (options?: ZoomOptions) => this;
|
|
306
|
-
addTooltips: (tooltipHtmlCallback: TooltipHtmlCallback<Metadata
|
|
309
|
+
addTooltips: (tooltipHtmlCallback: TooltipHtmlCallback<Metadata>, distanceAxis?: "x" | "y") => this;
|
|
307
310
|
private filterScatterPointsForLogAxis;
|
|
308
311
|
private filterScatterPoints;
|
|
309
312
|
addScatterPoints: (points: ScatterPoints<Metadata>) => this;
|
|
@@ -315,7 +318,7 @@ declare module "Chart" {
|
|
|
315
318
|
private processScales;
|
|
316
319
|
private appendClipPath;
|
|
317
320
|
private draw;
|
|
318
|
-
appendTo: (baseElement: HTMLDivElement, maxExtents?: PartialScales, initialExtents?: PartialScales, categoricalScales?: CategoricalScales, clipPathBoundsOptions?: ClipPathBounds) => this;
|
|
321
|
+
appendTo: (baseElement: HTMLDivElement, maxExtents?: PartialScales, initialExtents?: PartialScales, categoricalScales?: CategoricalScales, margins?: Partial<Bounds["margin"]>, clipPathBoundsOptions?: ClipPathBounds) => this;
|
|
319
322
|
private createCategoricalScale;
|
|
320
323
|
}
|
|
321
324
|
}
|