使用ngx-charts和d3的自定义时间线图表

时间:2017-09-07 11:55:44

标签: angular d3.js ngx-charts

是否有详细的文档如何制作自定义ngx图表?这是我发现的,但无法开始使用: https://medium.com/@amcdnl/charts-with-svgs-in-angular2-1d08a0e635ea

我想创建一个自定义时间表图表,如下所示:

https://drive.google.com/open?id=0B2wUYluH2H4vZXdNUmxjU3JIWmc https://drive.google.com/open?id=0B2wUYluH2H4vSnZkT1ZUdWd3N2M

我试图重新创建第二个,这是我目前取得的进展: https://drive.google.com/open?id=0B2wUYluH2H4veGlNak13clRFeEk

我在此图表中仅使用svg矩形,但我希望在angular4下使用d3。我认为可以用ngx-chart和d3完成,但我找不到任何有用的文档。

svg source:

    // reference: https://stackoverflow.com/a/15683034/347339
    func MKMapRectForCoordinateRegion(region:MKCoordinateRegion) -> MKMapRect {
        let topLeft = CLLocationCoordinate2D(latitude: region.center.latitude + (region.span.latitudeDelta/2), longitude: region.center.longitude - (region.span.longitudeDelta/2))
        let bottomRight = CLLocationCoordinate2D(latitude: region.center.latitude - (region.span.latitudeDelta/2), longitude: region.center.longitude + (region.span.longitudeDelta/2))

        let a = MKMapPointForCoordinate(topLeft)
        let b = MKMapPointForCoordinate(bottomRight)

        return MKMapRect(origin: MKMapPoint(x:min(a.x,b.x), y:min(a.y,b.y)), size: MKMapSize(width: abs(a.x-b.x), height: abs(a.y-b.y)))
    }

    // reference: https://stackoverflow.com/a/19307286/347339
    // assuming coordinates that create a polyline as well as a destination annotation
    func updateMap(coordinates: [CLLocationCoordinate2D], annotation: MKAnnotation) {

        var union = MKMapRectNull
        var coordinateArray = coordinates
        coordinateArray.append(annotation.coordinate)

        for coordinate in coordinateArray {
            // make a small, say, 50meter square for each
            let pReg = MKCoordinateRegionMakeWithDistance( coordinate, 50, 50 )
            // convert it to a MKMapRect
            let r = MKMapRectForCoordinateRegion(region: pReg)

            // union all of those
            union = MKMapRectUnion(union, r)
        }

        // expand the union, using the new #edgePadding call. T,L,B,R
        let f = mapView.mapRectThatFits(union, edgePadding: UIEdgeInsetsMake(70, 35, 10, 35))

        // NOTE you want the TOP padding much bigger than the BOTTOM padding
        // because the pins/signs are actually very tall

        mapView.setVisibleMapRect(f, animated: false)
    }

0 个答案:

没有答案