Code Monkey home page Code Monkey logo

Comments (6)

ivnsch avatar ivnsch commented on May 12, 2024

You can add a transparent overlay view that covers the chart when the user taps on the circle. There's a utility class HandlingView which you could use for this - you can pass a touchHandler to it in which you clear the popup.

In order for the circles to continue being interactive while the overlay is open you'd have to make that the overlay is added behind the circles (in this case the overlay can be added permanently, no need to do it only when user taps). I'd create a ChartLayer class and implement chartInitialized such that it adds this overlay as subview of the chart. Then pass this layer to Chart initialiser before the layer holding the circles. If you don't want to create new layer class you can also instantiate ChartPointsViewsLayer with a dummy chart point, where you just add the overlay to the chart in the view generator.

from swiftcharts.

ivnsch avatar ivnsch commented on May 12, 2024

P.S. Here also code to make clearer what I mean, with ChartPointsViewsLayer approach, it would look similar to this

let overlayGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsLayer, chart: Chart) -> UIView? in
let view = HandlingView(frame: chart.frame)
    view.touchHandler = {
    // code to hide current popup
    }
    return view
}

let dummyChartPoint = ChartPoint(0, 0) // coordinates are not important here since we don't use them
let overlayLayer = ChartPointsViewsLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: dummyChartPoint, viewGenerator: overlayGenerator)

...

let chart = Chart(
    frame: chartFrame,
    layers: [
        ...
        overlayLayer,
        circlesLayer,
        ...
    ]
)

let me know if it works out for you or you face any other issues!

from swiftcharts.

christinalau avatar christinalau commented on May 12, 2024

Didn't seem to work, the touchHandler was never entered. Would it be possible to provide an updated running example? Thanks so much for your quick response.

from swiftcharts.

ivnsch avatar ivnsch commented on May 12, 2024

This is an exact copy of the areas example, you can find the overlay part enclosed in ////////////. https://gist.github.com/i-schuetz/a7801eba798e2d04d1c5

from swiftcharts.

christinalau avatar christinalau commented on May 12, 2024

Thank you. This is what I observed now, if I click on any of the green space, then the pop up is clear. However, if I click on some of the white space, then sometimes the popup is not clear. For example, click 6,290, then click on the first top box (i.e. 350-300,0-2), then it is not clear.

from swiftcharts.

ivnsch avatar ivnsch commented on May 12, 2024

Ah, you have to pass chart.bounds instead of chart.frame to the HandlingView. The chart's frame starts at 0,70 which is why the overlay doesn't cover the upper part.

from swiftcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.