1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20 21# usage: runpy.sh fixtures/t14/chart.py <port> <outdir> <tag> 22# A Calc document with a chart over A1:C4 (data in the sheet, so the chart uses the sheet's data provider), saved with the 23# office's configured ODF version and reloaded. Writes <outdir>/<tag>.json: whether the reloaded chart has an internal data 24# provider, the source range of every data sequence, and whether the chart still follows a changed cell. 25import json, os, sys 26import uno 27from unohelp import connect, desktop, pv 28 29port, out, tag = int(sys.argv[1]), os.path.abspath(sys.argv[2]), sys.argv[3] 30os.makedirs(out, exist_ok=True) 31ctx = connect(port) 32desk = desktop(ctx) 33 34 35def info(doc): 36 sh = doc.Sheets.getByIndex(0) 37 cd = sh.Charts.getByName("chart1").EmbeddedObject 38 seqs = [] 39 cs = cd.FirstDiagram.CoordinateSystems[0] 40 for ct in cs.ChartTypes: 41 for ser in ct.DataSeries: 42 for seq in ser.DataSequences: 43 seqs.append((seq.Role if hasattr(seq, "Role") else seq.Values.Role, seq.Values.SourceRangeRepresentation)) 44 first = cd.DataProvider if hasattr(cd, "DataProvider") else cd.getDataProvider() 45 before = [seq.Values.getNumericalData() for ct in cs.ChartTypes for ser in ct.DataSeries for seq in ser.DataSequences] 46 sh.getCellByPosition(1, 1).Value = 12345 47 after = [seq.Values.getNumericalData() for ct in cs.ChartTypes for ser in ct.DataSeries for seq in ser.DataSequences] 48 return {"internal_data_provider": bool(cd.hasInternalDataProvider()), "ranges": seqs, 49 "follows_cell": before != after, "label_sequences": [s.Label.SourceRangeRepresentation for ct in cs.ChartTypes for ser in ct.DataSeries for s in [ser.DataSequences[0]]] if False else None} 50 51 52doc = desk.loadComponentFromURL("private:factory/scalc", "_blank", 0, (pv("Hidden", True),)) 53sh = doc.Sheets.getByIndex(0) 54for r, row in enumerate((("", "a", "b"), ("x", 1, 2), ("y", 3, 4), ("z", 5, 6))): 55 for c, v in enumerate(row): 56 cell = sh.getCellByPosition(c, r) 57 if isinstance(v, str): 58 cell.String = v 59 else: 60 cell.Value = v 61addr = uno.createUnoStruct("com.sun.star.table.CellRangeAddress") 62addr.Sheet, addr.StartColumn, addr.StartRow, addr.EndColumn, addr.EndRow = 0, 0, 0, 2, 3 63rect = uno.createUnoStruct("com.sun.star.awt.Rectangle", 6000, 500, 8000, 6000) 64sh.Charts.addNewByName("chart1", rect, (addr,), True, True) 65path = os.path.join(out, tag + ".ods") 66if os.path.exists(path): 67 os.remove(path) 68doc.storeToURL(uno.systemPathToFileUrl(path), (pv("FilterName", "calc8"), pv("Overwrite", True))) 69doc.close(True) 70d2 = desk.loadComponentFromURL(uno.systemPathToFileUrl(path), "_blank", 0, (pv("Hidden", True),)) 71res = info(d2) 72d2.close(True) 73json.dump(res, open(os.path.join(out, "chart-" + tag + ".json"), "w"), indent=1, sort_keys=True) 74print(tag, res) 75