@reside-ic/skadi-chart 1.1.4 → 1.1.5-alpha
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 +12 -6
- 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%")
|
|
@@ -157,9 +157,13 @@ overview of the methods [Chart](./src/Chart.ts) class provides for adding layers
|
|
|
157
157
|
|
|
158
158
|
* `addAxes` adds an [AxesLayer](./src/layers/AxesLayer.ts). This will draw axes with tick
|
|
159
159
|
marks. The axes can be autoscaled based on your data or you can provide a fixed scale in
|
|
160
|
-
the `appendTo` function below.
|
|
160
|
+
the `appendTo` function below. Both the arguments are optional. Note that the values passed in
|
|
161
|
+
the `labelPositions` argument are proportions: for example, `{ x: 0.5 }` would mean to position
|
|
162
|
+
the axis label halfway (50%) between the bottom edge of the graph and the bottom edge of the svg.
|
|
161
163
|
```ts
|
|
162
|
-
|
|
164
|
+
labels = { x: "Time" }
|
|
165
|
+
labelPositions = { x: 0.5 }
|
|
166
|
+
chart.addAxes(labels, labelPositions);
|
|
163
167
|
```
|
|
164
168
|
* `addTraces` adds a [TracesLayer](./src/layers/TracesLayer.ts). This will add traces to
|
|
165
169
|
the graph. This data will also be used for autoscaling the axes if you haven't provided a
|
|
@@ -192,9 +196,11 @@ Each layer itself defines how it zooms so this will let the user zoom on your gr
|
|
|
192
196
|
* `addTooltips` adds a [TooltipLayer](./src/layers/TooltipsLayer.ts) which adds tooltips
|
|
193
197
|
to the chart. For traces and points this means the tooltip will appear pointing to the
|
|
194
198
|
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.
|
|
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.
|
|
201
|
+
For example, you may want to show the tooltip for the nearest x value regardless of y distance.
|
|
196
202
|
```ts
|
|
197
|
-
chart.addTooltips(tooltipHtmlCallback);
|
|
203
|
+
chart.addTooltips(tooltipHtmlCallback, "x");
|
|
198
204
|
```
|
|
199
205
|
* `makeResponsive` is not really a layer but will make your graph responsive (redraw on change
|
|
200
206
|
to container bounds and changes to window size).
|
|
@@ -230,7 +236,7 @@ class CustomLayer extends OptionalLayer {
|
|
|
230
236
|
const svg = layerArgs.coreLayers[LayerType.Svg];
|
|
231
237
|
const { getHtmlId } = layerArgs;
|
|
232
238
|
svg.append("svg:circle")
|
|
233
|
-
.attr("id",
|
|
239
|
+
.attr("id", `${getHtmlId(this.type)}-circle`)
|
|
234
240
|
.attr("cx", "50%")
|
|
235
241
|
.attr("cy", "50%")
|
|
236
242
|
.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
|
}
|