Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vetraskr
Copy link

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.

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.
@vetraskr
Copy link
Author

vetraskr commented Apr 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant