@flourish/chart-layout
Advanced tools
Comparing version 2.1.0 to 3.0.0-prerelease.1
{ | ||
"name": "@flourish/chart-layout", | ||
"version": "2.1.0", | ||
"version": "3.0.0-prerelease.1", | ||
"description": "Create axes", | ||
@@ -5,0 +5,0 @@ "main": "chart-layout.js", |
@@ -45,3 +45,3 @@ # Flourish chart layout | ||
var container = select(layout.getSection("primary")).select("svg"); // see @flourish/layout | ||
var props = { x: state.x, y: state.y, y: state.y2 background: state.chart_bg }; | ||
var props = { x: state.x, y: state.y, y2: state.y2, background: state.chart_bg }; | ||
var chart_layout = createChartLayout(container, props); | ||
@@ -158,3 +158,16 @@ ``` | ||
## The `Title` methods of `chart_layout` | ||
### `chart_layout.xTitle()` | ||
Returns the computed title text for the x axis. | ||
### `chart_layout.yTitle()` | ||
Returns the computed title text for the y axis. | ||
### `chart_layout.y2Title()` | ||
Returns the computed title text for the y2 axis. | ||
## Other methods of `chart_layout` | ||
@@ -184,2 +197,6 @@ | ||
### `chart_layout.xAutoTitle([value])` | ||
If `value` is specified, sets the title text to be used for the x axis to `value` when the Flourish user choses `auto` for the `title_mode`. | ||
### `chart_layout.xDatetimeParse([func])` | ||
@@ -194,2 +211,6 @@ If `func` is specified, sets the parsing function to be applied when the Flourish user inputs dates in string format in the settings for the x axis. Currently this means the min and max for the date range. | ||
### `chart_layout.yAutoTitle([value])` | ||
If `value` is specified, sets the title text to be used for the y axis to `value` when the Flourish user choses `auto` for the `title_mode`. | ||
### `chart_layout.yDatetimeParse([func])` | ||
@@ -204,2 +225,6 @@ If `func` is specified, sets the parsing function to be applied when the Flourish user inputs dates in string format in the settings for the y axis. Currently this means the min and max for the date range. | ||
### `chart_layout.y2AutoTitle([value])` | ||
If `value` is specified, sets the title text to be used for the y2 axis to `value` when the Flourish user choses `auto` for the `title_mode`. | ||
### `chart_layout.y2DatetimeParse([func])` | ||
@@ -212,2 +237,2 @@ If `func` is specified, sets the parsing function to be applied when the Flourish user inputs dates in string format in the settings for the y2 axis. Currently this means the min and max for the date range. | ||
### `chart_layout.y2ZeroAxis([value])` | ||
If `value` is specified and is truthy then the secondary y axis will include 0 if the data is numeric and the axis linear, regardless of the `y2Data` values. User-set `min` and `max` settings can overcome this restriction. | ||
If `value` is specified and is truthy then the secondary y axis will include 0 if the data is numeric and the axis linear, regardless of the `y2Data` values. User-set `min` and `max` settings can overcome this restriction. |
@@ -0,1 +1,5 @@ | ||
# 3.0.0 prerelease 1 | ||
* Add auto axis titles | ||
* Fix bug with zeroAxis functions and negative minimum | ||
# 2.1.0 | ||
@@ -2,0 +6,0 @@ * Support datetime scales |
@@ -12,2 +12,3 @@ import { prepareState } from "./state"; | ||
import { initXTicks, initYTicks, initY2Ticks } from "./ticks"; | ||
import { initXTitle, initYTitle, initY2Title } from "./axis-titles"; | ||
import { initMargins } from "./margins"; | ||
@@ -54,2 +55,5 @@ import { initXScale, initYScale, initY2Scale, initZeroAxis } from "./scales"; | ||
instance.y2DatetimeParse = initDatetimeParse(instance); | ||
instance.xTitle = initXTitle(instance, state); // Implicitly adds instance.xAutoTitle | ||
instance.yTitle = initYTitle(instance, state); // Implicitly adds instance.yAutoTitle | ||
instance.y2Title = initY2Title(instance, state); // Implicitly adds instance.y2AutoTitle | ||
instance.xTicks = initXTicks(instance, state); | ||
@@ -56,0 +60,0 @@ instance.yTicks = initYTicks(instance, state); |
@@ -6,3 +6,3 @@ import { remToPx, getFont } from "../common"; | ||
var x = state.x; | ||
var title_text = x.title.trim(); | ||
var title_text = instance.xTitle(); | ||
if (x.axis_visible === "off" || !title_text) return 0; | ||
@@ -26,3 +26,3 @@ | ||
var y = state.y; | ||
var title_text = y.title.trim(); | ||
var title_text = instance.yTitle(); | ||
if (!y.axis_visible || !title_text) return 0; | ||
@@ -47,3 +47,3 @@ | ||
var y = state.y2; | ||
var title_text = y.title.trim(); | ||
var title_text = instance.y2Title(); | ||
if (!y.axis_visible || !title_text) return 0; | ||
@@ -50,0 +50,0 @@ |
@@ -20,3 +20,6 @@ import { scaleLinear, scaleLog, scalePoint, scaleTime } from "d3-scale"; | ||
domain = scaleLinear().domain(data.extent()).nice().domain(); | ||
if (include_zero) domain[0] >= 0 ? domain[0] = 0 : domain[1] = 0; | ||
if (include_zero) { | ||
if (domain[0] >= 0) domain[0] = 0; | ||
else if (domain[1] < 0) domain[1] = 0; | ||
} | ||
} | ||
@@ -23,0 +26,0 @@ else if (data.length) { // Only one unique value |
@@ -34,2 +34,3 @@ var X_DEFAULTS = Object.freeze({ | ||
title_mode: "auto", | ||
title: "", | ||
@@ -36,0 +37,0 @@ title_color: "#aaaaaa", |
@@ -34,2 +34,3 @@ import { fillInDefaults } from "./common"; | ||
title_mode: "auto", | ||
title: "", | ||
@@ -36,0 +37,0 @@ title_color: "#aaaaaa", |
@@ -11,3 +11,4 @@ import { select } from "d3-selection"; | ||
var tick_length, tick_label_size, tick_label_distance; | ||
var title_size, x_mid; | ||
var title_size, title_text; | ||
var x_mid; | ||
var oldXScale, enteringXScale, exitingXScale, oldYScale; | ||
@@ -33,2 +34,3 @@ | ||
title_size = remToPx(x.title_size); | ||
title_text = instance.xTitle(); | ||
} | ||
@@ -227,3 +229,3 @@ | ||
var title = title_container.selectAll("text") | ||
.data(show_this_axis && x.title ? [x.title] : []); | ||
.data(show_this_axis && title_text ? [title_text] : []); | ||
@@ -440,3 +442,3 @@ title.exit().remove(); | ||
var title = title_container.selectAll("text") | ||
.data(show_this_axis && x.title ? [x.title] : []); | ||
.data(show_this_axis && title_text ? [title_text] : []); | ||
@@ -443,0 +445,0 @@ title.exit().remove(); |
@@ -36,2 +36,4 @@ import { select } from "d3-selection"; | ||
var tick_label_distance = (ticks_out ? tick_length : 0) + remToPx(y.tick_padding); | ||
var title_text = instance.yTitle(); | ||
var title_size = remToPx(y.title_size); | ||
@@ -187,3 +189,3 @@ var title_distance = tick_label_distance + ticks.max_box_width + remToPx(y.title_padding) + 0.33 * title_size; | ||
var title = title_container.selectAll("text") | ||
.data(y.axis_visible && y.title ? [y.title] : []); | ||
.data(y.axis_visible && title_text ? [title_text] : []); | ||
@@ -190,0 +192,0 @@ title.exit().remove(); |
@@ -36,2 +36,4 @@ import { select } from "d3-selection"; | ||
var tick_label_distance = (ticks_out ? tick_length : 0) + remToPx(y.tick_padding); | ||
var title_text = instance.y2Title(); | ||
var title_size = remToPx(y.title_size); | ||
@@ -188,3 +190,3 @@ var title_distance = tick_label_distance + ticks.max_box_width + remToPx(y.title_padding) + 0.85 * title_size; | ||
var title = title_container.selectAll("text") | ||
.data(y.axis_visible && y.title ? [y.title] : []); | ||
.data(y.axis_visible && title_text ? [title_text] : []); | ||
@@ -191,0 +193,0 @@ title.exit().remove(); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
341812
42
8822
233
2