예제 #1
0
  void SeriesList::drawInFrame(Frame& innerFrame, double minX, double maxX, double minY, double maxY)
  {
    double multX = innerFrame.getWidth()/(maxX-minX);
    double multY = innerFrame.getHeight()/(maxY-minY);

    // Draw lines
    for(int i=0;i<getNumSeries();i++)
    {
      innerFrame.push_state();

      StrokeStyle s = getStyle(i);          
      Marker m = getMarker(i);

      if(m.getColor().isClear() && s.getColor().isClear())
      {
        innerFrame << Comment("Plot contained data with clear stroke and marker.  Skipping.");
        continue;
      }

      vector< pair<double,double> >& vec = getPointList(i);
      Path curve(vec,innerFrame.lx(), innerFrame.ly());

      // What I'd give for a line of haskell...
      // map (\(x,y) -> (multX*(x-minX), multY*(y-minY))) vector
      map_object map_instance(multX,minX,multY,minY);

      innerFrame.setMarker(m);
      innerFrame.setLineStyle(s);

      if(s.getColor().isClear())
      {
        // crop
        auto_ptr< Path > cropX = Splitter::cropToBox(minX,maxX,minY,maxY,curve);

        // Fit it to the box.
        std::for_each(cropX->begin(), cropX->end(), map_instance);

        // Draw the line
        innerFrame.line(*cropX);
      }
      else 
      {
        // interpolate
        auto_ptr< std::list<Path> > interpX = Splitter::interpToBox(minX,maxX,minY,maxY,curve);

        for(std::list<Path>::iterator i=interpX->begin();i!=interpX->end();i++)
        {
          // Fit it to the box
          std::for_each(i->begin(), i->end(), map_instance);

          // Draw the line
          innerFrame.line(*i);
        }
      }
      innerFrame.pop_state();
    }
  }
예제 #2
0
  std::string SVGImage::convertStrokeStyle (const StrokeStyle& ss) const
  {
    using namespace std;
    stringstream ostr(stringstream::in | stringstream::out); 

    if(ss.getColor().isClear())
    {
      ostr << "stroke-opacity:0;";
      return string(ostr.str());        
    }

    // Color
    if(ss.getColor()!=Color::BLACK)
    {
      ostr << "stroke:rgb(";
      short red, blue, green;
      ss.getColor().getRGBTriplet(red, blue, green);
      ostr << red << "," << blue << "," << green;
      ostr << ");";
    }

    // Width
    if(ss.getWidth()!=1)
      ostr << "stroke-width:" << ss.getWidth() << "pt;";

    if (!ss.getSolid())
    {
      // Dash array list: comma separated variables
      ostr << "stroke-dasharray:";

      StrokeStyle::dashLengthList dll=ss.getDashList();
      StrokeStyle::dashLengthList::iterator i, inext;

      for (i=dll.begin(); i!=dll.end(); i++)
      {
        ostr << (i==dll.begin()?"":",") << *i;
        inext = i; inext++; 
        if (inext!=dll.end())
          cout << ",";
      }
      // Final delimiter
      ostr << ";";   
    }

    return string(ostr.str());
  }