Skip to content

Commit

Permalink
Fix: Ensure smartLabels, sorted values are inherited
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhutchings committed Dec 7, 2023
1 parent a3e983d commit 9975427
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/templates/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import line from "./line.js"
* @param {AxisOptions} [options.yAxis]
* Overrides for the y-axis. See {@link AxisOptions} for more details.
* @param {boolean} [options.sorted] - Whether to sort the values.
* @param {Boolean} [options.smartLabels] - Labels are shifted to minimise
* overlapping the line.
* @returns {string} Rendered chart
*
* @example
Expand All @@ -36,6 +38,7 @@ import line from "./line.js"
* key: ["α", "β", "γ", "δ"],
* },
* sorted: true,
* smartLabels: false,
* })
*
* @example
Expand All @@ -53,7 +56,16 @@ import line from "./line.js"
* })
*/

export default ({ data, title, description, map, xAxis, yAxis, sorted }) => {
export default ({
data,
title,
description,
map,
xAxis,
yAxis,
sorted,
smartLabels,
}) => {
return line({
data,
title,
Expand All @@ -62,6 +74,7 @@ export default ({ data, title, description, map, xAxis, yAxis, sorted }) => {
xAxis,
yAxis,
sorted,
smartLabels,
showGaps: true,
area: true,
})
Expand Down
17 changes: 15 additions & 2 deletions src/templates/scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import line from "./line.js"
* Overrides for the x-axis. See {@link AxisOptions} for more details.
* @param {AxisOptions} [options.yAxis]
* Overrides for the y-axis. See {@link AxisOptions} for more details.
* @param {Boolean} [options.sorted] - Whether to sort the values.
* @param {Boolean} [options.smartLabels] - Labels are shifted to minimise
* overlapping the line.
* @returns {string} Rendered chart
*
* @example
Expand Down Expand Up @@ -54,7 +57,16 @@ import line from "./line.js"
*
*/

export default ({ data, title, description, map, xAxis, yAxis }) => {
export default ({
data,
title,
description,
map,
xAxis,
yAxis,
sorted,
smartLabels = false,
}) => {
data = Array.isArray(data[0][0]) ? data : [data]

map = {
Expand All @@ -73,7 +85,8 @@ export default ({ data, title, description, map, xAxis, yAxis }) => {
map,
xAxis,
yAxis,
smartLabels: false,
sorted,
smartLabels,
scatter: true,
})
}
9 changes: 9 additions & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare module "shown" {
* key: ["α", "β", "γ", "δ"],
* },
* sorted: true,
* smartLabels: false,
* })
* @example
* shown.area({
Expand Down Expand Up @@ -43,6 +44,8 @@ declare module "shown" {
* @param [options.xAxis] - Overrides for the x-axis. See {@link AxisOptions} for more details.
* @param [options.yAxis] - Overrides for the y-axis. See {@link AxisOptions} for more details.
* @param [options.sorted] - Whether to sort the values.
* @param [options.smartLabels] - Labels are shifted to minimise
* overlapping the line.
* @returns Rendered chart
*/
function area(options: {
Expand All @@ -53,6 +56,7 @@ declare module "shown" {
xAxis?: AxisOptions;
yAxis?: AxisOptions;
sorted?: boolean;
smartLabels?: boolean;
}): string;
/**
* Generate a bar chart.
Expand Down Expand Up @@ -356,6 +360,9 @@ declare module "shown" {
* @param [options.map] - Controls for transforming data. See {@link MapOptions} for more details.
* @param [options.xAxis] - Overrides for the x-axis. See {@link AxisOptions} for more details.
* @param [options.yAxis] - Overrides for the y-axis. See {@link AxisOptions} for more details.
* @param [options.sorted] - Whether to sort the values.
* @param [options.smartLabels] - Labels are shifted to minimise
* overlapping the line.
* @returns Rendered chart
*/
function scatter(options: {
Expand All @@ -365,6 +372,8 @@ declare module "shown" {
map?: MapOptions;
xAxis?: AxisOptions;
yAxis?: AxisOptions;
sorted?: boolean;
smartLabels?: boolean;
}): string;
}

Expand Down

0 comments on commit 9975427

Please sign in to comment.