From 72839b1c3ceac884230ff21806b5892283109c29 Mon Sep 17 00:00:00 2001 From: Trdat Mkrtchyan Date: Tue, 5 Sep 2023 14:52:10 +0400 Subject: [PATCH 1/2] fix: forced plot bands to draw only inside plotting area (#140) --- demo/examples/plotlines.html | 37 +++++++++++++++++++++ src/YagrCore/plugins/plotLines/plotLines.ts | 20 +++++++++++ 2 files changed, 57 insertions(+) diff --git a/demo/examples/plotlines.html b/demo/examples/plotlines.html index 710a4944..224bb0f3 100644 --- a/demo/examples/plotlines.html +++ b/demo/examples/plotlines.html @@ -30,6 +30,10 @@

Plot lines

+
+
+
+ diff --git a/src/YagrCore/plugins/plotLines/plotLines.ts b/src/YagrCore/plugins/plotLines/plotLines.ts index 367fe139..7fe80a9a 100644 --- a/src/YagrCore/plugins/plotLines/plotLines.ts +++ b/src/YagrCore/plugins/plotLines/plotLines.ts @@ -54,6 +54,7 @@ export default function plotLinesPlugin(yagr: Yagr, plotLinesCfg: PlotLineConfig function renderPlotLines(u: UPlot) { const {ctx} = u; const {height, top, width, left} = u.bbox; + const timeline = u.data[0]; for (const plotLineConfig of plotLines) { if (!plotLineConfig.scale) { @@ -69,6 +70,25 @@ export default function plotLinesPlugin(yagr: Yagr, plotLinesCfg: PlotLineConfig /** This weird code should handles unexpected Inifinities in values */ const [fromValue, toValue] = value.map((val) => { if (Math.abs(val) !== Infinity) { + if (scale === DEFAULT_X_SCALE) { + if (val < timeline[0]) { + return timeline[0]; + } + + if (val > timeline[timeline.length - 1]) { + return timeline[timeline.length - 1]; + } + } else { + const scaleCfg = u.scales[scale]; + if (scaleCfg.min !== undefined && val < scaleCfg.min) { + return scaleCfg.min; + } + + if (scaleCfg.max !== undefined && val > scaleCfg.max) { + return scaleCfg.max; + } + } + return val; } From 2f01d754354a64ff069fedcc37c61a180761f8ae Mon Sep 17 00:00:00 2001 From: Gravity UI Bot <111915794+gravity-ui-bot@users.noreply.github.com> Date: Tue, 5 Sep 2023 14:17:57 +0300 Subject: [PATCH 2/2] chore(main): release 3.7.13 (#141) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab567ef6..4d285f45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ### master +## [3.7.13](https://github.com/gravity-ui/yagr/compare/v3.7.12...v3.7.13) (2023-09-05) + + +### Bug Fixes + +* forced plot bands to draw only inside plotting area ([#140](https://github.com/gravity-ui/yagr/issues/140)) ([72839b1](https://github.com/gravity-ui/yagr/commit/72839b1c3ceac884230ff21806b5892283109c29)) + ## [3.7.12](https://github.com/gravity-ui/yagr/compare/v3.7.11...v3.7.12) (2023-08-31) diff --git a/package-lock.json b/package-lock.json index da2b2629..8c244302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gravity-ui/yagr", - "version": "3.7.12", + "version": "3.7.13", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gravity-ui/yagr", - "version": "3.7.12", + "version": "3.7.13", "license": "MIT", "dependencies": { "uplot": "1.6.25" diff --git a/package.json b/package.json index 9b4d74ad..2801bd78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gravity-ui/yagr", - "version": "3.7.12", + "version": "3.7.13", "description": "High level wrapper for uPlot", "keywords": [ "canvas",