PMSI-AlignAlytics / dimple

An object-oriented API for business analytics
Other
2.73k stars 556 forks source link

Add mechanism to control application of .nice() #268

Open vetraskr opened 7 years ago

vetraskr commented 7 years ago

If the forceTickCount property is set on the axis, the call to .nice(...) will take the specified tickCount into account when generating the scale function for the axis. This prevents an issue where the specified min/max value is overridden in the axis scale by the call to .nice() as the scale function is constructed.

An example of the issue may be seen here http://jsbin.com/menejiwuxu where there is a gap between the min-value of the x-axis and the origin of the axis.

vetraskr commented 5 years ago

For posterity or in case JSBin falls over, the code for the example illustrating the buggy behaviour on the x-axis is as follows:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>

  <script src="http://dimplejs.org/lib/d3.v4.3.0.js"></script>
  <script src="http://dimplejs.org/dist/dimple.v2.3.0.min.js"></script>

</head>
<body>
  <h2> scatter chart with axis bug demo</h2>
  <div id="chartContainer">

  </div>

</body>
</html>
    var xAxisProperty = "x_value";
    var yAxisProperty = "y_value";

    var data = [
          {x_value: 9, y_value: 0.9},
          {x_value: 10.9, y_value: 2},
          {x_value: 15.6, y_value: 0.5},
          {x_value: 23, y_value: 1.8}
        ];

    var svg = dimple.newSvg("#chartContainer", 590, 400);
    var myChart = new dimple.chart(svg);

    var xAxis = myChart.addMeasureAxis("x", xAxisProperty);
    xAxis.overrideMin = 5;
    xAxis.overrideMax = 25;
    xAxis.ticks = 5;

    var yAxis = myChart.addMeasureAxis("y", yAxisProperty);
    yAxis.overrideMin = 0.4;
    yAxis.overrideMax = 2.4;
    yAxis.ticks = 4;

    var scatterSeries = myChart.addSeries(
      [xAxisProperty, yAxisProperty, "Example Series"],
      dimple.plot.bubble,
      [xAxis, yAxis]);
    scatterSeries.data = data;

    myChart.addLegend(130, 10, 400, 35, "right");
    myChart.draw();

Output chart: Screen Shot 2019-04-08 at 12 36 16

In this output chart, the xAxis can be seen to start with a min-value below 5, despite that being explicitly set with the overrideMin property.