Skip to content

Commit 2c7c5a5

Browse files
committed
Fleshed out font settings in the chart def.
1 parent 27a10cf commit 2c7c5a5

6 files changed

+75
-57
lines changed

package-lock.json

+14-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "data-forge-plot",
3-
"version": "0.4.5",
3+
"version": "0.6.0",
44
"description": "Plotting API for use with Data-Forge.",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",
@@ -35,8 +35,8 @@
3535
},
3636
"homepage": "https://github.com/data-forge/data-forge-plot#readme",
3737
"dependencies": {
38-
"@data-forge-plot/apex": "0.0.39",
39-
"@data-forge-plot/chart-def": "^1.1.2",
38+
"@data-forge-plot/apex": "0.2.0",
39+
"@data-forge-plot/chart-def": "^1.4.0",
4040
"@data-forge/serialization": "^1.0.0",
4141
"inflate-template": "^1.1.6",
4242
"opn": "^5.5.0",

src/chart-def.ts

+12-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11

2-
import { ISerializedDataFrame } from "@data-forge/serialization";
3-
import { HorizontalLabelPosition, VerticalLabelPosition, AxisType, ChartType } from "@data-forge-plot/chart-def";
2+
import { AxisType, ChartType, IAxisLabelConfig, ILegendConfig, IDataLabels } from "@data-forge-plot/chart-def";
43

54
/**
6-
* Defines the configuration of an axis label.
5+
* Configures an axis of the chart.
76
*/
8-
export interface IAxisLabelConfig {
9-
10-
/**
11-
* The text for the label.
12-
*/
13-
text?: string;
7+
export interface IAxisConfig {
148

159
/**
16-
* Position of the label.
10+
* Label for the axis.
1711
*/
18-
position?: HorizontalLabelPosition | VerticalLabelPosition;
12+
label?: string | IAxisLabelConfig;
1913
}
2014

2115
/**
2216
* Configures an axis of the chart.
2317
*/
24-
export interface IAxisConfig {
18+
export interface IXAxisConfig extends IAxisConfig {
2519

2620
/**
2721
* Sets the type of the axis' data.
28-
* Default: AxisType.Indexed ("indexed")
2922
*/
3023
axisType?: AxisType;
31-
32-
/**
33-
* Label for the axis.
34-
*/
35-
label?: string | IAxisLabelConfig;
3624
}
3725

3826
/**
@@ -51,17 +39,6 @@ export interface IYAxisConfig extends IAxisConfig {
5139
max?: number;
5240
}
5341

54-
/**
55-
* Configures the legend of the chart.
56-
*/
57-
export interface ILegendConfig {
58-
59-
/**
60-
* Set to true (default) to show the legend for the chart .
61-
*/
62-
show?: boolean;
63-
}
64-
6542
/**
6643
* Defines the chart.
6744
*/
@@ -88,7 +65,7 @@ export interface IPlotConfig {
8865
/**
8966
* Configuration for the x axis.
9067
*/
91-
x?: IAxisConfig;
68+
x?: IXAxisConfig;
9269

9370
/**
9471
* Configuration for the y axis.
@@ -104,6 +81,11 @@ export interface IPlotConfig {
10481
* Configures the chart's legend.
10582
*/
10683
legend?: ILegendConfig;
84+
85+
/**
86+
* Configure data labels for the whole chart.
87+
*/
88+
dataLabels?: IDataLabels;
10789
}
10890

10991
/**

src/expand-chart-def.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IChartDef, IPlotConfig as IExpandedPlotConfig, IAxisMap as IExpandedAxisMap, ChartType, IAxisConfig as IExpandedAxisConfig, IYAxisConfig as IExpandedYAxisConfig, IXAxisConfig as IExpandedXAxisConfig, IAxisSeriesConfig as IExpandedAxisSeriesConfig, IYAxisSeriesConfig as IExpandedYAxisSeriesConfig } from "@data-forge-plot/chart-def";
1+
import { IChartDef, IPlotConfig as IExpandedPlotConfig, IAxisMap as IExpandedAxisMap, IAxisConfig as IExpandedAxisConfig, IYAxisConfig as IExpandedYAxisConfig, IXAxisConfig as IExpandedXAxisConfig, IAxisSeriesConfig as IExpandedAxisSeriesConfig, IYAxisSeriesConfig as IExpandedYAxisSeriesConfig, ISeriesLabelConfig } from "@data-forge-plot/chart-def";
22
import { IAxisMap, IPlotConfig, IAxisConfig, IYAxisConfig, IAxisSeriesConfig, IYAxisSeriesConfig } from "./chart-def";
33
import { ISerializedDataFrame } from "@data-forge/serialization";
44
import { isString } from "./utils";
@@ -36,14 +36,33 @@ export function expandSeriesConfig(series: string | IAxisSeriesConfig): IExpande
3636
};
3737
}
3838
else {
39-
return Object.assign({}, series);
39+
const inputSeriesConfig = series as IAxisSeriesConfig;
40+
const expandedSeriesConfig: IExpandedAxisSeriesConfig = {
41+
series: inputSeriesConfig.series,
42+
};
43+
44+
if (inputSeriesConfig.label) {
45+
expandedSeriesConfig.label = inputSeriesConfig.label;
46+
}
47+
48+
if (inputSeriesConfig.format) {
49+
expandedSeriesConfig.format = inputSeriesConfig.format;
50+
}
51+
52+
if (inputSeriesConfig.color) {
53+
expandedSeriesConfig.color = inputSeriesConfig.color;
54+
}
55+
56+
return expandedSeriesConfig;
4057
}
4158
}
4259

4360
export function expandYSeriesConfig(series: string | IYAxisSeriesConfig): IExpandedYAxisSeriesConfig {
4461
const expanded = expandSeriesConfig(series) as IExpandedYAxisSeriesConfig;
45-
if (expanded.x) {
46-
expanded.x = expandSeriesConfig(expanded.x);
62+
if (!isString(series)) {
63+
if (series.x) {
64+
expanded.x = expandSeriesConfig(series.x);
65+
}
4766
}
4867
return expanded;
4968
}

src/test/expand-chart-def.test.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,31 @@ describe("expand chart def", () => {
1414
expect(expanded.series).toBe("my series");
1515
});
1616

17-
it("can clone object series config", () => {
17+
it("can expand series config", () => {
1818
const seriesConfig = { series: "my series" };
1919
const expanded = expandSeriesConfig(seriesConfig);
2020
expect(expanded).not.toBe(seriesConfig);
2121
expect(expanded).toEqual(seriesConfig);
2222
});
2323

24+
it("can expand series config with string label", () => {
25+
const seriesConfig = { series: "my series", label: "a great series" };
26+
const expanded = expandSeriesConfig(seriesConfig);
27+
expect(expanded.label).toBe("a great series");
28+
});
29+
30+
it("can expand series config with format", () => {
31+
const seriesConfig = { series: "my series", format: "the format!" };
32+
const expanded = expandSeriesConfig(seriesConfig);
33+
expect(expanded.format).toBe("the format!");
34+
});
35+
36+
it("can expand series config with color", () => {
37+
const seriesConfig = { series: "my series", format: "red" };
38+
const expanded = expandSeriesConfig(seriesConfig);
39+
expect(expanded.format).toBe("red");
40+
});
41+
2442
it("can expand y series config with specific x series as string", () => {
2543
const seriesConfig = { series: "my y series", x: "my x series" };
2644
const expanded = expandYSeriesConfig(seriesConfig);
@@ -163,8 +181,8 @@ describe("expand chart def", () => {
163181
it("can expand axis config", () => {
164182

165183
const xConfig = { axisType: AxisType.Category };
166-
const yConfig = { axisType: AxisType.Numerical };
167-
const y2Config = { axisType: AxisType.Timeseries };
184+
const yConfig = {};
185+
const y2Config = {};
168186
const expanded = expandChartDef({} as any, { x: xConfig, y: yConfig, y2: y2Config }, {});
169187
expect(expanded.plotConfig.x).not.toBe(xConfig);
170188
expect(expanded.plotConfig.x).toEqual(xConfig);

src/test/plot-api.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe("plot-api", () => {
183183
.addSeries("my series")
184184
.label("a great series")
185185
.serialize();
186-
expect(serialized.axisMap.y[0].label!).toBe("a great series");
186+
expect(serialized.axisMap.y[0].label).toBe("a great series");
187187
});
188188

189189
it("can set specific x series for y axis series", () => {
@@ -209,7 +209,7 @@ describe("plot-api", () => {
209209
.addSeries("my series")
210210
.label("a great series")
211211
.serialize();
212-
expect(serialized.axisMap.y2[0].label!).toBe("a great series");
212+
expect(serialized.axisMap.y2[0].label).toBe("a great series");
213213
});
214214

215215
it("can set specific x series for y2 axis series", () => {

0 commit comments

Comments
 (0)