0

嗨,我尝试制作一个简单的 jsxgraph 图,我可以在其中使用按钮切换电路板的一些属性。我正在使用角度,但我不明白为什么它不起作用。这是小提琴

我很高兴任何形式的帮助

 <div class="col-md-10">
    <div ng-controller="MyCtrl">
    <div id="jsxgbox" class="jxgbox " style="width:250px; height:250px;"></div>
    <button type="button" class="btn btn-primary" ng-model="showAxis" ng-click="showAxis = !showAxis">
    <span ng-show="showAxis">axis On</span>
    <span ng-show="!showAxis">axis Off</span></button>
    <button type="button" class="btn btn-primary" ng-model="showNav" ng-click="showNav = !showNav"> <span ng-show="showNav">Navigation On</span>
    <span ng-show="!showNav">Navigation Off</span></button>
    </div>
</div>

var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.showAxis = true;
$scope.showNav = false;
$scope.axisOn = true
$scope.board = JXG.JSXGraph.initBoard('jsxgbox', {
    unitX: 10, // this are the lighter gray lines parallel ro the y axis
    unitY: 10,
    axis: $scope.showAxis,
    showNavigation: $scope.showNav,
    showCopyright: false,
    grid: true,
    wheel: true,
    keepaspectratio: true,
    needshift: false,
    boundingbox: [-5, 5, 5, -5] // upperleft corner ( x1,y1) bottom right corner (x2,y2)
});
}
4

1 回答 1

0

在 JSXGraph 中,默认轴和导航栏的行为与其他元素略有不同。导航栏只能通过直接将 CSS 属性设置为 HTML div 来关闭。这是您的示例的工作版本。如果代码没有完善,我很抱歉。这是我的第一个 angual.js 应用程序。但是很高兴看到 JSXGraph 和 angualrs.jus 是如何协同工作的。

<!doctype html>
<html ng-app="JSXGraphApp">
  <head>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
    <script type="text/javascript" src="https://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
    <link rel="stylesheet" type="text/css" href="https://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css"/>

  </head>
  <body>
    <div class="col-md-10">          
        <div ng-controller="JSXGraphController">
            <div id="jsxgbox" class="jxgbox " style="width:250px; height:250px;"></div>
            <button type="button" class="btn btn-primary" ng-model="showAxis" ng-click="toggleAxis()">
                <span ng-show="showAxis">axis On</span>
                <span ng-show="!showAxis">axis Off</span>
            </button>
            <button type="button" class="btn btn-primary" ng-model="showNav" ng-click="toggleNav()"> 
                <span ng-show="showNav">Navigation On</span>
                <span ng-show="!showNav">Navigation Off</span>
            </button>
            <button type="button" class="btn btn-primary" ng-model="showPoint" ng-click="togglePoint()"> 
                <span ng-show="showPoint">Show point</span>
                <span ng-show="!showPoint">Hide point</span>
            </button>
        </div>
    </div>
  </body>
</html>

<script type="text/javascript">

var JSXGraphApp = angular.module('JSXGraphApp', [])
    .controller('JSXGraphController', function($scope) {

    $scope.showAxis = true;
    $scope.showNav = false;
    $scope.showPoint = true;
    $scope.axisOn = true;
    $scope.board = JXG.JSXGraph.initBoard('jsxgbox', {
        unitX: 10, // this are the lighter gray lines parallel ro the y axis
        unitY: 10,
        axis: $scope.showAxis,
        showNavigation: $scope.showNav,
        showCopyright: false,
        grid: true,
        wheel: true,
        keepaspectratio: true,
        needshift: false,
        boundingbox: [-5, 5, 5, -5] // upperleft corner ( x1,y1) bottom right corner (x2,y2)
    });

    $scope.toggleNav = function() {
        var navbar = document.getElementById($scope.board.containerObj.id + '_navigationbar');
        $scope.showNav = !$scope.showNav;
        if ($scope.showNav) {
            navbar.style.display = "block";
        } else {
            navbar.style.display = "none";
        }
    };

    $scope.toggleAxis = function() {
        $scope.showAxis = !$scope.showAxis;
        $scope.board.defaultAxes.x.setAttribute({visible: $scope.showAxis});
        $scope.board.defaultAxes.y.setAttribute({visible: $scope.showAxis});
    };

    $scope.p = $scope.board.create('point', [1, 2]);
    $scope.togglePoint = function() {
        $scope.showPoint = !$scope.showPoint;
        $scope.p.setAttribute({visible: $scope.showPoint});
    };
});
</script>
于 2015-10-13T12:43:33.393 回答