在选择之外隐藏导航器的顶部轮廓

Hide navigator's top outline outside of selection

我正在使用导航器绘制 Highchart 图,我注意到我的轮廓颜色应用于整个导航器的顶部,而不仅仅是选定的数据范围。

可视化: 我说的是贯穿整个图表的紫色线,虽然我希望它只是选择框的一部分,但顶部轮廓的其余部分应该有不同的 color/width。我怎样才能做到这一点?

这是一个供参考的片段,是在网上找到的,它相当简单,但它准确地显示了正在发生的事情:

Highcharts.stockChart('container', {

    navigator: {
        outlineColor: 'blue',
        outlineWidth: 2,
        series: {
            lineWidth: 3,
          fillOpacity: 0.3
        }
    },

    rangeSelector: {
        selected: 1
    },

    series: [{
        name: 'USD to EUR',
        data: usdeur
    }]
});
<div id="container" style="height: 400px; min-width: 600px"></div>

<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script type="text/javascript" src="https://www.highcharts.com/samples/data/usdeur.js"></script>

所有的蓝线都是由一个 svg 路径元素创建的。更改导航器轮廓的唯一方法是包装负责绘制它的函数并更改其路径。

例如:

(function(H) {
  H.wrap(H.Navigator.prototype, 'drawOutline', function(procced, zoomedMin, zoomedMax, inverted, verb) {
    var navigator = this,
      maskInside = navigator.navigatorOptions.maskInside,
      outlineWidth = navigator.outline.strokeWidth(),
      halfOutline = outlineWidth / 2,
      outlineCorrection = (outlineWidth % 2) / 2, // #5800
      outlineHeight = navigator.outlineHeight,
      scrollbarHeight = navigator.scrollbarHeight,
      navigatorSize = navigator.size,
      left = navigator.left - scrollbarHeight,
      navigatorTop = navigator.top,
      verticalMin,
      path;

    if (inverted) {
      left -= halfOutline;
      verticalMin = navigatorTop + zoomedMax + outlineCorrection;
      zoomedMax = navigatorTop + zoomedMin + outlineCorrection;

      path = [
        'M',
        left + outlineHeight,
        navigatorTop - scrollbarHeight - outlineCorrection, // top edge
        'L',
        left + outlineHeight,
        verticalMin, // top right of zoomed range
        'L',
        left,
        verticalMin, // top left of z.r.
        'L',
        left,
        zoomedMax, // bottom left of z.r.
        'L',
        left + outlineHeight,
        zoomedMax, // bottom right of z.r.
        'L',
        left + outlineHeight,
        navigatorTop + navigatorSize + scrollbarHeight // bottom edge
      ].concat(maskInside ? [
        'M',
        left + outlineHeight,
        verticalMin - halfOutline, // upper left of zoomed range
        'L',
        left + outlineHeight,
        zoomedMax + halfOutline // upper right of z.r.
      ] : []);
    } else {
      zoomedMin += left + scrollbarHeight - outlineCorrection;
      zoomedMax += left + scrollbarHeight - outlineCorrection;
      navigatorTop += halfOutline;

      path = [
        'M',
        zoomedMin,
        navigatorTop, // upper left of zoomed range
        'L',
        zoomedMin,
        navigatorTop + outlineHeight, // lower left of z.r.
        'L',
        zoomedMax,
        navigatorTop + outlineHeight, // lower right of z.r.
        'L',
        zoomedMax,
        navigatorTop, // upper right of z.r.
      ].concat(maskInside ? [
        'M',
        zoomedMin - halfOutline,
        navigatorTop, // upper left of zoomed range
        'L',
        zoomedMax + halfOutline,
        navigatorTop // upper right of z.r.
      ] : []);
    }
    navigator.outline[verb]({
      d: path
    });

  });
}(Highcharts));

实例: https://jsfiddle.net/BlackLabel/Lrgok19a/

有用的线程: https://www.highcharts.com/forum/viewtopic.php?t=41155