Coder Social home page Coder Social logo

Styling the html element about cell HOT 2 CLOSED

intercellular avatar intercellular commented on June 10, 2024
Styling the html element

from cell.

Comments (2)

kingoftheknoll avatar kingoftheknoll commented on June 10, 2024 1

If I understand your question correctly, this is not something that you'd want to do with cell. Rather I don't think there's a good case for mutating the html tag ever, maybe the body element.

Using an example provided elsewhere by the author, cell will inject into the element with the id we specify. However it will blow away the DOM at and below where it's injected. So if you run this snippet below you'll rewrite the whole DOM.

<html id="viz">
<script src="https://rawgit.com/intercellular/cell/plan/cell.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js"></script>
<body></body>
<script>
var gene = {
  _sampleSVG: null,
  id: "viz",
  $cell: true,
  _r: 40,
  _cx: 50,
  _cy: 50,
  _width: 100,
  _height: 100,
  _color: 'red',
	$init: function(){
    var self = this;
    this._sampleSVG = d3.select(this)
      .append("svg")
      .attr("width", this._width)
      .attr("height", this._height);  
    this._sampleSVG.append("circle")
      .style("stroke", "gray")
      .style("fill", "white")
      .attr("r", this._r)
      .attr("cx", this._cx)
      .attr("cy", this._cy)
      .on("mouseover", function(){d3.select(this).style("fill", self._color);})
      .on("mouseout", function(){d3.select(this).style("fill", "white");});  
  }
};
</script>

</html>

But if you want to inject on the body element you can set the style attributes there. If you want to set the style on the html tag, use the DOM api to do it.

from cell.

idkjs avatar idkjs commented on June 10, 2024

Thought I would point it out because the docs say that the API matches the DOM 1-to-1 so I figured I was missing how to correctly access this element. Thank you.

from cell.

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.