Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flourish/chart-layout

Package Overview
Dependencies
Maintainers
0
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flourish/chart-layout - npm Package Compare versions

Comparing version 11.0.0 to 11.0.1

22

package.json
{
"name": "@flourish/chart-layout",
"version": "11.0.0",
"version": "11.0.1",
"private": false,

@@ -15,11 +15,10 @@ "description": "Create axes",

"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"eslint": "^8.35.0",
"only-allow": "^1.2.1",
"rollup": "^4.6.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"terser": "^5.19.2"
"terser": "^5.19.2",
"mocha": "^10.2.0",
"@flourish/mocha-env": "^1.0.0"
},
"repository": {
"type": "git",
"url": "git://github.com/kiln/flourish-chart-layout.git"
},
"lint-staged": {

@@ -42,2 +41,7 @@ "*.js": "npm run lint --"

"exports": "./src/index.js",
"mocha": {
"spec": "**/*.test.{js,cjs,mjs,ts}",
"recursive": true,
"require": "@flourish/mocha-env"
},
"scripts": {

@@ -47,4 +51,6 @@ "lint": "eslint .",

"minify": "terser -m -o chart-layout.min.js chart-layout.js",
"precommit": "lint-staged"
"precommit": "lint-staged",
"mocha": "mocha",
"test": "npm run mocha"
}
}

@@ -0,1 +1,4 @@

# 11.0.1
* Remove repo from package.json
# 11.0.0

@@ -2,0 +5,0 @@ * Switch to preferring ESM by default on recent versions of Node.js by adding an `exports` field to `package.json`.

@@ -6,3 +6,3 @@ import "d3-transition";

return function(value) {
return function (value) {
if (value === undefined) return animation_duration;

@@ -9,0 +9,0 @@ animation_duration = value;

function initAutoTitle(instance) {
var auto_title = "";
return function(value) {
return function (value) {
if (value === undefined) return auto_title;

@@ -15,4 +15,5 @@ auto_title = value;

return function() {
var text = (state.x.title_mode === "auto" ? instance.xAutoTitle() : state.x.title);
return function () {
var text =
state.x.title_mode === "auto" ? instance.xAutoTitle() : state.x.title;
return text.trim();

@@ -26,4 +27,5 @@ };

return function() {
var text = state.y.title_mode === "auto" ? instance.yAutoTitle() : state.y.title;
return function () {
var text =
state.y.title_mode === "auto" ? instance.yAutoTitle() : state.y.title;
return text.trim();

@@ -37,4 +39,5 @@ };

return function() {
var text = (state.y2.title_mode === "auto" ? instance.y2AutoTitle() : state.y2.title);
return function () {
var text =
state.y2.title_mode === "auto" ? instance.y2AutoTitle() : state.y2.title;
return text.trim();

@@ -41,0 +44,0 @@ };

function addAxes(chart) {
var axes_container = chart.append("g").attr("class", "fl-axes").attr("aria-hidden", true);
var axes_container = chart
.append("g")
.attr("class", "fl-axes")
.attr("aria-hidden", true);
var x_axes = axes_container.append("g").attr("class", "fl-x-axes");
var y_axes = axes_container.append("g").attr("class", "fl-y-axes");
var bottom = x_axes.append("g").attr("class", "fl-axis fl-x-axis fl-bottom-axis");
var bottom = x_axes
.append("g")
.attr("class", "fl-axis fl-x-axis fl-bottom-axis");
bottom.append("g").attr("class", "fl-axis-line");

@@ -21,3 +26,5 @@ bottom.append("g").attr("class", "fl-axis-ticks");

var right = y_axes.append("g").attr("class", "fl-axis fl-y-axis fl-right-axis");
var right = y_axes
.append("g")
.attr("class", "fl-axis fl-y-axis fl-right-axis");
right.append("g").attr("class", "fl-axis-line");

@@ -24,0 +31,0 @@ right.append("g").attr("class", "fl-axis-ticks");

@@ -5,3 +5,5 @@ function addBackground(chart) {

background.append("image").attr("class", "fl-chart-image");
background.append("rect").attr("class", "fl-chart-interaction")
background
.append("rect")
.attr("class", "fl-chart-interaction")
.style("opacity", 0);

@@ -8,0 +10,0 @@ }

function addDebugRectangle(chart) {
chart.append("rect")
chart
.append("rect")
.attr("class", "fl-chart-debug-rectangle")

@@ -4,0 +5,0 @@ .attr("x", 0)

function addGridlines(chart) {
var gridlines_container = chart.append("g").attr("class", "fl-gridlines").style("pointer-events", "none");
var gridlines_container = chart
.append("g")
.attr("class", "fl-gridlines")
.style("pointer-events", "none");
gridlines_container.append("g").attr("class", "fl-gridlines-vertical");

@@ -4,0 +7,0 @@ gridlines_container.append("g").attr("class", "fl-gridlines-horizontal");

@@ -1,3 +0,13 @@

var ALL_TRUE = Object.freeze({ left: true, top: true, right: true, bottom: true });
var ALL_FALSE = Object.freeze({ left: false, top: false, right: false, bottom: false });
var ALL_TRUE = Object.freeze({
left: true,
top: true,
right: true,
bottom: true,
});
var ALL_FALSE = Object.freeze({
left: false,
top: false,
right: false,
bottom: false,
});

@@ -7,3 +17,3 @@ function initClip(instance) {

return function(value) {
return function (value) {
if (value === undefined) return clip;

@@ -17,3 +27,3 @@ if (!value) clip = ALL_FALSE;

right: !!value.right,
bottom: !!value.bottom
bottom: !!value.bottom,
});

@@ -20,0 +30,0 @@ }

var remToPx;
function updateRemToPx() {
var multiplier = parseFloat(getComputedStyle(document.documentElement).fontSize);
var multiplier = parseFloat(
getComputedStyle(document.documentElement).fontSize,
);
var dpr = window.devicePixelRatio;
remToPx = function(rem, round) {
remToPx = function (rem, round) {
if (!rem) return 0;

@@ -22,3 +24,3 @@ if (!round) return rem * multiplier;

function xyToTranslate(x, y) {
return "translate(" + x + "," + y +")";
return "translate(" + x + "," + y + ")";
}

@@ -32,3 +34,7 @@

var log10 = Math.log10 || function(x) { return Math.log(x) * Math.LOG10E; };
var log10 =
Math.log10 ||
function (x) {
return Math.log(x) * Math.LOG10E;
};

@@ -49,5 +55,11 @@ function getExponent(value) {

function linesIntersect(p, q) {
var x1 = p[0][0], x2 = p[1][0], x3 = q[0][0], x4 = q[1][0];
var y1 = p[0][1], y2 = p[1][1], y3 = q[0][1], y4 = q[1][1];
var denominator = (x1-x2) * (y3-y4) - (x3-x4) * (y1-y2);
var x1 = p[0][0],
x2 = p[1][0],
x3 = q[0][0],
x4 = q[1][0];
var y1 = p[0][1],
y2 = p[1][1],
y3 = q[0][1],
y4 = q[1][1];
var denominator = (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2);

@@ -57,13 +69,14 @@ // Parallel lines

if (
(x1 < x3 && x1 < x4 && x2 < x3 && x2 < x4) // p is left of q
|| (x1 > x3 && x1 > x4 && x2 > x3 && x2 > x4) // p is right of q
|| (y1 < y3 && y1 < y4 && y2 < y3 && y2 < y4) // p is above q
|| (y1 > y3 && y1 > y4 && y2 > y3 && y2 > y4) // p is below q
) return false;
(x1 < x3 && x1 < x4 && x2 < x3 && x2 < x4) || // p is left of q
(x1 > x3 && x1 > x4 && x2 > x3 && x2 > x4) || // p is right of q
(y1 < y3 && y1 < y4 && y2 < y3 && y2 < y4) || // p is above q
(y1 > y3 && y1 > y4 && y2 > y3 && y2 > y4) // p is below q
)
return false;
return true;
}
var t = ((x1-x3)*(y3-y4) - (y1-y3)*(x3-x4)) / denominator;
var t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / denominator;
if (t < 0 || t > 1) return false; // point of intersection does not fall within the p line segment
var u = -((x1-x2)*(y1-y3) - (y1-y2)*(x1-x3)) / denominator;
var u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denominator;
if (u < 0 || u > 1) return false; // point of intersection does not fall within the q line segment

@@ -89,3 +102,3 @@

var scaleWrapper = function(unscaled_value) {
var scaleWrapper = function (unscaled_value) {
var val = scale(unscaled_value);

@@ -109,4 +122,4 @@ // Catch values that will break SVG transforms

// Having the range and domain easily accessible is useful, so apply these functions
COPIED_METHODS.forEach(function(name) {
scaleWrapper[name] = function() {
COPIED_METHODS.forEach(function (name) {
scaleWrapper[name] = function () {
var result = scale[name].apply(scale, arguments);

@@ -119,3 +132,5 @@ // Return the wrapper rather than the wrapped scale object

// Add a custom copy method and the type and step properties to the wrapper
scaleWrapper.copy = function() { return safeScale(scale); };
scaleWrapper.copy = function () {
return safeScale(scale);
};
scaleWrapper.type = scale.type;

@@ -136,5 +151,8 @@ scaleWrapper.step = scale.step;

function textareaToArray(text_string) {
return text_string.split("\n")
.filter(function(d) { return d; })
.map(function(d) { return d.trim(); });
return text_string
.split("\n")
.filter(Boolean)
.map(function (d) {
return d.trim();
});
}

@@ -155,3 +173,3 @@

isValidDate,
textareaToArray
textareaToArray,
};

@@ -11,13 +11,15 @@ import { select } from "d3-selection";

container = select(target.node()); // Make sure we have a select not selectAll
}
else container = select(target);
} else container = select(target);
var container_node = container.node();
if (!container_node) throw new Error("Chart layout instance must have a target");
if (!container_node)
throw new Error("Chart layout instance must have a target");
var container_is_svg = isSvg(container_node);
var getSvg = function() {
var getSvg = function () {
if (container_is_svg) return container;
var current_node = container_node.parentNode;
while (current_node && !isSvg(current_node)) current_node = current_node.parentNode;
if (!isSvg(current_node)) throw new Error("target must be an SVG or a descendant of an SVG");
while (current_node && !isSvg(current_node))
current_node = current_node.parentNode;
if (!isSvg(current_node))
throw new Error("target must be an SVG or a descendant of an SVG");
return select(current_node);

@@ -24,0 +26,0 @@ };

@@ -1,2 +0,6 @@

import { createNumericArray, createStringArray, createDatetimeArray } from "@flourish/enhanced-arrays";
import {
createNumericArray,
createStringArray,
createDatetimeArray,
} from "@flourish/enhanced-arrays";
import { isDate } from "../common/index.js";

@@ -11,3 +15,7 @@

var acc = accessor || function(x) { return x; };
var acc =
accessor ||
function (x) {
return x;
};

@@ -28,3 +36,3 @@ for (var i = 0; i < input_data.length; i++) {

return function(data, accessor) {
return function (data, accessor) {
if (data === undefined) return current_data;

@@ -31,0 +39,0 @@ current_data = getFrozenData(data, accessor);

function initDebug(instance) {
let debug = false;
return function(value) {
return function (value) {
if (value === undefined) return debug;

@@ -14,3 +14,3 @@ debug = !!value;

return function(value) {
return function (value) {
if (value === undefined) return color;

@@ -17,0 +17,0 @@ color = value;

@@ -7,3 +7,3 @@ function initDimensions(instance) {

dimensions.width = function(value) {
dimensions.width = function (value) {
if (value === undefined) {

@@ -17,7 +17,11 @@ if (width !== null) return width;

dimensions.height = function(value) {
dimensions.height = function (value) {
if (value === undefined) {
if (height !== null) return height;
else if (plot_aspect !== null) {
return dimensions.plotHeight() + instance.margins.top + instance.margins.bottom;
return (
dimensions.plotHeight() +
instance.margins.top +
instance.margins.bottom
);
}

@@ -31,3 +35,3 @@ return instance.svg.node().getBoundingClientRect().height;

dimensions.plotAspect = function(value) {
dimensions.plotAspect = function (value) {
if (value === undefined) {

@@ -42,9 +46,11 @@ if (plot_aspect !== null) return plot_aspect;

dimensions.plotWidth = function() {
dimensions.plotWidth = function () {
return instance.width() - (instance.margins.right + instance.margins.left);
};
dimensions.plotHeight = function() {
dimensions.plotHeight = function () {
if (plot_aspect === null) {
return dimensions.height() - (instance.margins.top + instance.margins.bottom);
return (
dimensions.height() - (instance.margins.top + instance.margins.bottom)
);
}

@@ -54,25 +60,31 @@ return dimensions.plotWidth() / plot_aspect;

dimensions.innerWidth = function() {
dimensions.innerWidth = function () {
const { inner_margins } = instance;
return Math.max(0, dimensions.plotWidth() - (inner_margins.right + inner_margins.left));
return Math.max(
0,
dimensions.plotWidth() - (inner_margins.right + inner_margins.left),
);
};
dimensions.innerHeight = function() {
dimensions.innerHeight = function () {
const { inner_margins } = instance;
return Math.max(0, dimensions.plotHeight() - (inner_margins.top + inner_margins.bottom));
return Math.max(
0,
dimensions.plotHeight() - (inner_margins.top + inner_margins.bottom),
);
};
dimensions.xLeft = function() {
dimensions.xLeft = function () {
return instance.margins.left;
};
dimensions.xRight = function() {
dimensions.xRight = function () {
return instance.width() - instance.margins.right;
};
dimensions.yBottom = function() {
dimensions.yBottom = function () {
return instance.height() - instance.margins.bottom;
};
dimensions.yTop = function() {
dimensions.yTop = function () {
return instance.margins.top;

@@ -87,3 +99,3 @@ };

return function(value) {
return function (value) {
if (value === undefined) return left_offset;

@@ -98,3 +110,3 @@ else left_offset = value;

return function(value) {
return function (value) {
if (value === undefined) return top_offset;

@@ -101,0 +113,0 @@ else top_offset = value;

@@ -1,6 +0,8 @@

function defaultFormat(value) { return "" + value; }
function defaultFormat(value) {
return "" + value;
}
function initFormat(instance) {
var currentFormat = defaultFormat;
return function(func) {
return function (func) {
if (func === undefined) return currentFormat || defaultFormat;

@@ -7,0 +9,0 @@ else currentFormat = func;

@@ -5,6 +5,8 @@ function initHide(instance) {

return function(value) {
if (value === undefined) return hide ? {keep_gridlines: keep_gridlines} : false;
return function (value) {
if (value === undefined)
return hide ? { keep_gridlines: keep_gridlines } : false;
hide = !!value;
keep_gridlines = (value && typeof value === "object" && value.keep_gridlines) ? true : false;
keep_gridlines =
value && typeof value === "object" && value.keep_gridlines ? true : false;
return instance;

@@ -11,0 +13,0 @@ };

@@ -6,3 +6,3 @@ var counter = 0;

return function(value) {
return function (value) {
if (value === undefined) return identifier;

@@ -9,0 +9,0 @@ identifier = value;

@@ -10,3 +10,7 @@ import { prepareState } from "./state/index.js";

import { initNumberParse, initDatetimeParse } from "./parse/index.js";
import { initDimensions, initOffsetLeft, initOffsetTop } from "./dimensions/index.js";
import {
initDimensions,
initOffsetLeft,
initOffsetTop,
} from "./dimensions/index.js";
import { initData } from "./data/index.js";

@@ -19,3 +23,3 @@ import {

initYAutoTicks,
initY2AutoTicks
initY2AutoTicks,
} from "./ticks/index.js";

@@ -35,3 +39,3 @@ import { initXTitle, initYTitle, initY2Title } from "./axis-titles/index.js";

initYPadding,
initY2Padding
initY2Padding,
} from "./scales/index.js";

@@ -47,3 +51,3 @@ import { initHide } from "./hide/index.js";

* whose values are objects.
*/
*/
function initChartLayout(target, state) {

@@ -61,7 +65,7 @@ state = prepareState(state);

/*
* "data_background" and "data_foreground" are container groups intended to be filled with visual
* "data_background" and "data_foreground" are container groups intended to be filled with visual
* representations of data - eg the circles in a scatter plot or the rectangles of a bar chart.
* The "data_background" group lies behind the gridlines and axes while the "data_foreground"
* group lies on top of these elements.
*/
*/
instance.data_background = instance.chart.select("g.fl-data-background");

@@ -74,3 +78,3 @@ instance.data_foreground = instance.chart.select("g.fl-data-foreground");

* It's not used as an id itself (though maybe it should be?).
*/
*/
instance.identifier = initIdentifier(instance);

@@ -81,3 +85,3 @@

* This can be useful, eg, when trying to position multiple chart-layout instances in a grid.
*/
*/
instance.debug = initDebug(instance);

@@ -101,6 +105,12 @@ instance.debugColor = initDebugColor(instance);

Object.defineProperty(instance, "plot_width", { get: dimensions.plotWidth });
Object.defineProperty(instance, "plot_height", { get: dimensions.plotHeight });
Object.defineProperty(instance, "plot_height", {
get: dimensions.plotHeight,
});
Object.defineProperty(instance, "inner_width", { get: dimensions.innerWidth });
Object.defineProperty(instance, "inner_height", { get: dimensions.innerHeight });
Object.defineProperty(instance, "inner_width", {
get: dimensions.innerWidth,
});
Object.defineProperty(instance, "inner_height", {
get: dimensions.innerHeight,
});

@@ -133,3 +143,3 @@ // Calculated coordinates of the corners of the plot area.

* as the min and max values and sorted values.
*/
*/
instance.xData = initData(instance);

@@ -136,0 +146,0 @@ instance.yData = initData(instance);

@@ -11,3 +11,4 @@ import { remToPx, getFont } from "../common/index.js";

var title_selection = title_container.append("text")
var title_selection = title_container
.append("text")
.text(title_text)

@@ -30,3 +31,4 @@ .style("opacity", 0)

var title_selection = title_container.append("text")
var title_selection = title_container
.append("text")
.text(title_text)

@@ -51,3 +53,4 @@ .style("opacity", 0)

var title_selection = title_container.append("text")
var title_selection = title_container
.append("text")
.text(title_text)

@@ -72,3 +75,8 @@ .style("opacity", 0)

var ticks = instance.xTicks();
tick_space = ticks.length && x.tick_side === "out" && x.tick_label_position === "default" ? remToPx(x.tick_length) : 0;
tick_space =
ticks.length &&
x.tick_side === "out" &&
x.tick_label_position === "default"
? remToPx(x.tick_length)
: 0;
tick_label_space = ticks.max_box_height || 0;

@@ -89,3 +97,4 @@ tick_padding = ticks.length ? remToPx(x.tick_padding) : 0;

var y_offset = 0, y2_offset = 0;
var y_offset = 0,
y2_offset = 0;

@@ -95,4 +104,6 @@ var y_ticks = !instance.yHide() ? instance.yTicks() : [];

var last_y_tick = y_ticks[y_ticks.length - 1]; // Assume last tick is placed at the top of the axis
if (state.y.tick_label_position == "default") y_offset = 0.9 * last_y_tick.box_height_above;
else if (state.y.tick_label_position == "above") y_offset += last_y_tick.box_height;
if (state.y.tick_label_position == "default")
y_offset = 0.9 * last_y_tick.box_height_above;
else if (state.y.tick_label_position == "above")
y_offset += last_y_tick.box_height;
}

@@ -106,4 +117,6 @@ if (state.y.title_position === "end" && !x_axis_above) {

var last_y2_tick = y2_ticks[y2_ticks.length - 1]; // Assume last tick is placed at the top of the axis
if (state.y2.tick_label_position == "default") y2_offset = 0.9 * last_y2_tick.box_height_above;
else if (state.y2.tick_label_position == "above") y2_offset += last_y2_tick.box_height;
if (state.y2.tick_label_position == "default")
y2_offset = 0.9 * last_y2_tick.box_height_above;
else if (state.y2.tick_label_position == "above")
y2_offset += last_y2_tick.box_height;
}

@@ -126,10 +139,17 @@ if (state.y2.title_position === "end" && !x_axis_above) {

var y_offset = 0, y2_offset = 0;
var y_offset = 0,
y2_offset = 0;
var y_ticks = !instance.yHide() ? instance.yTicks() : [];
if (y_ticks.length) {
var first_y_tick = y_ticks[0]; // Assume first tick is placed at the bottom of the axis
if (state.y.tick_label_position == "default") y_offset = 0.9 * first_y_tick.box_height_below;
else if (state.y.tick_label_position == "below") y_offset += first_y_tick.box_height;
if (state.y.tick_label_position == "default")
y_offset = 0.9 * first_y_tick.box_height_below;
else if (state.y.tick_label_position == "below")
y_offset += first_y_tick.box_height;
}
if (state.y.title_position === "end" && !x_axis_below && x.axis_position !== "off") {
if (
state.y.title_position === "end" &&
!x_axis_below &&
x.axis_position !== "off"
) {
y_offset += getYTitleHeight(instance, state);

@@ -141,6 +161,12 @@ }

var first_y2_tick = y2_ticks[0]; // Assume first tick is placed at the bottom of the axis
if (state.y2.tick_label_position == "default") y2_offset = 0.9 * first_y2_tick.box_height_below;
else if (state.y2.tick_label_position == "below") y2_offset += first_y2_tick.box_height;
if (state.y2.tick_label_position == "default")
y2_offset = 0.9 * first_y2_tick.box_height_below;
else if (state.y2.tick_label_position == "below")
y2_offset += first_y2_tick.box_height;
}
if (state.y2.title_position === "end" && !x_axis_below && x.axis_position !== "off") {
if (
state.y2.title_position === "end" &&
!x_axis_below &&
x.axis_position !== "off"
) {
y2_offset += getY2TitleHeight(instance, state);

@@ -159,3 +185,8 @@ }

var ticks = !instance.yHide() ? instance.yTicks() : [];
var tick_space = ticks.length && y.tick_side === "out" && y.tick_label_position === "default" ? remToPx(y.tick_length) : 0;
var tick_space =
ticks.length &&
y.tick_side === "out" &&
y.tick_label_position === "default"
? remToPx(y.tick_length)
: 0;
var tick_padding = ticks.length ? remToPx(y.tick_padding) : 0;

@@ -169,8 +200,11 @@ var tick_label_space = ticks.max_box_width || 0;

// Space for overflowing x tick
var x_overflow = remToPx(0.25), offset = 0;
var x_overflow = remToPx(0.25),
offset = 0;
var x_ticks = !instance.xHide() ? instance.xTicks() : [];
if (x_ticks.length) {
var first_x_tick = x_ticks[0]; // Assume first tick is placed at the left edge of the axis
if (state.x.tick_label_position == "default") offset = 0.9 * first_x_tick.box_width_left;
else if (state.x.tick_label_position == "left") offset = first_x_tick.box_width;
if (state.x.tick_label_position == "default")
offset = 0.9 * first_x_tick.box_width_left;
else if (state.x.tick_label_position == "left")
offset = first_x_tick.box_width;
x_overflow = Math.max(x_overflow, offset);

@@ -188,3 +222,8 @@ }

var y2_ticks = !instance.y2Hide() ? instance.y2Ticks() : [];
var tick_space = y2_ticks.length && (y2.tick_side === "out" && y2.tick_label_position === "default") ? remToPx(y2.tick_length) : 0;
var tick_space =
y2_ticks.length &&
y2.tick_side === "out" &&
y2.tick_label_position === "default"
? remToPx(y2.tick_length)
: 0;
var tick_padding = y2_ticks.length ? remToPx(y2.tick_padding) : 0;

@@ -198,8 +237,11 @@ var tick_label_space = y2_ticks.max_box_width || 0;

// Space for overflowing x tick
var x_overflow = remToPx(0.25), offset = 0;
var x_overflow = remToPx(0.25),
offset = 0;
var x_ticks = !instance.xHide() ? instance.xTicks() : [];
if (x_ticks.length) {
var last_x_tick = x_ticks[x_ticks.length - 1]; // Assume last tick is placed at the right edge of the axis
if (state.x.tick_label_position == "default") offset = 0.9 * last_x_tick.box_width_right;
else if (state.x.tick_label_position == "right") offset = last_x_tick.box_width;
if (state.x.tick_label_position == "default")
offset = 0.9 * last_x_tick.box_width_right;
else if (state.x.tick_label_position == "right")
offset = last_x_tick.box_width;
x_overflow = Math.max(x_overflow, offset);

@@ -216,3 +258,3 @@ }

var updateMargins = function(overrides) {
var updateMargins = function (overrides) {
overrides = overrides || {};

@@ -230,3 +272,3 @@ calculated_top = calculateTopMargin(instance, state);

var applyOverride = function(override, calculated) {
var applyOverride = function (override, calculated) {
if (typeof override === "function") {

@@ -241,7 +283,7 @@ override = override(calculated);

var margins = function() {
var margins = function () {
return { top: top, right: right, bottom: bottom, left: left };
};
margins._calculated = function() {
margins._calculated = function () {
return {

@@ -251,3 +293,3 @@ top: calculated_top,

bottom: calculated_bottom,
left: calculated_left
left: calculated_left,
};

@@ -258,6 +300,22 @@ };

Object.defineProperty(margins, "top", { get: function() { return top; } });
Object.defineProperty(margins, "right", { get: function() { return right; } });
Object.defineProperty(margins, "bottom", { get: function() { return bottom; } });
Object.defineProperty(margins, "left", { get: function() { return left; } });
Object.defineProperty(margins, "top", {
get: function () {
return top;
},
});
Object.defineProperty(margins, "right", {
get: function () {
return right;
},
});
Object.defineProperty(margins, "bottom", {
get: function () {
return bottom;
},
});
Object.defineProperty(margins, "left", {
get: function () {
return left;
},
});

@@ -271,3 +329,3 @@ return margins;

var updateMargins = function(overrides) {
var updateMargins = function (overrides) {
overrides = overrides || {};

@@ -281,3 +339,3 @@

var inner_margins = function() {
var inner_margins = function () {
return { top: top, right: right, bottom: bottom, left: left };

@@ -288,6 +346,22 @@ };

Object.defineProperty(inner_margins, "top", { get: function() { return top; } });
Object.defineProperty(inner_margins, "right", { get: function() { return right; } });
Object.defineProperty(inner_margins, "bottom", { get: function() { return bottom; } });
Object.defineProperty(inner_margins, "left", { get: function() { return left; } });
Object.defineProperty(inner_margins, "top", {
get: function () {
return top;
},
});
Object.defineProperty(inner_margins, "right", {
get: function () {
return right;
},
});
Object.defineProperty(inner_margins, "bottom", {
get: function () {
return bottom;
},
});
Object.defineProperty(inner_margins, "left", {
get: function () {
return left;
},
});

@@ -294,0 +368,0 @@ return inner_margins;

function createXOffset(instance) {
var left_offset = 0;
return function(value) {
return function (value) {
if (value === undefined) return left_offset;

@@ -14,3 +14,3 @@ else left_offset = value;

return function(value) {
return function (value) {
if (value === undefined) return top_offset;

@@ -17,0 +17,0 @@ else top_offset = value;

@@ -8,3 +8,3 @@ import { timeParse } from "d3-time-format";

var currentNumberParser = defaultNumberParser;
return function(func) {
return function (func) {
if (func === undefined) return currentNumberParser || defaultNumberParser;

@@ -18,4 +18,5 @@ else currentNumberParser = func;

var currentDatetimeParser = defaultDatetimeParser;
return function(func) {
if (func === undefined) return currentDatetimeParser || defaultDatetimeParser;
return function (func) {
if (func === undefined)
return currentDatetimeParser || defaultDatetimeParser;
else currentDatetimeParser = func;

@@ -22,0 +23,0 @@ return instance;

function initZeroAxis(instance) {
var zero_axis = false;
return function(value) {
return function (value) {
if (value === undefined) return zero_axis;

@@ -13,3 +13,3 @@ zero_axis = !!value;

return function(value) {
return function (value) {
if (value === undefined) return flip;

@@ -16,0 +16,0 @@ flip = !!value;

@@ -5,5 +5,7 @@ import { scaleLinear, scaleLog, scalePoint, scaleUtc } from "d3-scale";

function getPointScale(data, {edge_padding, flip}) {
function getPointScale(data, { edge_padding, flip }) {
var domain = flip ? data.unique().reverse() : data.unique();
var scale = scalePoint().domain(domain).padding(edge_padding/100);
var scale = scalePoint()
.domain(domain)
.padding(edge_padding / 100);
scale.type = "ordinal";

@@ -13,3 +15,3 @@ return scale;

function getLinearDomain(data, {min, max, include_zero, nice, flip}) {
function getLinearDomain(data, { min, max, include_zero, nice, flip }) {
const FALLBACK_DOMAIN_RANGE = 100; // If we can't construct a sensible default domain, make an arbitrary one this wide

@@ -21,3 +23,4 @@ if (min === max) min = max = null; // If min and max are equal then ignore them both

let domain;
if (data.range) { // Standard case: multiple different values
if (data.range) {
// Standard case: multiple different values
domain = data.extent();

@@ -30,10 +33,11 @@ if (nice) domain = scaleLinear().domain(domain).nice().domain();

}
}
else if (data.length) { // Only one unique value
} else if (data.length) {
// Only one unique value
var value = data.min;
if (value > 0) domain = [0, 2 * value]; // Place value in middle of domain starting at 0
else if (value < 0) domain = [2 * value, 0]; // Place value in middle of domain ending at 0
else domain = [-FALLBACK_DOMAIN_RANGE/2, FALLBACK_DOMAIN_RANGE/2]; // Domain centred on 0 with arbitrary min and max
}
else domain = [0, FALLBACK_DOMAIN_RANGE]; // No values at all: pick arbitrary domain values
if (value > 0)
domain = [0, 2 * value]; // Place value in middle of domain starting at 0
else if (value < 0)
domain = [2 * value, 0]; // Place value in middle of domain ending at 0
else domain = [-FALLBACK_DOMAIN_RANGE / 2, FALLBACK_DOMAIN_RANGE / 2]; // Domain centred on 0 with arbitrary min and max
} else domain = [0, FALLBACK_DOMAIN_RANGE]; // No values at all: pick arbitrary domain values

@@ -43,8 +47,9 @@ if (min !== null) {

// If domain values now match we need to do something, so change the non-specified max value
if (domain[0] === domain[1]) domain[1] = min + (data.range || FALLBACK_DOMAIN_RANGE);
}
else if (max !== null) {
if (domain[0] === domain[1])
domain[1] = min + (data.range || FALLBACK_DOMAIN_RANGE);
} else if (max !== null) {
domain[1] = max;
// If domain values now match we need to do something, so change the non-specified min value
if (domain[0] === domain[1]) domain[0] = max - (data.range || FALLBACK_DOMAIN_RANGE);
if (domain[0] === domain[1])
domain[0] = max - (data.range || FALLBACK_DOMAIN_RANGE);
}

@@ -62,7 +67,7 @@

function getLogScale(data, {min, max, nice, flip}) {
function getLogScale(data, { min, max, nice, flip }) {
// Get suitable values for the domain based on data
const extent = data.extent();
if (extent[0] <= 0) {
if (extent[1] > 0) extent[0] = Math.min(1, extent[1]/LOG_SCALE_FACTOR);
if (extent[1] > 0) extent[0] = Math.min(1, extent[1] / LOG_SCALE_FACTOR);
else extent[0] = 1;

@@ -85,3 +90,3 @@ }

function getDatetimeScale(data, {min, max, format, nice, flip}) {
function getDatetimeScale(data, { min, max, format, nice, flip }) {
const extent = data.extent();

@@ -102,7 +107,2 @@ const scale = scaleUtc().domain(extent);

export {
getPointScale,
getLinearScale,
getLogScale,
getDatetimeScale
};
export { getPointScale, getLinearScale, getLogScale, getDatetimeScale };
function minStep(data, scale) {
if (scale.step) return scale.step();
const scaled_data = data.uniqueAscending().map(d => scale(d));
const scaled_data = data.uniqueAscending().map((d) => scale(d));
const n = scaled_data.length;

@@ -10,3 +10,3 @@ if (n < 2) return 0;

for (let i = 1; i < n; i++) {
const step = Math.abs(scaled_data[i] - scaled_data[i-1]);
const step = Math.abs(scaled_data[i] - scaled_data[i - 1]);
min_step = Math.min(min_step, step);

@@ -13,0 +13,0 @@ }

@@ -1,6 +0,11 @@

import { getPointScale, getLinearScale, getLogScale, getDatetimeScale } from "./scales.js";
import {
getPointScale,
getLinearScale,
getLogScale,
getDatetimeScale,
} from "./scales.js";
import { minStep } from "./utils.js";
function initXPadding(instance) {
const UNITS = [ "px", "steps" ];
const UNITS = ["px", "steps"];
let left = 0;

@@ -10,3 +15,3 @@ let right = 0;

return function(values) {
return function (values) {
if (values === undefined) return { left, right, unit };

@@ -29,3 +34,8 @@ const u = values.unit;

// Ignore developer-set padding on logarithmic axes if not in px
if (x_data.numeric_array && x_state.numeric_scale_type !== "linear" && unit !== "px") return no_padding;
if (
x_data.numeric_array &&
x_state.numeric_scale_type !== "linear" &&
unit !== "px"
)
return no_padding;

@@ -40,3 +50,3 @@ if (unit === "px" || (!left && !right)) return { left, right };

for (let i = 1; i < n; i++) {
const step = Math.abs(unique_values[i] - unique_values[i-1]);
const step = Math.abs(unique_values[i] - unique_values[i - 1]);
min_data_step = Math.min(min_data_step, step);

@@ -46,3 +56,3 @@ }

const domain_width = Math.max(...domain) - Math.min(...domain); // in domain units
const full_width = domain_width + ((left + right) * min_data_step); // in domain units
const full_width = domain_width + (left + right) * min_data_step; // in domain units
const n_min_steps = full_width / min_data_step;

@@ -57,3 +67,3 @@ const step_width = instance.inner_width / n_min_steps; // in pixels

return function(opts = {}) {
return function (opts = {}) {
const x_data = instance.xData();

@@ -65,4 +75,3 @@ const settings = { nice: x.nice, flip: instance.xFlipAxis() !== x.flip };

settings.edge_padding = x.edge_padding;
}
else if (x_data.datetime_array) {
} else if (x_data.datetime_array) {
getScale = getDatetimeScale;

@@ -72,13 +81,16 @@ settings.min = x.datetime_min;

settings.format = instance.xDatetimeParse();
}
else if (x.numeric_scale_type === "log") {
} else if (x.numeric_scale_type === "log") {
getScale = getLogScale;
settings.min = x.log_min;
settings.max = x.log_max;
}
else {
} else {
getScale = getLinearScale;
settings.min = x.linear_min;
settings.max = x.linear_max;
settings.include_zero = x.zero_axis === "off" ? false : (x.zero_axis === "on" ? true : instance.xZeroAxis());
settings.include_zero =
x.zero_axis === "off"
? false
: x.zero_axis === "on"
? true
: instance.xZeroAxis();
}

@@ -94,5 +106,8 @@

const range_start = left_margin + left;
let range = [ range_start, range_start + effective_width ];
let range = [range_start, range_start + effective_width];
const offset = opts.global && instance.offsetLeft();
if (offset) range = range.map(function(x) { return x + offset; });
if (offset)
range = range.map(function (x) {
return x + offset;
});

@@ -104,3 +119,3 @@ return xScale.range(range);

function initXMinStep(instance) {
return function() {
return function () {
return minStep(instance.xData(), instance.xScale());

@@ -107,0 +122,0 @@ };

@@ -1,6 +0,11 @@

import { getPointScale, getLinearScale, getLogScale, getDatetimeScale } from "./scales.js";
import {
getPointScale,
getLinearScale,
getLogScale,
getDatetimeScale,
} from "./scales.js";
import { minStep } from "./utils.js";
function initYPadding(instance) {
const UNITS = [ "px", "steps" ];
const UNITS = ["px", "steps"];
let bottom = 0;

@@ -10,3 +15,3 @@ let top = 0;

return function(values) {
return function (values) {
if (values === undefined) return { bottom, top, unit };

@@ -29,3 +34,8 @@ const u = values.unit;

// Ignore developer-set padding on logarithmic axes if not in px
if (y_data.numeric_array && y_state.numeric_scale_type !== "linear" && unit !== "px") return no_padding;
if (
y_data.numeric_array &&
y_state.numeric_scale_type !== "linear" &&
unit !== "px"
)
return no_padding;

@@ -40,3 +50,3 @@ if (unit === "px" || (!bottom && !top)) return { bottom, top };

for (let i = 1; i < n; i++) {
const step = Math.abs(unique_values[i] - unique_values[i-1]);
const step = Math.abs(unique_values[i] - unique_values[i - 1]);
min_data_step = Math.min(min_data_step, step);

@@ -46,3 +56,3 @@ }

const domain_width = Math.max(...domain) - Math.min(...domain); // in domain units
const full_width = domain_width + ((bottom + top) * min_data_step); // in domain units
const full_width = domain_width + (bottom + top) * min_data_step; // in domain units
const n_min_steps = full_width / min_data_step;

@@ -57,3 +67,3 @@ const step_width = instance.inner_height / n_min_steps; // in pixels

return function(opts = {}) {
return function (opts = {}) {
var y_data = instance.yData();

@@ -66,4 +76,3 @@

settings.edge_padding = y.edge_padding;
}
else if (y_data.datetime_array) {
} else if (y_data.datetime_array) {
getScale = getDatetimeScale;

@@ -73,13 +82,16 @@ settings.min = y.datetime_min;

settings.format = instance.yDatetimeParse();
}
else if (y.numeric_scale_type === "log") {
} else if (y.numeric_scale_type === "log") {
getScale = getLogScale;
settings.min = y.log_min;
settings.max = y.log_max;
}
else {
} else {
getScale = getLinearScale;
settings.min = y.linear_min;
settings.max = y.linear_max;
settings.include_zero = y.zero_axis === "off" ? false : (y.zero_axis === "on" ? true : instance.yZeroAxis());
settings.include_zero =
y.zero_axis === "off"
? false
: y.zero_axis === "on"
? true
: instance.yZeroAxis();
}

@@ -96,4 +108,7 @@

const range_start = top_margin + top;
let range = [ range_start + effective_height, range_start ];
if (offset) range = range.map(function(y) { return y + offset; });
let range = [range_start + effective_height, range_start];
if (offset)
range = range.map(function (y) {
return y + offset;
});

@@ -105,3 +120,3 @@ return yScale.range(range);

function initYMinStep(instance) {
return function() {
return function () {
return minStep(instance.yData(), instance.yScale());

@@ -108,0 +123,0 @@ };

@@ -1,6 +0,11 @@

import { getPointScale, getLinearScale, getLogScale, getDatetimeScale } from "./scales.js";
import {
getPointScale,
getLinearScale,
getLogScale,
getDatetimeScale,
} from "./scales.js";
import { minStep } from "./utils.js";
function initY2Padding(instance) {
const UNITS = [ "px", "steps" ];
const UNITS = ["px", "steps"];
let bottom = 0;

@@ -10,3 +15,3 @@ let top = 0;

return function(values) {
return function (values) {
if (values === undefined) return { bottom, top, unit };

@@ -29,3 +34,8 @@ const u = values.unit;

// Ignore developer-set padding on logarithmic axes if not in px
if (y2_data.numeric_array && y2_state.numeric_scale_type !== "linear" && unit !== "px") return no_padding;
if (
y2_data.numeric_array &&
y2_state.numeric_scale_type !== "linear" &&
unit !== "px"
)
return no_padding;

@@ -40,3 +50,3 @@ if (unit === "px" || (!bottom && !top)) return { bottom, top };

for (let i = 1; i < n; i++) {
const step = Math.abs(unique_values[i] - unique_values[i-1]);
const step = Math.abs(unique_values[i] - unique_values[i - 1]);
min_data_step = Math.min(min_data_step, step);

@@ -46,3 +56,3 @@ }

const domain_width = Math.max(...domain) - Math.min(...domain); // in domain units
const full_width = domain_width + ((bottom + top) * min_data_step); // in domain units
const full_width = domain_width + (bottom + top) * min_data_step; // in domain units
const n_min_steps = full_width / min_data_step;

@@ -57,3 +67,3 @@ const step_width = instance.inner_width / n_min_steps; // in pixels

return function(opts = {}) {
return function (opts = {}) {
var y2_data = instance.y2Data();

@@ -66,4 +76,3 @@

settings.edge_padding = y2.edge_padding;
}
else if (y2_data.datetime_array) {
} else if (y2_data.datetime_array) {
getScale = getDatetimeScale;

@@ -73,13 +82,16 @@ settings.min = y2.datetime_min;

settings.format = instance.y2DatetimeParse();
}
else if (y2.numeric_scale_type === "log") {
} else if (y2.numeric_scale_type === "log") {
getScale = getLogScale;
settings.min = y2.log_min;
settings.max = y2.log_max;
}
else {
} else {
getScale = getLinearScale;
settings.min = y2.linear_min;
settings.max = y2.linear_max;
settings.include_zero = y2.zero_axis === "off" ? false : (y2.zero_axis === "on" ? true : instance.y2ZeroAxis());
settings.include_zero =
y2.zero_axis === "off"
? false
: y2.zero_axis === "on"
? true
: instance.y2ZeroAxis();
}

@@ -96,4 +108,7 @@

const range_start = top_margin + top;
let range = [ range_start + effective_height, range_start ];
if (offset) range = range.map(function(y) { return y + offset; });
let range = [range_start + effective_height, range_start];
if (offset)
range = range.map(function (y) {
return y + offset;
});

@@ -105,3 +120,3 @@ return yScale.range(range);

function initY2MinStep(instance) {
return function() {
return function () {
return minStep(instance.y2Data(), instance.y2Scale());

@@ -108,0 +123,0 @@ };

function fillInDefaults(target, defaults) {
Object.keys(defaults).forEach(function(key) {
Object.keys(defaults).forEach(function (key) {
if (target[key] === undefined) target[key] = defaults[key];

@@ -4,0 +4,0 @@ });

@@ -55,5 +55,5 @@ var X_DEFAULTS = Object.freeze({

title_weight: "bold",
title_padding: 0.6
title_padding: 0.6,
});
export { X_DEFAULTS };

@@ -52,9 +52,9 @@ import { fillInDefaults } from "./common.js";

title_weight: "bold",
title_padding: 0.6
title_padding: 0.6,
});
var Y2_DEFAULTS = Object.freeze(
fillInDefaults({ axis_visible: false }, Y_DEFAULTS)
fillInDefaults({ axis_visible: false }, Y_DEFAULTS),
);
export { Y_DEFAULTS, Y2_DEFAULTS };
import { select } from "d3-selection";
import { remToPx, getFont, getSignificantDigitCount, getExponent } from "../common/index.js";
import {
remToPx,
getFont,
getSignificantDigitCount,
getExponent,
} from "../common/index.js";

@@ -12,3 +17,3 @@ var DUMMY_TEXT = "Testing";

var last_value;
return tick_array.filter(function(value) {
return tick_array.filter(function (value) {
var fv = format(value);

@@ -23,3 +28,4 @@ if (fv === last_value) return;

var max_space = params.max_space !== undefined ? params.max_space : 100;
var text_height = params.text_height !== undefined ? params.text_height : remToPx(1);
var text_height =
params.text_height !== undefined ? params.text_height : remToPx(1);
var max_lines = params.max_lines;

@@ -35,3 +41,3 @@ var angle = params.angle || 0;

return function(text) {
return function (text) {
if (typeof text == "number") text = text.toString();

@@ -81,6 +87,9 @@ if (!text) text = "";

do {
truncated_string = string.substring(0, string.length - remove_counter) + "…";
truncated_string =
string.substring(0, string.length - remove_counter) + "…";
string_width = ctx.measureText(truncated_string).width;
}
while ((string_width > max_width) && (++remove_counter < string.length));
} while (
string_width > max_width &&
++remove_counter < string.length
);
max_line_width = Math.max(max_line_width, string_width);

@@ -98,3 +107,3 @@ current_line = truncated_string;

function getAutoLabelSpaceFunction(instance, dimension, min) {
var UNITS = [ "px", "rem", "fraction" ];
var UNITS = ["px", "rem", "fraction"];
dimension = dimension || "width";

@@ -105,3 +114,3 @@ min = typeof min == "number" ? min : 50;

var getValues = function() {
var getValues = function () {
var dim = instance[dimension]();

@@ -111,3 +120,3 @@ var px;

else if (unit === "rem") px = remToPx(value);
else if (unit === "fraction") px = Math.max(min, (value * dim));
else if (unit === "fraction") px = Math.max(min, value * dim);

@@ -118,7 +127,7 @@ return {

fraction: unit === "fraction" ? value : px / dim,
unit: unit
unit: unit,
};
};
return function(v, u) {
return function (v, u) {
if (v === undefined) return getValues();

@@ -136,5 +145,9 @@ value = Math.max(v, 0);

var setTicks = function(tick_array) {
var setTicks = function (tick_array) {
var type = instance.xData().string_array ? "string" : "numeric";
var font = getFont(select(".fl-x-axes"), x.tick_label_size, x.tick_label_weight);
var font = getFont(
select(".fl-x-axes"),
x.tick_label_size,
x.tick_label_weight,
);
var angle = x.tick_label_position === "default" ? +x.tick_label_angle : 90;

@@ -148,7 +161,11 @@ var max_box_height = 0;

group.append("text")
group
.append("text")
.style("opacity", 0)
.style("font", font)
.each(function() {
var bounds = select(this).text(DUMMY_TEXT).node().getBoundingClientRect();
.each(function () {
var bounds = select(this)
.text(DUMMY_TEXT)
.node()
.getBoundingClientRect();
text_height = bounds.height;

@@ -159,17 +176,32 @@ })

// filter out dates that will give repeated tick labels
if (typeof tick_array[0] === "object") tick_array = dropRepeatedLabels(tick_array, format);
if (typeof tick_array[0] === "object")
tick_array = dropRepeatedLabels(tick_array, format);
var max_space = remToPx(x.tick_label_space);
if (x.tick_label_space_mode === "auto") max_space = instance.xTicks.autoLabelSpace().px;
var params = { text_height: text_height, max_space: max_space, font: font, angle: 90 - angle, max_lines: x.tick_label_max_lines };
if (x.tick_label_space_mode === "auto")
max_space = instance.xTicks.autoLabelSpace().px;
var params = {
text_height: text_height,
max_space: max_space,
font: font,
angle: 90 - angle,
max_lines: x.tick_label_max_lines,
};
var fitText = getFitTextFunction(params);
ticks = tick_array.map(function(value, index) {
ticks = tick_array.map(function (value, index) {
var result = fitText(format(value));
var lines = result.lines;
var text_width = result.text_width;
var box_width, box_height, box_width_left, box_width_right, box_height_left, box_height_right;
var box_width,
box_height,
box_width_left,
box_width_right,
box_height_left,
box_height_right;
var multiline_offset = 0;
var total_text_height = (text_height * lines.length) + ((lines.length - 1) * x.tick_label_line_height);
var total_text_height =
text_height * lines.length +
(lines.length - 1) * x.tick_label_line_height;
if (angle === 0 || angle === 90) {

@@ -182,5 +214,9 @@ // Add extra padding for non-rotated text

box_height_right = box_height;
if (angle === 90) multiline_offset = lines.length < 2 ? 0 : ((lines.length - 1)/2 * (font_size * x.tick_label_line_height));
}
else {
if (angle === 90)
multiline_offset =
lines.length < 2
? 0
: ((lines.length - 1) / 2) *
(font_size * x.tick_label_line_height);
} else {
/*

@@ -214,7 +250,12 @@ tl------tr <- rotate about tr

// the lines to flow upwards not downwards
if (angle !== 0 && angle !== 90) multiline_offset = lines.length < 2 ? 0 : (lines.length - 1) * (font_size * x.tick_label_line_height);
if (angle !== 0 && angle !== 90)
multiline_offset =
lines.length < 2
? 0
: (lines.length - 1) * (font_size * x.tick_label_line_height);
}
max_box_height = Math.max(max_box_height, box_height);
var significant_digits = type === "numeric" ? getSignificantDigitCount(value) : null;
var significant_digits =
type === "numeric" ? getSignificantDigitCount(value) : null;
var exponent = type === "numeric" ? getExponent(value) : null;

@@ -236,3 +277,3 @@

box_height_right: box_height_right,
multiline_offset: multiline_offset
multiline_offset: multiline_offset,
});

@@ -242,3 +283,6 @@ });

ticks.type = type;
ticks.max_box_height = x.tick_label_space_mode === "fixed" ? remToPx(x.tick_label_space) : max_box_height;
ticks.max_box_height =
x.tick_label_space_mode === "fixed"
? remToPx(x.tick_label_space)
: max_box_height;
Object.freeze(ticks);

@@ -249,3 +293,5 @@

var getTicks = function() { return ticks; };
var getTicks = function () {
return ticks;
};
getTicks._update = setTicks;

@@ -265,5 +311,9 @@ getTicks.autoLabelSpace = getAutoLabelSpaceFunction(instance, "height", 120);

var setTicks = function(tick_array) {
var setTicks = function (tick_array) {
var type = instance[data_name]().string_array ? "string" : "numeric";
var font = getFont(select(".fl-y-axes"), y.tick_label_size, y.tick_label_weight);
var font = getFont(
select(".fl-y-axes"),
y.tick_label_size,
y.tick_label_weight,
);
var angle = y.tick_label_position === "default" ? +y.tick_label_angle : 0;

@@ -274,7 +324,11 @@ var max_box_width = 0;

group.append("text")
group
.append("text")
.style("opacity", 0)
.style("font", font)
.each(function() {
var bounds = select(this).text(DUMMY_TEXT).node().getBoundingClientRect();
.each(function () {
var bounds = select(this)
.text(DUMMY_TEXT)
.node()
.getBoundingClientRect();
text_height = bounds.height;

@@ -285,17 +339,32 @@ })

// filter out dates that will give repeated tick labels
if (typeof tick_array[0] === "object") tick_array = dropRepeatedLabels(tick_array, format);
if (typeof tick_array[0] === "object")
tick_array = dropRepeatedLabels(tick_array, format);
var max_space = remToPx(y.tick_label_space);
if (y.tick_label_space_mode === "auto") max_space = instance[ticks_name].autoLabelSpace().px;
var params = { text_height: text_height, max_space: max_space, font: font, angle: angle, max_lines: angle ? 1 : y.tick_label_max_lines };
if (y.tick_label_space_mode === "auto")
max_space = instance[ticks_name].autoLabelSpace().px;
var params = {
text_height: text_height,
max_space: max_space,
font: font,
angle: angle,
max_lines: angle ? 1 : y.tick_label_max_lines,
};
var fitText = getFitTextFunction(params);
ticks = tick_array.map(function(value, index) {
ticks = tick_array.map(function (value, index) {
var result = fitText(format(value));
var lines = result.lines;
var text_width = result.text_width;
var box_width, box_height, box_width_above, box_width_below, box_height_above, box_height_below;
var box_width,
box_height,
box_width_above,
box_width_below,
box_height_above,
box_height_below;
var multiline_offset = 0;
var total_text_height = (text_height * lines.length) + ((lines.length - 1) * y.tick_label_line_height);
var total_text_height =
text_height * lines.length +
(lines.length - 1) * y.tick_label_line_height;
if (angle === 0 || angle === 90) {

@@ -308,5 +377,9 @@ box_width = !angle ? text_width : total_text_height;

box_height_above = box_height_below = box_height / 2;
if (angle === 0) multiline_offset = lines.length < 2 ? 0 : ((lines.length - 1)/2 * (text_height * y.tick_label_line_height));
}
else {
if (angle === 0)
multiline_offset =
lines.length < 2
? 0
: ((lines.length - 1) / 2) *
(text_height * y.tick_label_line_height);
} else {
/*

@@ -329,3 +402,4 @@ tl------tr

max_box_width = Math.max(max_box_width, box_width);
var significant_digits = type === "numeric" ? getSignificantDigitCount(value) : null;
var significant_digits =
type === "numeric" ? getSignificantDigitCount(value) : null;
var exponent = type === "numeric" ? getExponent(value) : null;

@@ -348,3 +422,3 @@

box_height_below: box_height_below,
multiline_offset: multiline_offset
multiline_offset: multiline_offset,
});

@@ -354,3 +428,6 @@ });

ticks.type = type;
ticks.max_box_width = y.tick_label_space_mode === "fixed" ? remToPx(y.tick_label_space) : max_box_width;
ticks.max_box_width =
y.tick_label_space_mode === "fixed"
? remToPx(y.tick_label_space)
: max_box_width;
Object.freeze(ticks);

@@ -361,3 +438,5 @@

var getTicks = function() { return ticks; };
var getTicks = function () {
return ticks;
};
getTicks._update = setTicks;

@@ -379,6 +458,6 @@ getTicks.autoLabelSpace = getAutoLabelSpaceFunction(instance);

function initAutoTicks(instance, axis = "x") {
const DEFAULT = () => instance[axis + "Scale"]({ "domain_only": true }).ticks();
const DEFAULT = () => instance[axis + "Scale"]({ domain_only: true }).ticks();
let value = DEFAULT;
return function(v) {
return function (v) {
if (v === undefined) return value;

@@ -393,3 +472,3 @@ if (v === null) value = DEFAULT;

const func = initAutoTicks(instance, "x");
return v => func(v);
return (v) => func(v);
}

@@ -399,3 +478,3 @@

const func = initAutoTicks(instance, "y");
return v => func(v);
return (v) => func(v);
}

@@ -405,5 +484,12 @@

const func = initAutoTicks(instance, "y2");
return v => func(v);
return (v) => func(v);
}
export { initXTicks, initYTicks, initY2Ticks, initXAutoTicks, initYAutoTicks, initY2AutoTicks };
export {
initXTicks,
initYTicks,
initY2Ticks,
initXAutoTicks,
initYAutoTicks,
initY2AutoTicks,
};

@@ -10,3 +10,3 @@ import { initXAxisUpdating } from "./x-axis.js";

return function() {
return function () {
var x = updateXAxes();

@@ -18,3 +18,3 @@ var y = updateYAxes();

y: y,
y2: y2
y2: y2,
};

@@ -21,0 +21,0 @@ };

import { select } from "d3-selection";
import { remToPx, xyToTranslate, angleToRotate, linesIntersect, safeScale } from "../../common/index.js";
import {
remToPx,
xyToTranslate,
angleToRotate,
linesIntersect,
safeScale,
} from "../../common/index.js";
import { tickSorter, userSelectNone, getDirectionAttribute } from "./common.js";

@@ -23,4 +29,10 @@

if (!oldXScale) oldXScale = xScale;
enteringXScale = oldXScale.type === xScale.type && xScale.type !== "ordinal" ? oldXScale : xScale;
exitingXScale = oldXScale.type === xScale.type && oldXScale.type !== "ordinal" ? xScale : oldXScale;
enteringXScale =
oldXScale.type === xScale.type && xScale.type !== "ordinal"
? oldXScale
: xScale;
exitingXScale =
oldXScale.type === xScale.type && oldXScale.type !== "ordinal"
? xScale
: oldXScale;
line_color = x.line_and_tick_color;

@@ -34,7 +46,11 @@ line_width = remToPx(x.line_and_tick_width, true);

var tick_padding = x_ticks.length ? remToPx(x.tick_padding) : 0;
if (x.axis_position == "top" || x.axis_position == "bottom") axis_height += tick_padding;
if (x.axis_position == "top" || x.axis_position == "bottom")
axis_height += tick_padding;
var ticks_out = x.tick_side === "out";
tick_length = ticks_labels_below ? (remToPx(x.tick_length) * (ticks_out ? 1 : -1)) : axis_height;
tick_length = ticks_labels_below
? remToPx(x.tick_length) * (ticks_out ? 1 : -1)
: axis_height;
tick_label_size = remToPx(x.tick_label_size);
tick_label_distance = (ticks_out && ticks_labels_below ? tick_length : 0) + tick_padding;
tick_label_distance =
(ticks_out && ticks_labels_below ? tick_length : 0) + tick_padding;
title_size = remToPx(x.title_size);

@@ -44,3 +60,3 @@ title_text = instance.xTitle();

var updateBottomAxis = (function() {
var updateBottomAxis = (function () {
var bottom = instance.chart.select("g.fl-bottom-axis");

@@ -52,6 +68,7 @@ var line_container = bottom.select("g.fl-axis-line");

return function() {
return function () {
var pos = x.axis_position;
var measurements = { pos: pos };
var show_this_axis = (!instance.xHide() && ["bottom", "float-below"].indexOf(pos) !== -1);
var show_this_axis =
!instance.xHide() && ["bottom", "float-below"].indexOf(pos) !== -1;
var ticks = show_this_axis ? instance.xTicks() : [];

@@ -63,3 +80,4 @@ var y_bottom = instance.y_bottom;

title_distance += tick_label_distance + ticks.max_box_height;
measurements.extended_gridline = y_bottom + tick_label_distance + ticks.max_box_height;
measurements.extended_gridline =
y_bottom + tick_label_distance + ticks.max_box_height;
}

@@ -75,10 +93,15 @@

if (pos === "float-below") {
axis_y_position_old = getAxisPosition((oldYScale || yScale)(x.y_axis_position), y_bottom_old);
axis_y_position_old = getAxisPosition(
(oldYScale || yScale)(x.y_axis_position),
y_bottom_old,
);
axis_y_position = getAxisPosition(yScale(x.y_axis_position), y_bottom);
}
var line = line_container.selectAll("line")
var line = line_container
.selectAll("line")
.data(show_this_axis && x.line_visible ? [xScale.domain()] : []);
line.exit()
line
.exit()
.style("stroke", line_color)

@@ -95,3 +118,4 @@ .style("stroke-width", line_width)

var line_enter = line.enter()
var line_enter = line
.enter()
.append("line")

@@ -107,3 +131,4 @@ .style("shape-rendering", "crispEdges")

line.merge(line_enter)
line
.merge(line_enter)
.style("stroke", line_color)

@@ -124,35 +149,62 @@ .style("stroke-width", line_width)

var tickLabelTransform = function(d) {
var angle = x.tick_label_position == "default" ? -x.tick_label_angle : -90;
var tickLabelTransform = function (d) {
var angle =
x.tick_label_position == "default" ? -x.tick_label_angle : -90;
var rotate = angleToRotate(angle, 0, 0);
if (x.tick_label_position !== "default") {
var y_offset = x.tick_label_position === "left" ? -0.3 : 1;
return xyToTranslate(0, tick_label_distance) + " " + rotate + " " + xyToTranslate(0, tick_label_size * y_offset);
return (
xyToTranslate(0, tick_label_distance) +
" " +
rotate +
" " +
xyToTranslate(0, tick_label_size * y_offset)
);
}
if (angle === 0) {
return xyToTranslate(d.text_width/2, tick_label_distance + tick_label_size*0.66);
return xyToTranslate(
d.text_width / 2,
tick_label_distance + tick_label_size * 0.66,
);
} else if (angle === -90) {
return (
xyToTranslate(0, tick_label_distance) +
" " +
rotate +
" " +
xyToTranslate(0, tick_label_size * 0.33 - d.multiline_offset)
);
} else {
return (
xyToTranslate(0, tick_label_distance) +
" " +
rotate +
" " +
xyToTranslate(0, tick_label_size * 0.66)
);
}
else if (angle === -90) {
return xyToTranslate(0, tick_label_distance) + " " + rotate + " " + xyToTranslate(0, tick_label_size*0.33 - d.multiline_offset);
}
else {
return xyToTranslate(0, tick_label_distance) + " " + rotate + " " + xyToTranslate(0, tick_label_size*0.66);
}
};
var tick_g = tick_container.selectAll("g")
.data(sorted_ticks, function(d) { return d.type + "-" + d.value; });
var tick_g = tick_container
.selectAll("g")
.data(sorted_ticks, function (d) {
return d.type + "-" + d.value;
});
var tick_g_exit = tick_g.exit();
tick_g_exit.transition()
tick_g_exit
.transition()
.duration(animation_duration)
.attr("transform", function(d) { return xyToTranslate(exitingXScale(d.value), axis_y_position); })
.attr("transform", function (d) {
return xyToTranslate(exitingXScale(d.value), axis_y_position);
})
.style("opacity", 0)
.remove();
tick_g_exit.each(function() {
tick_g_exit.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -164,3 +216,4 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
sel
.select("text")
.style("fill", tick_label_color)

@@ -174,15 +227,16 @@ .style("font-size", tick_label_size + "px")

var tick_g_enter = tick_g.enter().append("g")
.style("opacity", 0);
var tick_g_enter = tick_g.enter().append("g").style("opacity", 0);
tick_g_enter
.attr("transform", function(d) { return xyToTranslate(enteringXScale(d.value), axis_y_position_old); });
tick_g_enter.attr("transform", function (d) {
return xyToTranslate(enteringXScale(d.value), axis_y_position_old);
});
tick_g_enter.each(function() {
tick_g_enter.each(function () {
var sel = select(this);
// Tick lines
sel.append("line")
.attr("y2", tick_length);
sel.append("line").attr("y2", tick_length);
// Tick labels
sel.append("text").attr("text-anchor", "middle")
sel
.append("text")
.attr("text-anchor", "middle")
.attr("transform", tickLabelTransform)

@@ -194,11 +248,14 @@ .call(userSelectNone);

tick_g_update.transition()
tick_g_update
.transition()
.duration(animation_duration)
.style("opacity", 1)
.attr("transform", function(d) { return xyToTranslate(xScale(d.value), axis_y_position); });
.attr("transform", function (d) {
return xyToTranslate(xScale(d.value), axis_y_position);
});
var setTickOpacity = (function() {
var setTickOpacity = (function () {
var placed_ticks = [];
var y_anchor = axis_y_position + tick_label_distance;
return function(d) {
return function (d) {
var x_anchor = xScale(d.value);

@@ -216,7 +273,10 @@ if (pos === "float-below") {

}
var p1q1 = [ x_anchor, y_anchor ];
var p2 = [ x_anchor + d.box_width_right, y_anchor + d.box_height_right];
var q2 = [ x_anchor - d.box_width_left, y_anchor + d.box_height_left];
var p = [ p1q1, p2 ];
var q = [ p1q1, q2 ];
var p1q1 = [x_anchor, y_anchor];
var p2 = [
x_anchor + d.box_width_right,
y_anchor + d.box_height_right,
];
var q2 = [x_anchor - d.box_width_left, y_anchor + d.box_height_left];
var p = [p1q1, p2];
var q = [p1q1, q2];
for (var i = 0; i < placed_ticks.length; i++) {

@@ -226,4 +286,3 @@ var placed_tick = placed_ticks[i];

if (linesIntersect(p, placed_tick.q)) return 0;
}
else {
} else {
if (linesIntersect(placed_tick.p, q)) return 0; // eslint-disable-line no-lonely-if

@@ -238,6 +297,7 @@ }

tick_g_update.each(function() {
tick_g_update.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -249,9 +309,19 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
.each(function() {
var tspans = select(this).selectAll("tspan").data(function(d) { return d.lines; });
tspans.merge(tspans.enter().append("tspan"))
sel
.select("text")
.each(function () {
var tspans = select(this)
.selectAll("tspan")
.data(function (d) {
return d.lines;
});
tspans
.merge(tspans.enter().append("tspan"))
.attr("x", 0)
.attr("dy", function(d, i) { return i ? x.tick_label_line_height + "em" : 0; })
.text(function(d) { return typeof d === "number" && isNaN(d) ? "" : d; });
.attr("dy", function (d, i) {
return i ? x.tick_label_line_height + "em" : 0;
})
.text(function (d) {
return typeof d === "number" && isNaN(d) ? "" : d;
});
tspans.exit().remove();

@@ -269,3 +339,4 @@ })

var title = title_container.selectAll("text")
var title = title_container
.selectAll("text")
.data(show_this_axis && title_text ? [title_text] : []);

@@ -275,3 +346,5 @@

title.enter().append("text")
title
.enter()
.append("text")
.attr("text-anchor", "middle")

@@ -285,3 +358,5 @@ .style("font-size", title_size + "px")

.delay(animation_duration)
.text(function(d) { return d; })
.text(function (d) {
return d;
})
.attr("x", x_mid)

@@ -291,3 +366,6 @@ .attr("y", title_distance)

title.text(function(d) { return d; })
title
.text(function (d) {
return d;
})
.style("fill", x.title_color)

@@ -308,3 +386,3 @@ .style("font-size", title_size + "px")

var updateTopAxis = (function() {
var updateTopAxis = (function () {
var top = instance.chart.select("g.fl-top-axis");

@@ -316,6 +394,7 @@ var line_container = top.select("g.fl-axis-line");

return function() {
return function () {
var pos = x.axis_position;
var measurements = { pos: pos };
var show_this_axis = (!instance.xHide() && ["top", "float-above"].indexOf(pos) !== -1);
var show_this_axis =
!instance.xHide() && ["top", "float-above"].indexOf(pos) !== -1;
var ticks = show_this_axis ? instance.xTicks() : [];

@@ -327,12 +406,19 @@ var y_top = instance.y_top;

title_distance -= tick_label_distance + ticks.max_box_height;
measurements.extended_gridline = y_top - (tick_label_distance + ticks.max_box_height);
measurements.extended_gridline =
y_top - (tick_label_distance + ticks.max_box_height);
}
var axis_y_position_old = pos === "float-above" ? (oldYScale || yScale)(x.y_axis_position) : y_top_old;
var axis_y_position = pos === "float-above" ? yScale(x.y_axis_position) : y_top;
var axis_y_position_old =
pos === "float-above"
? (oldYScale || yScale)(x.y_axis_position)
: y_top_old;
var axis_y_position =
pos === "float-above" ? yScale(x.y_axis_position) : y_top;
var line = line_container.selectAll("line")
var line = line_container
.selectAll("line")
.data(show_this_axis && x.line_visible ? [xScale.domain()] : []);
line.exit()
line
.exit()
.style("stroke", line_color)

@@ -349,3 +435,4 @@ .style("stroke-width", line_width)

var line_enter = line.enter()
var line_enter = line
.enter()
.append("line")

@@ -361,3 +448,4 @@ .style("shape-rendering", "crispEdges")

line.merge(line_enter)
line
.merge(line_enter)
.style("stroke", line_color)

@@ -375,38 +463,65 @@ .style("stroke-width", line_width)

if (show_this_axis) {
sorted_ticks = ticks.type === "numeric" ? ticks.slice().sort(tickSorter) : ticks;
sorted_ticks =
ticks.type === "numeric" ? ticks.slice().sort(tickSorter) : ticks;
}
var tickLabelTransform = function(d) {
var angle = x.tick_label_position == "default" ? -x.tick_label_angle : -90;
var tickLabelTransform = function (d) {
var angle =
x.tick_label_position == "default" ? -x.tick_label_angle : -90;
var rotate = angleToRotate(angle, 0, 0);
if (x.tick_label_position !== "default") {
var y_offset = x.tick_label_position === "left" ? -0.3 : 1;
return xyToTranslate(0, -tick_label_distance) + " " + rotate + " " + xyToTranslate(0, tick_label_size * y_offset);
return (
xyToTranslate(0, -tick_label_distance) +
" " +
rotate +
" " +
xyToTranslate(0, tick_label_size * y_offset)
);
}
if (angle === 0) {
return xyToTranslate(-d.text_width/2, -(tick_label_distance + tick_label_size*0.33));
return xyToTranslate(
-d.text_width / 2,
-(tick_label_distance + tick_label_size * 0.33),
);
} else if (angle === -90) {
return (
xyToTranslate(0, -tick_label_distance) +
" " +
rotate +
" " +
xyToTranslate(0, tick_label_size * 0.33 - d.multiline_offset)
);
} else {
return (
xyToTranslate(0, -tick_label_distance) +
" " +
rotate +
xyToTranslate(0, -d.multiline_offset)
); // + " " + xyToTranslate(0, tick_label_size*0.66);
}
else if (angle === -90) {
return xyToTranslate(0, -tick_label_distance) + " " + rotate + " " + xyToTranslate(0, tick_label_size*0.33 - d.multiline_offset);
}
else {
return xyToTranslate(0, -tick_label_distance) + " " + rotate + xyToTranslate(0, -d.multiline_offset); // + " " + xyToTranslate(0, tick_label_size*0.66);
}
};
var tick_g = tick_container.selectAll("g")
.data(sorted_ticks, function(d) { return d.type + "-" + d.value; });
var tick_g = tick_container
.selectAll("g")
.data(sorted_ticks, function (d) {
return d.type + "-" + d.value;
});
var tick_g_exit = tick_g.exit();
tick_g_exit.transition()
tick_g_exit
.transition()
.duration(animation_duration)
.attr("transform", function(d) { return xyToTranslate(exitingXScale(d.value), axis_y_position); })
.attr("transform", function (d) {
return xyToTranslate(exitingXScale(d.value), axis_y_position);
})
.style("opacity", 0)
.remove();
tick_g_exit.each(function() {
tick_g_exit.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -418,3 +533,4 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
sel
.select("text")
.style("fill", tick_label_color)

@@ -428,15 +544,16 @@ .style("font-size", tick_label_size + "px")

var tick_g_enter = tick_g.enter().append("g")
.style("opacity", 0);
var tick_g_enter = tick_g.enter().append("g").style("opacity", 0);
tick_g_enter
.attr("transform", function(d) { return xyToTranslate(enteringXScale(d.value), axis_y_position_old); });
tick_g_enter.attr("transform", function (d) {
return xyToTranslate(enteringXScale(d.value), axis_y_position_old);
});
tick_g_enter.each(function() {
tick_g_enter.each(function () {
var sel = select(this);
// Tick lines
sel.append("line")
.attr("y2", -tick_length);
sel.append("line").attr("y2", -tick_length);
// Tick labels
sel.append("text").attr("text-anchor", "middle")
sel
.append("text")
.attr("text-anchor", "middle")
.attr("transform", tickLabelTransform)

@@ -448,11 +565,14 @@ .call(userSelectNone);

tick_g_update.transition()
tick_g_update
.transition()
.duration(animation_duration)
.style("opacity", 1)
.attr("transform", function(d) { return xyToTranslate(xScale(d.value), axis_y_position); });
.attr("transform", function (d) {
return xyToTranslate(xScale(d.value), axis_y_position);
});
var setTickOpacity = (function() {
var setTickOpacity = (function () {
var placed_ticks = [];
var y_anchor = axis_y_position + tick_label_distance;
return function(d) {
return function (d) {
var x_anchor = xScale(d.value);

@@ -470,7 +590,10 @@ if (pos === "float-above") {

}
var p1q1 = [ x_anchor, y_anchor ];
var p2 = [ x_anchor - d.box_width_left, y_anchor - d.box_height_left];
var q2 = [ x_anchor + d.box_width_right, y_anchor - d.box_height_right];
var p = [ p1q1, p2 ];
var q = [ p1q1, q2 ];
var p1q1 = [x_anchor, y_anchor];
var p2 = [x_anchor - d.box_width_left, y_anchor - d.box_height_left];
var q2 = [
x_anchor + d.box_width_right,
y_anchor - d.box_height_right,
];
var p = [p1q1, p2];
var q = [p1q1, q2];
for (var i = 0; i < placed_ticks.length; i++) {

@@ -480,4 +603,3 @@ var placed_tick = placed_ticks[i];

if (linesIntersect(q, placed_tick.p)) return 0;
}
else {
} else {
if (linesIntersect(p, placed_tick.q)) return 0; // eslint-disable-line no-lonely-if

@@ -492,6 +614,7 @@ }

tick_g_update.each(function() {
tick_g_update.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -503,9 +626,19 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
.each(function() {
var tspans = select(this).selectAll("tspan").data(function(d) { return d.lines; });
tspans.merge(tspans.enter().append("tspan"))
sel
.select("text")
.each(function () {
var tspans = select(this)
.selectAll("tspan")
.data(function (d) {
return d.lines;
});
tspans
.merge(tspans.enter().append("tspan"))
.attr("x", 0)
.attr("dy", function(d, i) { return i ? x.tick_label_line_height + "em" : 0; })
.text(function(d) { return typeof d === "number" && isNaN(d) ? "" : d; });
.attr("dy", function (d, i) {
return i ? x.tick_label_line_height + "em" : 0;
})
.text(function (d) {
return typeof d === "number" && isNaN(d) ? "" : d;
});
tspans.exit().remove();

@@ -523,3 +656,4 @@ })

var title = title_container.selectAll("text")
var title = title_container
.selectAll("text")
.data(show_this_axis && title_text ? [title_text] : []);

@@ -529,3 +663,5 @@

title.enter().append("text")
title
.enter()
.append("text")
.attr("text-anchor", "middle")

@@ -539,3 +675,5 @@ .style("font-size", title_size + "px")

.delay(animation_duration)
.text(function(d) { return d; })
.text(function (d) {
return d;
})
.attr("x", x_mid)

@@ -545,3 +683,6 @@ .attr("y", title_distance)

title.text(function(d) { return d; })
title
.text(function (d) {
return d;
})
.style("fill", x.title_color)

@@ -562,3 +703,3 @@ .style("font-size", title_size + "px")

return function() {
return function () {
setValues();

@@ -565,0 +706,0 @@ var bottom = updateBottomAxis();

import { select } from "d3-selection";
import { remToPx, xyToTranslate, angleToRotate, linesIntersect, safeScale } from "../../common/index.js";
import {
remToPx,
xyToTranslate,
angleToRotate,
linesIntersect,
safeScale,
} from "../../common/index.js";
import { tickSorter, userSelectNone, getDirectionAttribute } from "./common.js";

@@ -16,3 +22,3 @@

return function() {
return function () {
var measurements = {};

@@ -26,4 +32,10 @@ var show_this_axis = y.axis_visible && !instance.yHide();

if (!oldYScale) oldYScale = yScale;
var enteringYScale = oldYScale.type === yScale.type && yScale.type !== "ordinal" ? oldYScale : yScale;
var exitingYScale = oldYScale.type === yScale.type && oldYScale.type !== "ordinal" ? yScale : oldYScale;
var enteringYScale =
oldYScale.type === yScale.type && yScale.type !== "ordinal"
? oldYScale
: yScale;
var exitingYScale =
oldYScale.type === yScale.type && oldYScale.type !== "ordinal"
? yScale
: oldYScale;
var y_bottom = instance.y_bottom;

@@ -45,17 +57,27 @@ var y_top = instance.y_top;

var axis_width = instance.yTicks().max_box_width + tick_padding;
var tick_length = ticks_labels_side ? (remToPx(y.tick_length) * (ticks_out ? 1 : -1)) : axis_width;
var tick_length = ticks_labels_side
? remToPx(y.tick_length) * (ticks_out ? 1 : -1)
: axis_width;
var tick_label_size = remToPx(y.tick_label_size);
var tick_label_distance = (ticks_out && ticks_labels_side ? tick_length : 0) + tick_padding;
var tick_label_distance =
(ticks_out && ticks_labels_side ? tick_length : 0) + tick_padding;
var title_text = instance.yTitle();
var title_size = remToPx(y.title_size);
var title_distance = tick_label_distance + ticks.max_box_width + remToPx(y.title_padding) + 0.33 * title_size;
measurements.extended_gridline = x_left - (tick_label_distance + ticks.max_box_width);
var title_distance =
tick_label_distance +
ticks.max_box_width +
remToPx(y.title_padding) +
0.33 * title_size;
measurements.extended_gridline =
x_left - (tick_label_distance + ticks.max_box_width);
var y_mid = (y_top + y_bottom) / 2;
var line = line_container.selectAll("line")
var line = line_container
.selectAll("line")
.data(show_this_axis && y.line_visible ? [yScale.domain()] : []);
line.exit()
line
.exit()
.style("stroke", line_color)

@@ -72,3 +94,4 @@ .style("stroke-width", line_width)

var line_enter = line.enter()
var line_enter = line
.enter()
.append("line")

@@ -84,3 +107,4 @@ .style("shape-rendering", "crispEdges")

line.merge(line_enter)
line
.merge(line_enter)
.style("stroke", line_color)

@@ -103,30 +127,40 @@ .style("stroke-width", line_width)

if (y.tick_label_position !== "default") {
var x_offset = -tick_label_distance - (ticks.max_box_width - d.box_width);
var x_offset =
-tick_label_distance - (ticks.max_box_width - d.box_width);
var y_offset = y.tick_label_position === "above" ? -0.3 : 1;
return xyToTranslate(x_offset, y_offset*tick_label_size);
return xyToTranslate(x_offset, y_offset * tick_label_size);
}
var angle = -y.tick_label_angle;
if (angle === 0) {
return xyToTranslate(-tick_label_distance, 0.33*tick_label_size - d.multiline_offset);
return xyToTranslate(
-tick_label_distance,
0.33 * tick_label_size - d.multiline_offset,
);
}
var transform = xyToTranslate(-tick_label_distance, 0) + " " + angleToRotate(angle);
if (angle === -90) transform += " " + xyToTranslate(d.text_width/2, 0);
var transform =
xyToTranslate(-tick_label_distance, 0) + " " + angleToRotate(angle);
if (angle === -90) transform += " " + xyToTranslate(d.text_width / 2, 0);
return transform;
}
var tick_g = tick_container.selectAll("g")
.data(sorted_ticks, function(d) { return d.type + "-" + d.value; });
var tick_g = tick_container.selectAll("g").data(sorted_ticks, function (d) {
return d.type + "-" + d.value;
});
var tick_g_exit = tick_g.exit();
tick_g_exit.transition()
tick_g_exit
.transition()
.duration(animation_duration)
.attr("transform", function(d) { return xyToTranslate(x_left, exitingYScale(d.value)); })
.attr("transform", function (d) {
return xyToTranslate(x_left, exitingYScale(d.value));
})
.style("opacity", 0)
.remove();
tick_g_exit.each(function() {
tick_g_exit.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -138,3 +172,4 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
sel
.select("text")
.style("fill", tick_label_color)

@@ -148,7 +183,7 @@ .style("font-size", tick_label_size + "px")

var tick_g_enter = tick_g.enter().append("g")
.style("opacity", 0);
var tick_g_enter = tick_g.enter().append("g").style("opacity", 0);
tick_g_enter
.attr("transform", function(d) { return xyToTranslate(x_left_old, enteringYScale(d.value)); });
tick_g_enter.attr("transform", function (d) {
return xyToTranslate(x_left_old, enteringYScale(d.value));
});

@@ -158,9 +193,9 @@ const read_direction = getDirectionAttribute();

tick_g_enter.each(function() {
tick_g_enter.each(function () {
var sel = select(this);
// Tick lines
sel.append("line")
.attr("x2", -tick_length);
sel.append("line").attr("x2", -tick_length);
// Tick labels
sel.append("text")
sel
.append("text")
.attr("text-anchor", text_anchor)

@@ -173,17 +208,20 @@ .attr("transform", tickLabelTransform)

tick_g_update.transition()
tick_g_update
.transition()
.duration(animation_duration)
.style("opacity", 1)
.attr("transform", function(d) { return xyToTranslate(x_left, yScale(d.value)); });
.attr("transform", function (d) {
return xyToTranslate(x_left, yScale(d.value));
});
var setTickOpacity = (function() {
var setTickOpacity = (function () {
var placed_ticks = [];
var x_anchor = x_left - tick_label_distance;
return function(d) {
return function (d) {
var y_anchor = yScale(d.value);
var p1q1 = [ x_anchor, y_anchor ];
var p2 = [ x_anchor - d.box_width_above, y_anchor - d.box_height_above];
var q2 = [ x_anchor - d.box_width_below, y_anchor + d.box_height_below];
var p = [ p1q1, p2 ];
var q = [ p1q1, q2 ];
var p1q1 = [x_anchor, y_anchor];
var p2 = [x_anchor - d.box_width_above, y_anchor - d.box_height_above];
var q2 = [x_anchor - d.box_width_below, y_anchor + d.box_height_below];
var p = [p1q1, p2];
var q = [p1q1, q2];
for (var i = 0; i < placed_ticks.length; i++) {

@@ -193,4 +231,3 @@ var placed_tick = placed_ticks[i];

if (linesIntersect(p, placed_tick.q)) return 0;
}
else {
} else {
if (linesIntersect(placed_tick.p, q)) return 0; // eslint-disable-line no-lonely-if

@@ -204,6 +241,7 @@ }

tick_g_update.each(function() {
tick_g_update.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -215,9 +253,19 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
.each(function() {
var tspans = select(this).selectAll("tspan").data(function(d) { return d.lines; });
tspans.merge(tspans.enter().append("tspan"))
sel
.select("text")
.each(function () {
var tspans = select(this)
.selectAll("tspan")
.data(function (d) {
return d.lines;
});
tspans
.merge(tspans.enter().append("tspan"))
.attr("x", 0)
.attr("dy", function(d, i) { return i ? y.tick_label_line_height + "em" : 0; })
.text(function(d) { return typeof d === "number" && isNaN(d) ? "" : d; });
.attr("dy", function (d, i) {
return i ? y.tick_label_line_height + "em" : 0;
})
.text(function (d) {
return typeof d === "number" && isNaN(d) ? "" : d;
});
tspans.exit().remove();

@@ -235,3 +283,4 @@ })

var title = title_container.selectAll("text")
var title = title_container
.selectAll("text")
.data(show_this_axis && title_text ? [title_text] : []);

@@ -241,9 +290,17 @@

var getTitleTransform = function() {
var getTitleTransform = function () {
if (y.title_position === "side") {
return xyToTranslate(x_left, y_mid) + " " + angleToRotate(-90) + " " + xyToTranslate(0, -title_distance);
return (
xyToTranslate(x_left, y_mid) +
" " +
angleToRotate(-90) +
" " +
xyToTranslate(0, -title_distance)
);
}
const x_pos = x_left - instance.margins._calculated().left;
const x_axis_above = ["top", "float-above"].includes(state.x.axis_position);
const x_axis_above = ["top", "float-above"].includes(
state.x.axis_position,
);
const title_below = x_axis_above;

@@ -255,8 +312,7 @@ const title_padding = remToPx(y.title_padding);

const space_for_end_label = ticks[0].box_height_below;
const baseline_offset = remToPx(0.66*y.title_size);
const baseline_offset = remToPx(0.66 * y.title_size);
const y_offset = space_for_end_label + title_padding + baseline_offset;
y_pos = y_bottom + y_offset;
}
else {
const space_for_end_label = ticks[ticks.length-1].box_height_above;
} else {
const space_for_end_label = ticks[ticks.length - 1].box_height_above;
const y_offset = space_for_end_label + title_padding;

@@ -269,3 +325,5 @@ y_pos = y_top - y_offset;

title.enter().append("text")
title
.enter()
.append("text")
.attr("text-anchor", y.title_position === "side" ? "middle" : "start")

@@ -279,6 +337,11 @@ .style("font-size", title_size + "px")

.delay(animation_duration)
.text(function(d) { return d; })
.text(function (d) {
return d;
})
.attr("transform", getTitleTransform);
title.text(function(d) { return d; })
title
.text(function (d) {
return d;
})
.attr("text-anchor", y.title_position === "side" ? "middle" : "start")

@@ -285,0 +348,0 @@ .style("fill", y.title_color)

import { select } from "d3-selection";
import { remToPx, xyToTranslate, angleToRotate, linesIntersect, safeScale } from "../../common/index.js";
import {
remToPx,
xyToTranslate,
angleToRotate,
linesIntersect,
safeScale,
} from "../../common/index.js";
import { tickSorter, userSelectNone, getDirectionAttribute } from "./common.js";

@@ -16,3 +22,3 @@

return function() {
return function () {
var measurements = {};

@@ -26,4 +32,10 @@ var show_this_axis = y.axis_visible && !instance.y2Hide();

if (!oldYScale) oldYScale = yScale;
var enteringYScale = oldYScale.type === yScale.type && yScale.type !== "ordinal" ? oldYScale : yScale;
var exitingYScale = oldYScale.type === yScale.type && oldYScale.type !== "ordinal" ? yScale : oldYScale;
var enteringYScale =
oldYScale.type === yScale.type && yScale.type !== "ordinal"
? oldYScale
: yScale;
var exitingYScale =
oldYScale.type === yScale.type && oldYScale.type !== "ordinal"
? yScale
: oldYScale;
var y_bottom = instance.y_bottom;

@@ -45,18 +57,28 @@ var y_top = instance.y_top;

var axis_width = instance.y2Ticks().max_box_width + tick_padding;
var tick_length = ticks_labels_side ? (remToPx(y.tick_length) * (ticks_out ? 1 : -1)) : axis_width;
var tick_length = ticks_labels_side
? remToPx(y.tick_length) * (ticks_out ? 1 : -1)
: axis_width;
var tick_label_size = remToPx(y.tick_label_size);
var tick_label_distance = (ticks_out && ticks_labels_side ? tick_length : 0) + tick_padding;
var tick_label_distance =
(ticks_out && ticks_labels_side ? tick_length : 0) + tick_padding;
var title_text = instance.y2Title();
var title_size = remToPx(y.title_size);
var title_distance = tick_label_distance + ticks.max_box_width + remToPx(y.title_padding) + 0.85 * title_size;
var title_distance =
tick_label_distance +
ticks.max_box_width +
remToPx(y.title_padding) +
0.85 * title_size;
// 0.85 was arrived at by trial and error; we do not fully understand why it is correct
measurements.extended_gridline = x_right + tick_label_distance + ticks.max_box_width;
measurements.extended_gridline =
x_right + tick_label_distance + ticks.max_box_width;
var y_mid = (y_bottom + y_top) / 2;
var line = line_container.selectAll("line")
var line = line_container
.selectAll("line")
.data(show_this_axis && y.line_visible ? [yScale.domain()] : []);
line.exit()
line
.exit()
.style("stroke", line_color)

@@ -73,3 +95,4 @@ .style("stroke-width", line_width)

var line_enter = line.enter()
var line_enter = line
.enter()
.append("line")

@@ -85,3 +108,4 @@ .style("shape-rendering", "crispEdges")

line.merge(line_enter)
line
.merge(line_enter)
.style("stroke", line_color)

@@ -97,34 +121,45 @@ .style("stroke-width", line_width)

var sorted_ticks = ticks.type === "numeric" ? ticks.slice().sort(tickSorter) : ticks;
var sorted_ticks =
ticks.type === "numeric" ? ticks.slice().sort(tickSorter) : ticks;
function tickLabelTransform(d) {
if (y.tick_label_position !== "default") {
var x_offset = tick_label_distance + (ticks.max_box_width - d.box_width);
var x_offset =
tick_label_distance + (ticks.max_box_width - d.box_width);
var y_offset = y.tick_label_position === "above" ? -0.3 : 1;
return xyToTranslate(x_offset, y_offset*tick_label_size);
return xyToTranslate(x_offset, y_offset * tick_label_size);
}
var angle = -y.tick_label_angle;
if (angle === 0) {
return xyToTranslate(tick_label_distance, 0.33*tick_label_size - d.multiline_offset);
return xyToTranslate(
tick_label_distance,
0.33 * tick_label_size - d.multiline_offset,
);
}
var transform = xyToTranslate(tick_label_distance, 0) + " " + angleToRotate(angle);
if (angle === -90) transform += " " + xyToTranslate(d.text_width/2, 0);
var transform =
xyToTranslate(tick_label_distance, 0) + " " + angleToRotate(angle);
if (angle === -90) transform += " " + xyToTranslate(d.text_width / 2, 0);
return transform;
}
var tick_g = tick_container.selectAll("g")
.data(sorted_ticks, function(d) { return d.type + "-" + d.value; });
var tick_g = tick_container.selectAll("g").data(sorted_ticks, function (d) {
return d.type + "-" + d.value;
});
var tick_g_exit = tick_g.exit();
tick_g_exit.transition()
tick_g_exit
.transition()
.duration(animation_duration)
.attr("transform", function(d) { return xyToTranslate(x_right, exitingYScale(d.value)); })
.attr("transform", function (d) {
return xyToTranslate(x_right, exitingYScale(d.value));
})
.style("opacity", 0)
.remove();
tick_g_exit.each(function() {
tick_g_exit.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -136,3 +171,4 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
sel
.select("text")
.style("fill", tick_label_color)

@@ -146,17 +182,17 @@ .style("font-size", tick_label_size + "px")

var tick_g_enter = tick_g.enter().append("g")
.style("opacity", 0);
var tick_g_enter = tick_g.enter().append("g").style("opacity", 0);
tick_g_enter
.attr("transform", function(d) { return xyToTranslate(x_right_old, enteringYScale(d.value)); });
tick_g_enter.attr("transform", function (d) {
return xyToTranslate(x_right_old, enteringYScale(d.value));
});
const read_direction = getDirectionAttribute();
tick_g_enter.each(function() {
tick_g_enter.each(function () {
var sel = select(this);
// Tick lines
sel.append("line")
.attr("x2", tick_length);
sel.append("line").attr("x2", tick_length);
// Tick labels
sel.append("text")
sel
.append("text")
.attr("transform", tickLabelTransform)

@@ -168,18 +204,21 @@ .call(userSelectNone);

tick_g_update.transition()
tick_g_update
.transition()
.duration(animation_duration)
.style("opacity", 1)
.attr("transform", function(d) { return xyToTranslate(x_right, yScale(d.value)); })
.attr("transform", function (d) {
return xyToTranslate(x_right, yScale(d.value));
})
.attr("text-anchor", read_direction === "rtl" ? "end" : "start");
var setTickOpacity = (function() {
var setTickOpacity = (function () {
var placed_ticks = [];
var x_anchor = x_right + tick_label_distance;
return function(d) {
return function (d) {
var y_anchor = yScale(d.value);
var p1q1 = [ x_anchor, y_anchor ];
var p2 = [ x_anchor - d.box_width_above, y_anchor - d.box_height_above];
var q2 = [ x_anchor - d.box_width_below, y_anchor + d.box_height_below];
var p = [ p1q1, p2 ];
var q = [ p1q1, q2 ];
var p1q1 = [x_anchor, y_anchor];
var p2 = [x_anchor - d.box_width_above, y_anchor - d.box_height_above];
var q2 = [x_anchor - d.box_width_below, y_anchor + d.box_height_below];
var p = [p1q1, p2];
var q = [p1q1, q2];
for (var i = 0; i < placed_ticks.length; i++) {

@@ -189,4 +228,3 @@ var placed_tick = placed_ticks[i];

if (linesIntersect(p, placed_tick.q)) return 0;
}
else {
} else {
if (linesIntersect(placed_tick.p, q)) return 0; // eslint-disable-line no-lonely-if

@@ -200,6 +238,7 @@ }

tick_g_update.each(function() {
tick_g_update.each(function () {
var sel = select(this);
// Tick lines
sel.select("line")
sel
.select("line")
.style("stroke", line_color)

@@ -211,9 +250,19 @@ .style("stroke-width", line_width)

// Tick labels
sel.select("text")
.each(function() {
var tspans = select(this).selectAll("tspan").data(function(d) { return d.lines; });
tspans.merge(tspans.enter().append("tspan"))
sel
.select("text")
.each(function () {
var tspans = select(this)
.selectAll("tspan")
.data(function (d) {
return d.lines;
});
tspans
.merge(tspans.enter().append("tspan"))
.attr("x", 0)
.attr("dy", function(d, i) { return i ? y.tick_label_line_height + "em" : 0; })
.text(function(d) { return typeof d === "number" && isNaN(d) ? "" : d; });
.attr("dy", function (d, i) {
return i ? y.tick_label_line_height + "em" : 0;
})
.text(function (d) {
return typeof d === "number" && isNaN(d) ? "" : d;
});
tspans.exit().remove();

@@ -230,3 +279,4 @@ })

var title = title_container.selectAll("text")
var title = title_container
.selectAll("text")
.data(show_this_axis && title_text ? [title_text] : []);

@@ -236,9 +286,17 @@

var getTitleTransform = function() {
var getTitleTransform = function () {
if (y.title_position === "side") {
return xyToTranslate(x_right, y_mid) + " " + angleToRotate(-90) + " " + xyToTranslate(0, title_distance);
return (
xyToTranslate(x_right, y_mid) +
" " +
angleToRotate(-90) +
" " +
xyToTranslate(0, title_distance)
);
}
const x_pos = x_right + instance.margins._calculated().right;
const x_axis_above = ["top", "float-above"].includes(state.x.axis_position);
const x_axis_above = ["top", "float-above"].includes(
state.x.axis_position,
);
const title_below = x_axis_above;

@@ -250,8 +308,7 @@ const title_padding = remToPx(y.title_padding);

const space_for_end_label = ticks[0].box_height_below;
const baseline_offset = remToPx(0.66*y.title_size);
const baseline_offset = remToPx(0.66 * y.title_size);
const y_offset = space_for_end_label + title_padding + baseline_offset;
y_pos = y_bottom + y_offset;
}
else {
const space_for_end_label = ticks[ticks.length-1].box_height_above;
} else {
const space_for_end_label = ticks[ticks.length - 1].box_height_above;
const y_offset = space_for_end_label + title_padding;

@@ -264,3 +321,5 @@ y_pos = y_top - y_offset;

title.enter().append("text")
title
.enter()
.append("text")
.attr("text-anchor", y.title_position === "side" ? "middle" : "end")

@@ -274,6 +333,11 @@ .style("font-size", title_size + "px")

.delay(animation_duration)
.text(function(d) { return d; })
.text(function (d) {
return d;
})
.attr("transform", getTitleTransform);
title.text(function(d) { return d; })
title
.text(function (d) {
return d;
})
.attr("text-anchor", y.title_position === "side" ? "middle" : "end")

@@ -280,0 +344,0 @@ .style("fill", y.title_color)

@@ -7,3 +7,3 @@ function initBackgroundUpdating(instance, state) {

return function() {
return function () {
var x = instance.x_left;

@@ -25,12 +25,11 @@ var y = instance.y_top;

.attr("height", height)
.attr("xlink:href", bg.background_image_enabled ? bg.background_image_src : null)
.attr("preserveAspectRatio", function() {
.attr(
"xlink:href",
bg.background_image_enabled ? bg.background_image_src : null,
)
.attr("preserveAspectRatio", function () {
if (bg.background_image_size == "stretch") return "none";
return bg.background_image_position + " " + bg.background_image_size;
});
rect
.attr("x", x)
.attr("y", y)
.attr("width", width)
.attr("height", height);
rect.attr("x", x).attr("y", y).attr("width", width).attr("height", height);
};

@@ -37,0 +36,0 @@ }

@@ -12,3 +12,3 @@ import { remToPx } from "../../common/index.js";

return function() {
return function () {
var id = instance.identifier() + "-clip-path";

@@ -50,4 +50,4 @@ var clip_attr = "url(#" + id + ")";

.attr("y", y_top - tb_padding)
.attr("width", (x_right - x_left) + (2 * lr_padding))
.attr("height", (y_bottom - y_top) + (2 * tb_padding));
.attr("width", x_right - x_left + 2 * lr_padding)
.attr("height", y_bottom - y_top + 2 * tb_padding);
};

@@ -54,0 +54,0 @@ }

function initDebugUpdating(instance) {
let debug_rect = instance.chart.select("rect.fl-chart-debug-rectangle");
return function() {
debug_rect.attr("width", instance.width())
return function () {
debug_rect
.attr("width", instance.width())
.attr("height", instance.height())

@@ -7,0 +8,0 @@ .style("stroke", instance.debugColor())

@@ -5,5 +5,5 @@ import { remToPx, safeScale } from "../../common/index.js";

solid: null,
dash: [ 4, 1 ],
dot: [ 1, 1 ],
dot_dash: [4, 1, 1, 1]
dash: [4, 1],
dot: [1, 1],
dot_dash: [4, 1, 1, 1],
};

@@ -14,3 +14,7 @@

var multiplier = remToPx(1) / 4;
return DASH_ARRAYS[style].map(function(d) { return d * multiplier; }).join(" ");
return DASH_ARRAYS[style]
.map(function (d) {
return d * multiplier;
})
.join(" ");
}

@@ -27,3 +31,3 @@

return function(measurements) {
return function (measurements) {
var xScale = safeScale(instance.xScale());

@@ -43,12 +47,30 @@ var yScale = safeScale(instance.yScale());

oldY2Scale = oldY2Scale || y2Scale;
var enteringXScale = oldXScale.type === xScale.type && xScale.type !== "ordinal" ? oldXScale : xScale;
var exitingXScale = oldXScale.type === xScale.type && oldXScale.type !== "ordinal" ? xScale : oldXScale;
var enteringYScale = oldYScale.type === yScale.type && yScale.type !== "ordinal" ? oldYScale : yScale;
var exitingYScale = oldYScale.type === yScale.type && oldYScale.type !== "ordinal" ? yScale : oldYScale;
var enteringY2Scale = oldY2Scale.type === y2Scale.type && oldY2Scale.type !== "ordinal" ? oldY2Scale : y2Scale;
var exitingY2Scale = oldY2Scale.type === y2Scale.type && oldY2Scale.type !== "ordinal" ? y2Scale : oldY2Scale;
var enteringXScale =
oldXScale.type === xScale.type && xScale.type !== "ordinal"
? oldXScale
: xScale;
var exitingXScale =
oldXScale.type === xScale.type && oldXScale.type !== "ordinal"
? xScale
: oldXScale;
var enteringYScale =
oldYScale.type === yScale.type && yScale.type !== "ordinal"
? oldYScale
: yScale;
var exitingYScale =
oldYScale.type === yScale.type && oldYScale.type !== "ordinal"
? yScale
: oldYScale;
var enteringY2Scale =
oldY2Scale.type === y2Scale.type && oldY2Scale.type !== "ordinal"
? oldY2Scale
: y2Scale;
var exitingY2Scale =
oldY2Scale.type === y2Scale.type && oldY2Scale.type !== "ordinal"
? y2Scale
: oldY2Scale;
var animation_duration = oldXScale ? instance.animationDuration() : 0;
var getTicksForGridlines = function(axis) {
var getTicksForGridlines = function (axis) {
// If the user has switched the whole axis off don't return any ticks

@@ -70,3 +92,3 @@ if (axis === "x" && state.x.axis_position === "off") return [];

var v_data = x_ticks.map(function(d) {
var v_data = x_ticks.map(function (d) {
return {

@@ -86,10 +108,11 @@ type: d.type,

v_data.pop();
v_data.forEach(function(gridline) {
gridline.x_enter += x_step/2;
gridline.x += x_step/2;
v_data.forEach(function (gridline) {
gridline.x_enter += x_step / 2;
gridline.x += x_step / 2;
if (x.gridline_category_dividers_extend) {
var extend_top = measurements.x && measurements.x.pos == "top",
extend_bottom = measurements.x && measurements.x.pos == "bottom";
extend_bottom = measurements.x && measurements.x.pos == "bottom";
if (extend_top) gridline.y2 = measurements.x.extended_gridline;
else if (extend_bottom) gridline.y1 = measurements.x.extended_gridline;
else if (extend_bottom)
gridline.y1 = measurements.x.extended_gridline;
}

@@ -99,3 +122,3 @@ });

var y_data = y_ticks.map(function(d) {
var y_data = y_ticks.map(function (d) {
return {

@@ -116,5 +139,5 @@ axis: "y",

y_data.pop();
y_data.forEach(function(gridline) {
gridline.y_enter -= y_step/2;
gridline.y -= y_step/2;
y_data.forEach(function (gridline) {
gridline.y_enter -= y_step / 2;
gridline.y -= y_step / 2;
if (y.gridline_category_dividers_extend) {

@@ -126,3 +149,3 @@ gridline.x1 = measurements.y.extended_gridline;

var y2_data = y2_ticks.map(function(d) {
var y2_data = y2_ticks.map(function (d) {
return {

@@ -143,5 +166,5 @@ axis: "y2",

y2_data.pop();
y2_data.forEach(function(gridline) {
gridline.y_enter -= y2_step/2;
gridline.y -= y2_step/2;
y2_data.forEach(function (gridline) {
gridline.y_enter -= y2_step / 2;
gridline.y -= y2_step / 2;
if (y2.gridline_category_dividers_extend) {

@@ -155,13 +178,25 @@ gridline.x2 = measurements.y2.extended_gridline;

var vertical_lines = vertical.selectAll("line")
.data(v_data, function(d) { return d.type + "-" + d.value; });
var vertical_lines = vertical.selectAll("line").data(v_data, function (d) {
return d.type + "-" + d.value;
});
vertical_lines.exit()
.attr("stroke-dasharray", function(d) { return d.dasharray; })
.style("stroke", function(d) { return d.stroke; })
.style("stroke-width", function(d) { return d.width; })
vertical_lines
.exit()
.attr("stroke-dasharray", function (d) {
return d.dasharray;
})
.style("stroke", function (d) {
return d.stroke;
})
.style("stroke-width", function (d) {
return d.width;
})
.transition()
.duration(animation_duration)
.attr("x1", function(d) { return exitingXScale(d.value); })
.attr("x2", function(d) { return exitingXScale(d.value); })
.attr("x1", function (d) {
return exitingXScale(d.value);
})
.attr("x2", function (d) {
return exitingXScale(d.value);
})
.attr("y1", y_bottom)

@@ -172,6 +207,12 @@ .attr("y2", y_top)

var vertical_lines_enter = vertical_lines.enter().append("line")
var vertical_lines_enter = vertical_lines
.enter()
.append("line")
.style("shape-rendering", "crispEdges")
.attr("x1", function(d) { return d.x_enter; })
.attr("x2", function(d) { return d.x_enter; })
.attr("x1", function (d) {
return d.x_enter;
})
.attr("x2", function (d) {
return d.x_enter;
})
.attr("y1", y_bottom_old)

@@ -181,10 +222,21 @@ .attr("y2", y_top_old)

vertical_lines.merge(vertical_lines_enter)
.attr("stroke-dasharray", function(d) { return d.dasharray; })
.style("stroke", function(d) { return d.stroke; })
.style("stroke-width", function(d) { return d.width; })
vertical_lines
.merge(vertical_lines_enter)
.attr("stroke-dasharray", function (d) {
return d.dasharray;
})
.style("stroke", function (d) {
return d.stroke;
})
.style("stroke-width", function (d) {
return d.width;
})
.transition()
.duration(animation_duration)
.attr("x1", function(d) { return d.x; })
.attr("x2", function(d) { return d.x; })
.attr("x1", function (d) {
return d.x;
})
.attr("x2", function (d) {
return d.x;
})
.attr("y1", y_bottom)

@@ -194,9 +246,19 @@ .attr("y2", y_top)

var horizontal_lines = horizontal.selectAll("line")
.data(h_data, function(d) { return d.axis + "-" + d.type + "-" + d.value; });
var horizontal_lines = horizontal
.selectAll("line")
.data(h_data, function (d) {
return d.axis + "-" + d.type + "-" + d.value;
});
horizontal_lines.exit()
.attr("stroke-dasharray", function(d) { return d.dasharray; })
.style("stroke", function(d) { return d.stroke; })
.style("stroke-width", function(d) { return d.width; })
horizontal_lines
.exit()
.attr("stroke-dasharray", function (d) {
return d.dasharray;
})
.style("stroke", function (d) {
return d.stroke;
})
.style("stroke-width", function (d) {
return d.width;
})
.transition()

@@ -206,19 +268,40 @@ .duration(animation_duration)

.attr("x2", x_right)
.attr("y1", function(d) { return d.axis === "y" ? exitingYScale(d.value) : exitingY2Scale(d.value); })
.attr("y2", function(d) { return d.axis === "y" ? exitingYScale(d.value) : exitingY2Scale(d.value); })
.attr("y1", function (d) {
return d.axis === "y"
? exitingYScale(d.value)
: exitingY2Scale(d.value);
})
.attr("y2", function (d) {
return d.axis === "y"
? exitingYScale(d.value)
: exitingY2Scale(d.value);
})
.style("opacity", 0)
.remove();
var horizontal_lines_enter = horizontal_lines.enter().append("line")
var horizontal_lines_enter = horizontal_lines
.enter()
.append("line")
.style("shape-rendering", "crispEdges")
.attr("x1", x_left_old)
.attr("x2", x_right_old)
.attr("y1", function(d) { return d.y_enter; })
.attr("y2", function(d) { return d.y_enter; })
.attr("y1", function (d) {
return d.y_enter;
})
.attr("y2", function (d) {
return d.y_enter;
})
.style("opacity", 0);
horizontal_lines.merge(horizontal_lines_enter)
.attr("stroke-dasharray", function(d) { return d.dasharray; })
.style("stroke", function(d) { return d.stroke; })
.style("stroke-width", function(d) { return d.width; })
horizontal_lines
.merge(horizontal_lines_enter)
.attr("stroke-dasharray", function (d) {
return d.dasharray;
})
.style("stroke", function (d) {
return d.stroke;
})
.style("stroke-width", function (d) {
return d.width;
})
.transition()

@@ -228,4 +311,8 @@ .duration(animation_duration)

.attr("x2", x_right)
.attr("y1", function(d) { return d.y; })
.attr("y2", function(d) { return d.y; })
.attr("y1", function (d) {
return d.y;
})
.attr("y2", function (d) {
return d.y;
})
.style("opacity", 1);

@@ -232,0 +319,0 @@

@@ -12,6 +12,7 @@ import { updateRemToPx } from "../common/index.js";

// Transform is based on parameters specified by offset* methods.
var updateTransform = function() {
var updateTransform = function () {
var transform = null;
if (instance.offsetLeft() || instance.offsetTop()) {
transform = "translate(" + instance.offsetLeft() + "," + instance.offsetTop() + ")";
transform =
"translate(" + instance.offsetLeft() + "," + instance.offsetTop() + ")";
}

@@ -23,4 +24,8 @@ instance.chart.attr("transform", transform);

var updateTicks = initTickUpdating(instance, state);
var updateMargins = function(margins) { instance.margins._update(margins); };
var updateInnerMargins = function(margins) { instance.inner_margins._update(margins); };
var updateMargins = function (margins) {
instance.margins._update(margins);
};
var updateInnerMargins = function (margins) {
instance.inner_margins._update(margins);
};
var updateClip = initClipUpdating(instance, state);

@@ -31,3 +36,3 @@ var updateBackground = initBackgroundUpdating(instance, state);

return function(opts) {
return function (opts) {
// "opts" object is often omitted but can be used to specify margin overrides (eg when) positioning

@@ -34,0 +39,0 @@ // charts close together and whether to skip rendering at all and just do calculations.

@@ -9,3 +9,5 @@ import { isDate, isValidDate, textareaToArray } from "../../common/index.js";

if (isDate(arr[0])) {
return Array.from(new Set(arr.map(d => d.getTime()))).map(d => new Date(d));
return Array.from(new Set(arr.map((d) => d.getTime()))).map(
(d) => new Date(d),
);
}

@@ -18,6 +20,9 @@

const axis_state = state[axis];
const scale = instance[axis + "Scale"]({ "domain_only": true });
const scale = instance[axis + "Scale"]({ domain_only: true });
const data = instance[axis + "Data"]();
let ticks;
const ticks_hidden = axis === "x" ? axis_state.axis_position === "off" : !axis_state.axis_visible;
const ticks_hidden =
axis === "x"
? axis_state.axis_position === "off"
: !axis_state.axis_visible;
if (ticks_hidden) ticks = [];

@@ -28,7 +33,11 @@ else if (data.string_array) {

else {
const custom_ticks = axis_state.tick_custom.replace("{{FIRST}}", domain[0]).replace("{{LAST}}", domain[domain.length - 1]);
ticks = textareaToArray(custom_ticks).filter(d => scale.domain().indexOf(d) > -1);
const custom_ticks = axis_state.tick_custom
.replace("{{FIRST}}", domain[0])
.replace("{{LAST}}", domain[domain.length - 1]);
ticks = textareaToArray(custom_ticks).filter(
(d) => scale.domain().indexOf(d) > -1,
);
}
}
else if (axis_state.tick_mode === "number") ticks = scale.ticks(axis_state.tick_number);
} else if (axis_state.tick_mode === "number")
ticks = scale.ticks(axis_state.tick_number);
else {

@@ -41,7 +50,8 @@ const is_datetime = data.datetime_array;

if (axis_state.tick_mode === "custom") {
const parser_name = axis + (is_datetime ? "Datetime" : "Number") + "Parse";
const parser_name =
axis + (is_datetime ? "Datetime" : "Number") + "Parse";
const parser = instance[parser_name]();
let custom_ticks = textareaToArray(axis_state.tick_custom);
ticks = custom_ticks.map(d => {
ticks = custom_ticks.map((d) => {
if (d === "{{FIRST}}") return domain[0];

@@ -51,4 +61,3 @@ if (d === "{{LAST}}") return domain[domain.length - 1];

});
}
else {
} else {
const auto = instance[axis + "AutoTicks"]();

@@ -58,4 +67,10 @@ ticks = Array.isArray(auto) ? auto : auto();

if (is_datetime) ticks = ticks.filter(d => isValidDate(d) && d >= domain_min && d <= domain_max);
else ticks = ticks.filter(d => !isNaN(d) && d >= domain_min && d <= domain_max);
if (is_datetime)
ticks = ticks.filter(
(d) => isValidDate(d) && d >= domain_min && d <= domain_max,
);
else
ticks = ticks.filter(
(d) => !isNaN(d) && d >= domain_min && d <= domain_max,
);

@@ -69,15 +84,15 @@ ticks = removeDuplicates(ticks);

function initTickUpdating(instance, state) {
var updateXTicks = function() {
var updateXTicks = function () {
instance.xTicks._update(getTickValues(instance, state, "x"));
};
var updateYTicks = function() {
var updateYTicks = function () {
instance.yTicks._update(getTickValues(instance, state, "y"));
};
var updateY2Ticks = function() {
var updateY2Ticks = function () {
instance.y2Ticks._update(getTickValues(instance, state, "y2"));
};
return function() {
return function () {
updateXTicks();

@@ -84,0 +99,0 @@ updateYTicks();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc