Tipsy won't recognize d3 elements in asp.net
Asked Answered
F

2

1

I am writing something ASP.NET and using d3 to graph a scatter plot, then tipsy to do mouseovers.

This is inspired by this example.

I have dumbed down my graph considerably so it is just this: http://jsfiddle.net/scottieb/D9Vjg/

But when I put that code in ASP.NET it won't work! If I put a button in and tie tipsy to that instead I have no issue generating the tooltip.

$('button').tipsy({
   html: false,
            live: true,
            fade: true,
            gravity: 'e',
            title: function () {
                return "test";
            }
        });

For what it's worth, here's the code:

%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Reports_test.aspx.cs"
Inherits="Pricing.App.Web.Reports_test" %

asp:content id="bodyContent" contentplaceholderid="Body" runat="server">
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://onehackoranother.com/projects/jquery/tipsy/javascripts/jquery.tipsy.js"></script>

<div id="slidegraph"></div>
<script type="text/javascript">

//$(function () {
        //var x_data = [1, 1.2, 1.4, 1.6, 1.8]; 
        var x_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
        var y_data = [2, 4, 6, 7, 8, 9, 10, 12, 14, 15, 19, 20];
        var r_data = [5, 5, 5, 5, 10, 10, 10, 10, 4, 4];
        var c_data = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2];
        var ipg_data = ['MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD', 'MUSTARD'];
        var srp_data = [2, 4, 6, 7, 8, 9, 10, 12, 14, 15, 19, 20];
        var old_data = [2, 4, 6, 7, 8, 9, 10, 12, 14, 15, 19, 20];

        var data = [];

        for (i = 0; i < x_data.length; i++) {
            data.push({ "x": x_data[i], "y": y_data[i], "c": c_data[i], "r": r_data[i]
                    , "ipg": ipg_data[i], "srp": srp_data[i], "old": old_data[i]
            });
        }


        var h = 400;
        var w = 400;
        var margin = 40;



        var x = d3.scale.linear().domain([0, 10]).range([0 + margin, w - margin]),
                y = d3.scale.linear().domain([20, 0]).range([0 + margin, h - margin]),
                r = d3.scale.linear().domain([0, 10]).range([3, 20]),
                c = d3.scale.ordinal().domain([1, 7]).range(["#FF0000", "#00FF00", "#0000FF"
                        , "#FFFF00", "#00FFFF", "#FF00FF", "#FFFFFF"]);

        var vis = d3.select("#slidegraph")
                    .append("svg:svg")
                    .attr("width", w)
                    .attr("height", h);

        vis.selectAll("circle").data(data).enter().append("svg:circle")
        .attr("stroke", "black")
        .attr("cx", function (d) {
            return x(d.x);
        }).attr("cy", function (d) {
            return y(d.y);
        }).attr("fill", "red").attr("r", 15)
;
        $('svg circle').tipsy({
            html: true,
            //live: true,
            //fade: true,
            gravity: 'w',
            title: function () {
                alert("gotcha!");
                return "test";
            }
        });

   //     });

    </script>
/asp:content>

UPDATE

It gets weirder. In IE, nothing works. In Firefox I get the tooltip, but it defaults to the top left of the screen, not next to the circles. Sadly, I can't get chrome in our dev machine.

Formal answered 30/5, 2012 at 13:46 Comment(1)
in your ASP.NET snippet you apparently don't have any tipsy stylesheet... I hope you have it in your example....in my browser (chrome) your jsFiddle example works. In general the tooltip defaults to the top left of the screen when you forgot the stylesheet, as I have seen in my previous tooltip trials, regardless of the tooltip being Tipys, nvd3, or Twitters's for that matter.Infusionism
B
2

By default ASP.net master pages usually have a older DOCTYPE. Remove it and put the HTML 5 doc type <!DOCTYPE html>. Also, make sure IE is not setup to display sites in compatibility mode.

Bevins answered 14/7, 2012 at 5:51 Comment(0)
F
1

This is solely a browser issue. Thanks to paxRoman for planting that seed. I get it to work flawlessly in chrome, marginally in firefox, and not at all in IE. This probably shocks no one.

Formal answered 30/5, 2012 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.