UNPKG

@difftim/excelize

Version:

Excel Workbook Manager - Read and Write xlsx and csv Files.

82 lines (71 loc) 1.71 kB
const BaseXform = require('../../base-xform'); const CTxChartXform = require('./c-tx-xform'); const CCatXform = require('./c-cat-xform'); const CValXform = require('./c-val-xform'); class CSerXform extends BaseXform { constructor() { super(); this.map = { 'c:cat': new CCatXform(), 'c:tx': new CTxChartXform(), 'c:val': new CValXform(), }; } get tag() { return 'c:ser'; } render(xmlStream, model) { xmlStream.openNode(this.tag); this.map['c:tx'].render(xmlStream, model); this.map['c:cat'].render(xmlStream, model); this.map['c:val'].render(xmlStream, model); xmlStream.closeNode(); } parseOpen(node) { if (this.parser) { this.parser.parseOpen(node); return true; } switch (node.name) { case this.tag: // this.reset(); // series 可能有多个 break; default: this.parser = this.map[node.name]; if (this.parser) { this.parser.parseOpen(node); } break; } return true; } parseText(text) { if (this.parser) { this.parser.parseText(text); } } parseClose(name) { if (this.parser) { if (!this.parser.parseClose(name)) { this.parser = undefined; } return true; } switch (name) { case this.tag: { const _model = this.model || []; const _item = { series_name: this.map['c:tx'].model, category: this.map['c:cat'].model, series_val: this.map['c:val'].model, }; _model.push(_item); this.model = _model; return false; } default: return true; } } } module.exports = CSerXform;