File:  [LON-CAPA] / modules / damieng / graphical_editor / loncapa_daxe / web / nodes / plot_axis.dart
Revision 1.3: download - view: text, annotated - select for diffs
Tue Feb 28 20:40:59 2017 UTC (7 years, 3 months ago) by damieng
Branches: MAIN
CVS tags: HEAD
updates following changes in Daxe Config API

/*
  This file is part of LONCAPA-Daxe.

  LONCAPA-Daxe is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  LONCAPA-Daxe is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Daxe.  If not, see <http://www.gnu.org/licenses/>.
*/

part of loncapa_daxe;

/**
 * Display for the axis element, for simple UI (displaying only selected attributes as if they were gnuplot attributes).
 * Jaxe display type: 'plotaxis'.
 */
class PlotAxis extends LCDBlock {
  static List<String> simpleUIAttributes = ['xmin', 'xmax', 'ymin', 'ymax'];
  
  PlotAxis.fromRef(x.Element elementRef) : super.fromRef(elementRef);
  
  PlotAxis.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
    if (simpleParent())
      simpleUI = true;
  }
  
  @override
  bool simpleUIPossible() {
    for (DaxeAttr att in attributes) {
      if (!simpleUIAttributes.contains(att.name)) {
        // check if it's a default value
        bool isDefault = false;
        for (x.Element attref in attRefs) {
          if (att.localName == doc.cfg.attributeName(attref) &&
              att.namespaceURI == doc.cfg.attributeNamespace(attref)) {
            String defaultValue = doc.cfg.defaultAttributeValue(attref);
            if (att.value == defaultValue)
              isDefault = true;
            break;
          }
        }
        if (!isDefault)
          throw new SimpleUIException('axis: ' + LCDStrings.get('attribute_problem') + ' ' + att.name);
      }
    }
    if (firstChild != null)
      return false;
    return true;
  }
  
  bool simpleParent() {
    return (parent is LCDBlock && (parent as LCDBlock).simpleUI);
  }
  
  @override
  h.Element html() {
    simpleUI = simpleParent();
    if (!simpleUI)
      return super.html();
    
    // the whole axis node is reduced to 4 attributes
    h.TableElement table = new h.TableElement();
    table.classes.add('expand');
    table.id = id;
    for (x.Element refAttr in attRefs) {
      String name = doc.cfg.attributeName(refAttr);
      if (simpleUIAttributes.contains(name)) {
        h.TableRowElement tr = attributeHTML(refAttr);
        table.append(tr);
      }
    }
    
    return(table);
  }
  
  @override
  void updateAttributes() {
    if (!simpleUI) {
      super.updateAttributes();
      return;
    }
    parent.updateHTML();
  }
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>