Exemplo n.º 1
0
Arquivo: Tabs.C Projeto: DTidd/wt
DataConfig::DataConfig(WCartesian3DChart* chart)
  : chart_(chart)
{
  WTemplate *template_ = new WTemplate(Wt::WString::tr("totaldataconfig-template"), this);

  dataselection_ = new DataSelection(chart);
  template_->bindWidget("dataselection", dataselection_);

  WStackedWidget *sw = new WStackedWidget(this);
  sw->addWidget(new WText("Select data to configure it"));
  numgriddatasettings_ = new NumGridDataSettings();
  catgriddatasettings_ = new CatGridDataSettings();
  scatterdatasettings_ = new ScatterDataSettings();
  sw->addWidget(numgriddatasettings_);
  sw->addWidget(catgriddatasettings_);
  sw->addWidget(scatterdatasettings_);
  template_->bindWidget("dataconfig", sw);

  dataselection_->selectionChanged().connect(std::bind([=] (WAbstractDataSeries3D* data) {
	if (dynamic_cast<WAbstractGridData*>(data)) {
	  WAbstractGridData *gridData = dynamic_cast<WAbstractGridData*>(data);
	  if (gridData->type() == BarSeries3D) {
	    catgriddatasettings_->bindDataSet(gridData);
	    sw->setCurrentIndex(2);
	  } else {
	    numgriddatasettings_->bindDataSet(gridData);
	    sw->setCurrentIndex(1);
	  }
	} else if (dynamic_cast<WScatterData*>(data)) {
	  scatterdatasettings_->bindDataSet(dynamic_cast<WScatterData*>(data));
	  sw->setCurrentIndex(3);
	}
      }, std::placeholders::_1));
}
Exemplo n.º 2
0
WAbstractChartImplementation::RenderRange WChart3DImplementation::computeRenderRange(Axis axis, AxisScale scale) const
{
  WAbstractChartImplementation::RenderRange range;
  
  const std::vector<WAbstractDataSeries3D*> series = chart_->dataSeries();
  if (series.size() == 0) {
    range.minimum = 0;
    range.maximum = 100;
    return range;
  }

  double min=std::numeric_limits<double>::max();
  double max=std::numeric_limits<double>::min();
  int xDim = 0, yDim = 0;
  double stackedBarsHeight = 0.0;
  WAbstractGridData* griddata;
  switch (chart_->type()) {
  case ChartType::Scatter:
    for (unsigned i = 0; i < series.size(); i++) {
      double seriesMin = series[i]->minimum(axis);
      double seriesMax = series[i]->maximum(axis);
      if (seriesMin < min) {
	min = seriesMin;
      }
      if (seriesMax > max) {
	max = seriesMax;
      }
    }
    range.minimum = min;
    range.maximum = max;
    return range;
  case ChartType::Category:
    for (unsigned k = 0; k < series.size(); k++) {
      griddata = dynamic_cast<WAbstractGridData*>(series[k]);
      if ( griddata == 0 
	   || griddata->type() != Series3DType::Bar) {
	throw WException("WChart3DImplementation: not all data is categorical");
      }
    }
    xDim = dynamic_cast<WAbstractGridData*>(series[0])->nbXPoints();
    yDim = dynamic_cast<WAbstractGridData*>(series[0])->nbYPoints();
    min = 0.0;

    for (int i=0; i < xDim; i++) {
      for (int j=0; j < yDim; j++) {
	for (unsigned k = 0; k < series.size(); k++) {
	  if (series[k]->isHidden())
	    continue;
	  griddata = dynamic_cast<WAbstractGridData*>(series[k]);
	  stackedBarsHeight += Wt::asNumber(griddata->data(i,j));
	}
	if (stackedBarsHeight > max) {
	  max = stackedBarsHeight;
	}
	stackedBarsHeight = 0;
      }
    }
    if (max == std::numeric_limits<double>::min()) {
      max = 100.0;
    }
    range.minimum = min;
    range.maximum = max;
    return range;
  default:
    throw WException("WChart3DImplementation: don't know this axis-type");
  }
}