From 9399e57fc21844a0c053c807daea92954587a058 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Fri, 29 May 2020 00:32:00 +0300 Subject: [PATCH] Clean lint errors from samples by refactoring (#7440) * Clean lint errors from samples by refactoring * Review --- samples/scriptable/bubble.html | 10 +++++++--- samples/tooltips/custom-line.html | 10 ++++++++-- samples/utils.js | 28 +++++++++++++++++----------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/samples/scriptable/bubble.html b/samples/scriptable/bubble.html index 23f4f30fb..87cd8a20b 100644 --- a/samples/scriptable/bubble.html +++ b/samples/scriptable/bubble.html @@ -28,13 +28,17 @@ utils.srand(110); + function channelValue(x, y, values) { + return x < 0 && y < 0 ? values[0] : x < 0 ? values[1] : y < 0 ? values[2] : values[3]; + } + function colorize(opaque, context) { var value = context.dataset.data[context.dataIndex]; var x = value.x / 100; var y = value.y / 100; - var r = x < 0 && y < 0 ? 250 : x < 0 ? 150 : y < 0 ? 50 : 0; - var g = x < 0 && y < 0 ? 0 : x < 0 ? 50 : y < 0 ? 150 : 250; - var b = x < 0 && y < 0 ? 0 : x > 0 && y > 0 ? 250 : 150; + var r = channelValue(x, y, [250, 150, 50, 0]); + var g = channelValue(x, y, [0, 50, 150, 250]); + var b = channelValue(x, y, [0, 150, 150, 250]); var a = opaque ? 1 : 0.5 * value.v / 1000; return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; diff --git a/samples/tooltips/custom-line.html b/samples/tooltips/custom-line.html index c4626d872..b2c7798fc 100644 --- a/samples/tooltips/custom-line.html +++ b/samples/tooltips/custom-line.html @@ -40,8 +40,7 @@